Mercurial > projects > dwt-addons
comparison dwtx/jface/internal/text/InformationControlReplacer.d @ 150:5cf141e43417
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 23:05:26 +0200 |
parents | 000f9136b8f7 |
children | a9566845f1cb |
comparison
equal
deleted
inserted
replaced
149:b411f1c62131 | 150:5cf141e43417 |
---|---|
2 * Copyright (c) 2008 IBM Corporation and others. | 2 * Copyright (c) 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
42 * | 42 * |
43 * @see AbstractInformationControlManager#setInformationControlReplacer(InformationControlReplacer) | 43 * @see AbstractInformationControlManager#setInformationControlReplacer(InformationControlReplacer) |
44 * @since 3.4 | 44 * @since 3.4 |
45 */ | 45 */ |
46 public class InformationControlReplacer : AbstractInformationControlManager { | 46 public class InformationControlReplacer : AbstractInformationControlManager { |
47 | 47 |
48 /** | 48 /** |
49 * Minimal width in pixels. | 49 * Minimal width in pixels. |
50 */ | 50 */ |
51 private static const int MIN_WIDTH= 80; | 51 private static const int MIN_WIDTH= 80; |
52 /** | 52 /** |
53 * Minimal height in pixels. | 53 * Minimal height in pixels. |
54 */ | 54 */ |
55 private static const int MIN_HEIGHT= 50; | 55 private static const int MIN_HEIGHT= 50; |
56 | 56 |
57 /** | 57 /** |
58 * Default control creator. | 58 * Default control creator. |
59 */ | 59 */ |
60 protected static class DefaultInformationControlCreator : AbstractReusableInformationControlCreator { | 60 protected static class DefaultInformationControlCreator : AbstractReusableInformationControlCreator { |
61 public IInformationControl doCreateInformationControl(Shell shell) { | 61 public IInformationControl doCreateInformationControl(Shell shell) { |
66 private bool fIsReplacing; | 66 private bool fIsReplacing; |
67 private Object fReplacableInformation; | 67 private Object fReplacableInformation; |
68 private bool fDelayedInformationSet; | 68 private bool fDelayedInformationSet; |
69 private Rectangle fReplaceableArea; | 69 private Rectangle fReplaceableArea; |
70 private Rectangle fContentBounds; | 70 private Rectangle fContentBounds; |
71 | 71 |
72 | 72 |
73 /** | 73 /** |
74 * Creates a new information control replacer. | 74 * Creates a new information control replacer. |
75 * | 75 * |
76 * @param creator the default information control creator | 76 * @param creator the default information control creator |
77 */ | 77 */ |
78 public this(IInformationControlCreator creator) { | 78 public this(IInformationControlCreator creator) { |
79 super(creator); | 79 super(creator); |
80 takesFocusWhenVisible(false); | 80 takesFocusWhenVisible(false); |
81 } | 81 } |
82 | 82 |
83 /** | 83 /** |
84 * Replace the information control. | 84 * Replace the information control. |
85 * | 85 * |
86 * @param informationPresenterControlCreator the information presenter control creator | 86 * @param informationPresenterControlCreator the information presenter control creator |
87 * @param contentBounds the bounds of the content area of the information control | 87 * @param contentBounds the bounds of the content area of the information control |
88 * @param information the information to show | 88 * @param information the information to show |
89 * @param subjectArea the subject area | 89 * @param subjectArea the subject area |
90 * @param takeFocus <code>true</code> iff the replacing information control should take focus | 90 * @param takeFocus <code>true</code> iff the replacing information control should take focus |
91 */ | 91 */ |
92 public void replaceInformationControl(IInformationControlCreator informationPresenterControlCreator, Rectangle contentBounds, Object information, final Rectangle subjectArea, bool takeFocus) { | 92 public void replaceInformationControl(IInformationControlCreator informationPresenterControlCreator, Rectangle contentBounds, Object information, final Rectangle subjectArea, bool takeFocus) { |
93 | 93 |
94 try { | 94 try { |
95 fIsReplacing= true; | 95 fIsReplacing= true; |
96 if (! fDelayedInformationSet) | 96 if (! fDelayedInformationSet) |
97 fReplacableInformation= information; | 97 fReplacableInformation= information; |
98 else | 98 else |
99 takeFocus= true; // delayed input has been set, so the original info control must have been focused | 99 takeFocus= true; // delayed input has been set, so the original info control must have been focused |
100 fContentBounds= contentBounds; | 100 fContentBounds= contentBounds; |
101 fReplaceableArea= subjectArea; | 101 fReplaceableArea= subjectArea; |
102 | 102 |
103 setCustomInformationControlCreator(informationPresenterControlCreator); | 103 setCustomInformationControlCreator(informationPresenterControlCreator); |
104 | 104 |
105 takesFocusWhenVisible(takeFocus); | 105 takesFocusWhenVisible(takeFocus); |
106 | 106 |
107 showInformation(); | 107 showInformation(); |
108 } finally { | 108 } finally { |
109 fIsReplacing= false; | 109 fIsReplacing= false; |
110 fReplacableInformation= null; | 110 fReplacableInformation= null; |
111 fDelayedInformationSet= false; | 111 fDelayedInformationSet= false; |
112 fReplaceableArea= null; | 112 fReplaceableArea= null; |
113 setCustomInformationControlCreator(null); | 113 setCustomInformationControlCreator(null); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 /* | 117 /* |
118 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() | 118 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() |
119 */ | 119 */ |
120 protected void computeInformation() { | 120 protected void computeInformation() { |
121 if (fIsReplacing && fReplacableInformation !is null) { | 121 if (fIsReplacing && fReplacableInformation !is null) { |
122 setInformation(fReplacableInformation, fReplaceableArea); | 122 setInformation(fReplacableInformation, fReplaceableArea); |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 if cast(DEBUG) | 126 if (DEBUG) |
127 System.out_.println("InformationControlReplacer: no active replaceable"); //$NON-NLS-1$ | 127 System.out_.println("InformationControlReplacer: no active replaceable"); //$NON-NLS-1$ |
128 } | 128 } |
129 | 129 |
130 /** | 130 /** |
131 * Opens the information control with the given information and the specified | 131 * Opens the information control with the given information and the specified |
134 * @param subjectArea the information area | 134 * @param subjectArea the information area |
135 * @param information the information | 135 * @param information the information |
136 */ | 136 */ |
137 public void showInformationControl(Rectangle subjectArea, Object information) { | 137 public void showInformationControl(Rectangle subjectArea, Object information) { |
138 IInformationControl informationControl= getInformationControl(); | 138 IInformationControl informationControl= getInformationControl(); |
139 | 139 |
140 Rectangle controlBounds= fContentBounds; | 140 Rectangle controlBounds= fContentBounds; |
141 if ( cast(IInformationControlExtension3)informationControl ) { | 141 if ( cast(IInformationControlExtension3)informationControl ) { |
142 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; | 142 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; |
143 Rectangle trim= iControl3.computeTrim(); | 143 Rectangle trim= iControl3.computeTrim(); |
144 controlBounds= Geometry.add(controlBounds, trim); | 144 controlBounds= Geometry.add(controlBounds, trim); |
145 | 145 |
146 /* | 146 /* |
147 * Ensure minimal size. Interacting with a tiny information control | 147 * Ensure minimal size. Interacting with a tiny information control |
148 * (resizing, selecting text) would be a pain. | 148 * (resizing, selecting text) would be a pain. |
149 */ | 149 */ |
150 controlBounds.width= Math.max(controlBounds.width, MIN_WIDTH); | 150 controlBounds.width= Math.max(controlBounds.width, MIN_WIDTH); |
151 controlBounds.height= Math.max(controlBounds.height, MIN_HEIGHT); | 151 controlBounds.height= Math.max(controlBounds.height, MIN_HEIGHT); |
152 | 152 |
153 getInternalAccessor().cropToClosestMonitor(controlBounds); | 153 getInternalAccessor().cropToClosestMonitor(controlBounds); |
154 } | 154 } |
155 | 155 |
156 Point location= Geometry.getLocation(controlBounds); | 156 Point location= Geometry.getLocation(controlBounds); |
157 Point size= Geometry.getSize(controlBounds); | 157 Point size= Geometry.getSize(controlBounds); |
158 | 158 |
159 // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values | 159 // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values |
160 informationControl.setSizeConstraints(size.x, size.y); | 160 informationControl.setSizeConstraints(size.x, size.y); |
161 | 161 |
162 if ( cast(IInformationControlExtension2)informationControl ) | 162 if ( cast(IInformationControlExtension2)informationControl ) |
163 (cast(IInformationControlExtension2) informationControl).setInput(information); | 163 (cast(IInformationControlExtension2) informationControl).setInput(information); |
164 else | 164 else |
165 informationControl.setInformation(information.toString()); | 165 informationControl.setInformation(information.toString()); |
166 | 166 |
167 informationControl.setLocation(location); | 167 informationControl.setLocation(location); |
168 informationControl.setSize(size.x, size.y); | 168 informationControl.setSize(size.x, size.y); |
169 | 169 |
170 showInformationControl(subjectArea); | 170 showInformationControl(subjectArea); |
171 } | 171 } |
172 | 172 |
173 /* | 173 /* |
174 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | 174 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() |
175 */ | 175 */ |
176 public void hideInformationControl() { | 176 public void hideInformationControl() { |
177 super.hideInformationControl(); | 177 super.hideInformationControl(); |
182 */ | 182 */ |
183 public void setDelayedInput(Object input) { | 183 public void setDelayedInput(Object input) { |
184 fReplacableInformation= input; | 184 fReplacableInformation= input; |
185 if (! isReplacing()) { | 185 if (! isReplacing()) { |
186 fDelayedInformationSet= true; | 186 fDelayedInformationSet= true; |
187 } else if (getCurrentInformationControl2() instanceof IInformationControlExtension2) { | 187 } else if (cast(IInformationControlExtension2)getCurrentInformationControl2() ) { |
188 (cast(IInformationControlExtension2) getCurrentInformationControl2()).setInput(input); | 188 (cast(IInformationControlExtension2) getCurrentInformationControl2()).setInput(input); |
189 } else if (getCurrentInformationControl2() !is null) { | 189 } else if (getCurrentInformationControl2() !is null) { |
190 getCurrentInformationControl2().setInformation(input.toString()); | 190 getCurrentInformationControl2().setInformation(input.toString()); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 /** | 194 /** |
195 * Tells whether the replacer is currently replacing another information control. | 195 * Tells whether the replacer is currently replacing another information control. |
196 * | 196 * |
197 * @return <code>true</code> while code from {@link #replaceInformationControl(IInformationControlCreator, Rectangle, Object, Rectangle, bool)} is run | 197 * @return <code>true</code> while code from {@link #replaceInformationControl(IInformationControlCreator, Rectangle, Object, Rectangle, bool)} is run |
198 */ | 198 */ |
199 public bool isReplacing() { | 199 public bool isReplacing() { |
200 return fIsReplacing; | 200 return fIsReplacing; |
201 } | 201 } |
202 | 202 |
203 /** | 203 /** |
204 * @return the current information control, or <code>null</code> if none available | 204 * @return the current information control, or <code>null</code> if none available |
205 */ | 205 */ |
206 public IInformationControl getCurrentInformationControl2() { | 206 public IInformationControl getCurrentInformationControl2() { |
207 return getInternalAccessor().getCurrentInformationControl(); | 207 return getInternalAccessor().getCurrentInformationControl(); |
208 } | 208 } |
209 | 209 |
210 /** | 210 /** |
211 * The number of pixels to blow up the keep-up zone. | 211 * The number of pixels to blow up the keep-up zone. |
212 * | 212 * |
213 * @return the margin in pixels | 213 * @return the margin in pixels |
214 */ | 214 */ |
215 public int getKeepUpMargin() { | 215 public int getKeepUpMargin() { |
216 return 15; | 216 return 15; |
217 } | 217 } |