129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Sean Montgomery, sean_montgomery@comcast.net - https://bugs.eclipse.org/bugs/show_bug.cgi?id=45095
|
|
11 * Port to the D programming language:
|
|
12 * Frank Benoit <benoit@tionex.de>
|
|
13 *******************************************************************************/
|
|
14
|
131
|
15
|
|
16 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport
|
|
17 import dwtx.jface.text.DefaultTextHover; // packageimport
|
|
18 import dwtx.jface.text.AbstractInformationControl; // packageimport
|
|
19 import dwtx.jface.text.TextUtilities; // packageimport
|
|
20 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport
|
|
21 import dwtx.jface.text.ITextViewerExtension2; // packageimport
|
|
22 import dwtx.jface.text.IDocumentPartitioner; // packageimport
|
|
23 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport
|
|
24 import dwtx.jface.text.ITextSelection; // packageimport
|
|
25 import dwtx.jface.text.Document; // packageimport
|
|
26 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport
|
|
27 import dwtx.jface.text.ITextListener; // packageimport
|
|
28 import dwtx.jface.text.BadPartitioningException; // packageimport
|
|
29 import dwtx.jface.text.ITextViewerExtension5; // packageimport
|
|
30 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport
|
|
31 import dwtx.jface.text.IUndoManager; // packageimport
|
|
32 import dwtx.jface.text.ITextHoverExtension2; // packageimport
|
|
33 import dwtx.jface.text.IRepairableDocument; // packageimport
|
|
34 import dwtx.jface.text.IRewriteTarget; // packageimport
|
|
35 import dwtx.jface.text.DefaultPositionUpdater; // packageimport
|
|
36 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport
|
|
37 import dwtx.jface.text.TextViewerHoverManager; // packageimport
|
|
38 import dwtx.jface.text.DocumentRewriteSession; // packageimport
|
|
39 import dwtx.jface.text.TextViewer; // packageimport
|
|
40 import dwtx.jface.text.ITextViewerExtension8; // packageimport
|
|
41 import dwtx.jface.text.RegExMessages; // packageimport
|
|
42 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport
|
|
43 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport
|
|
44 import dwtx.jface.text.IWidgetTokenOwner; // packageimport
|
|
45 import dwtx.jface.text.IViewportListener; // packageimport
|
|
46 import dwtx.jface.text.GapTextStore; // packageimport
|
|
47 import dwtx.jface.text.MarkSelection; // packageimport
|
|
48 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport
|
|
49 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport
|
|
50 import dwtx.jface.text.IInformationControlExtension; // packageimport
|
|
51 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport
|
|
52 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport
|
|
53 import dwtx.jface.text.ITextViewerExtension3; // packageimport
|
|
54 import dwtx.jface.text.IInformationControlCreator; // packageimport
|
|
55 import dwtx.jface.text.TypedRegion; // packageimport
|
|
56 import dwtx.jface.text.ISynchronizable; // packageimport
|
|
57 import dwtx.jface.text.IMarkRegionTarget; // packageimport
|
|
58 import dwtx.jface.text.TextViewerUndoManager; // packageimport
|
|
59 import dwtx.jface.text.IRegion; // packageimport
|
|
60 import dwtx.jface.text.IInformationControlExtension2; // packageimport
|
|
61 import dwtx.jface.text.IDocumentExtension4; // packageimport
|
|
62 import dwtx.jface.text.IDocumentExtension2; // packageimport
|
|
63 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport
|
|
64 import dwtx.jface.text.Assert; // packageimport
|
|
65 import dwtx.jface.text.DefaultInformationControl; // packageimport
|
|
66 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport
|
|
67 import dwtx.jface.text.DocumentClone; // packageimport
|
|
68 import dwtx.jface.text.DefaultUndoManager; // packageimport
|
|
69 import dwtx.jface.text.IFindReplaceTarget; // packageimport
|
|
70 import dwtx.jface.text.IAutoEditStrategy; // packageimport
|
|
71 import dwtx.jface.text.ILineTrackerExtension; // packageimport
|
|
72 import dwtx.jface.text.IUndoManagerExtension; // packageimport
|
|
73 import dwtx.jface.text.TextSelection; // packageimport
|
|
74 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport
|
|
75 import dwtx.jface.text.IAutoIndentStrategy; // packageimport
|
|
76 import dwtx.jface.text.IPainter; // packageimport
|
|
77 import dwtx.jface.text.IInformationControl; // packageimport
|
|
78 import dwtx.jface.text.IInformationControlExtension3; // packageimport
|
|
79 import dwtx.jface.text.ITextViewerExtension6; // packageimport
|
|
80 import dwtx.jface.text.IInformationControlExtension4; // packageimport
|
|
81 import dwtx.jface.text.DefaultLineTracker; // packageimport
|
|
82 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport
|
|
83 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport
|
|
84 import dwtx.jface.text.ITextHover; // packageimport
|
|
85 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport
|
|
86 import dwtx.jface.text.ILineTracker; // packageimport
|
|
87 import dwtx.jface.text.Line; // packageimport
|
|
88 import dwtx.jface.text.ITextViewerExtension; // packageimport
|
|
89 import dwtx.jface.text.IDocumentAdapter; // packageimport
|
|
90 import dwtx.jface.text.TextEvent; // packageimport
|
|
91 import dwtx.jface.text.BadLocationException; // packageimport
|
|
92 import dwtx.jface.text.AbstractDocument; // packageimport
|
|
93 import dwtx.jface.text.AbstractLineTracker; // packageimport
|
|
94 import dwtx.jface.text.TreeLineTracker; // packageimport
|
|
95 import dwtx.jface.text.ITextPresentationListener; // packageimport
|
|
96 import dwtx.jface.text.Region; // packageimport
|
|
97 import dwtx.jface.text.ITextViewer; // packageimport
|
|
98 import dwtx.jface.text.IDocumentInformationMapping; // packageimport
|
|
99 import dwtx.jface.text.MarginPainter; // packageimport
|
|
100 import dwtx.jface.text.IPaintPositionManager; // packageimport
|
|
101 import dwtx.jface.text.TextPresentation; // packageimport
|
|
102 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport
|
|
103 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport
|
|
104 import dwtx.jface.text.ISelectionValidator; // packageimport
|
|
105 import dwtx.jface.text.IDocumentExtension; // packageimport
|
|
106 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport
|
|
107 import dwtx.jface.text.ConfigurableLineTracker; // packageimport
|
|
108 import dwtx.jface.text.SlaveDocumentEvent; // packageimport
|
|
109 import dwtx.jface.text.IDocumentListener; // packageimport
|
|
110 import dwtx.jface.text.PaintManager; // packageimport
|
|
111 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport
|
|
112 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport
|
|
113 import dwtx.jface.text.IDocumentExtension3; // packageimport
|
|
114 import dwtx.jface.text.Position; // packageimport
|
|
115 import dwtx.jface.text.TextMessages; // packageimport
|
|
116 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport
|
|
117 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport
|
|
118 import dwtx.jface.text.IPositionUpdater; // packageimport
|
|
119 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport
|
|
120 import dwtx.jface.text.ListLineTracker; // packageimport
|
|
121 import dwtx.jface.text.ITextInputListener; // packageimport
|
|
122 import dwtx.jface.text.BadPositionCategoryException; // packageimport
|
|
123 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport
|
|
124 import dwtx.jface.text.IInputChangedListener; // packageimport
|
|
125 import dwtx.jface.text.ITextOperationTarget; // packageimport
|
|
126 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport
|
|
127 import dwtx.jface.text.ITextViewerExtension7; // packageimport
|
|
128 import dwtx.jface.text.IInformationControlExtension5; // packageimport
|
|
129 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport
|
|
130 import dwtx.jface.text.JFaceTextUtil; // packageimport
|
|
131 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport
|
|
132 import dwtx.jface.text.TabsToSpacesConverter; // packageimport
|
|
133 import dwtx.jface.text.CursorLinePainter; // packageimport
|
|
134 import dwtx.jface.text.ITextHoverExtension; // packageimport
|
|
135 import dwtx.jface.text.IEventConsumer; // packageimport
|
|
136 import dwtx.jface.text.IDocument; // packageimport
|
|
137 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport
|
|
138 import dwtx.jface.text.DocumentCommand; // packageimport
|
|
139 import dwtx.jface.text.TypedPosition; // packageimport
|
|
140 import dwtx.jface.text.IEditingSupportRegistry; // packageimport
|
|
141 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport
|
|
142 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport
|
|
143 import dwtx.jface.text.IEditingSupport; // packageimport
|
|
144 import dwtx.jface.text.IMarkSelection; // packageimport
|
|
145 import dwtx.jface.text.ISlaveDocumentManager; // packageimport
|
|
146 import dwtx.jface.text.DocumentEvent; // packageimport
|
|
147 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport
|
|
148 import dwtx.jface.text.ITextStore; // packageimport
|
|
149 import dwtx.jface.text.JFaceTextMessages; // packageimport
|
|
150 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport
|
|
151 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport
|
|
152 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport
|
|
153 import dwtx.jface.text.TextAttribute; // packageimport
|
|
154 import dwtx.jface.text.ITextViewerExtension4; // packageimport
|
|
155 import dwtx.jface.text.ITypedRegion; // packageimport
|
|
156
|
129
|
157 module dwtx.jface.text.AbstractInformationControlManager;
|
|
158
|
|
159 import dwt.dwthelper.utils;
|
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
|
165 import dwt.DWT;
|
|
166 import dwt.events.DisposeEvent;
|
|
167 import dwt.events.DisposeListener;
|
|
168 import dwt.graphics.GC;
|
|
169 import dwt.graphics.Point;
|
|
170 import dwt.graphics.Rectangle;
|
|
171 import dwt.widgets.Control;
|
|
172 import dwt.widgets.Display;
|
|
173 import dwt.widgets.Monitor;
|
|
174 import dwtx.core.runtime.Assert;
|
|
175 import dwtx.core.runtime.Platform;
|
|
176 import dwtx.jface.dialogs.IDialogSettings;
|
|
177 import dwtx.jface.internal.text.InformationControlReplacer;
|
|
178 import dwtx.jface.internal.text.InternalAccessor;
|
|
179 import dwtx.jface.text.ITextViewerExtension8.EnrichMode;
|
|
180 import dwtx.jface.util.Geometry;
|
|
181
|
|
182
|
|
183 /**
|
|
184 * Manages the life cycle, visibility, layout, and contents of an
|
|
185 * {@link dwtx.jface.text.IInformationControl}. This manager can be
|
|
186 * installed on and removed from a control, referred to as the subject control,
|
|
187 * i.e. the one from which the subject of the information to be shown is
|
|
188 * retrieved. Also a manager can be enabled or disabled. An installed and
|
|
189 * enabled manager can be forced to show information in its information control
|
|
190 * using <code>showInformation</code>. An information control manager uses an
|
|
191 * <code>IInformationControlCloser</code> to define the behavior when a
|
|
192 * presented information control must be closed. The disposal of the subject and
|
|
193 * the information control are internally handled by the information control
|
|
194 * manager and are not the responsibility of the information control closer.
|
|
195 *
|
|
196 * @see dwtx.jface.text.IInformationControl
|
|
197 * @since 2.0
|
|
198 */
|
|
199 abstract public class AbstractInformationControlManager {
|
|
200
|
|
201 /**
|
|
202 * An internal class that gives access to internal methods.
|
|
203 *
|
|
204 * @since 3.4
|
|
205 */
|
|
206 class MyInternalAccessor : InternalAccessor {
|
|
207 public IInformationControl getCurrentInformationControl() {
|
|
208 return AbstractInformationControlManager.this.getCurrentInformationControl();
|
|
209 }
|
|
210
|
|
211 public void setInformationControlReplacer(InformationControlReplacer replacer) {
|
|
212 AbstractInformationControlManager.this.setInformationControlReplacer(replacer);
|
|
213 }
|
|
214
|
|
215 public InformationControlReplacer getInformationControlReplacer() {
|
|
216 return AbstractInformationControlManager.this.getInformationControlReplacer();
|
|
217 }
|
|
218
|
|
219 public bool canReplace(IInformationControl control) {
|
|
220 return AbstractInformationControlManager.this.canReplace(control);
|
|
221 }
|
|
222
|
|
223 public bool isReplaceInProgress() {
|
|
224 return AbstractInformationControlManager.this.isReplaceInProgress();
|
|
225 }
|
|
226
|
|
227 public void replaceInformationControl(bool takeFocus) {
|
|
228 AbstractInformationControlManager.this.replaceInformationControl(takeFocus);
|
|
229 }
|
|
230
|
|
231 public void cropToClosestMonitor(Rectangle bounds) {
|
|
232 AbstractInformationControlManager.this.cropToClosestMonitor(bounds);
|
|
233 }
|
|
234
|
|
235 public void setHoverEnrichMode(EnrichMode mode) {
|
|
236 throw new UnsupportedOperationException("only implemented in AbstractHoverInformationControlManager"); //$NON-NLS-1$
|
|
237 }
|
|
238
|
|
239 public bool getAllowMouseExit() {
|
|
240 throw new UnsupportedOperationException("only implemented in AnnotationBarHoverManager"); //$NON-NLS-1$
|
|
241 }
|
|
242 }
|
|
243
|
|
244 /**
|
|
245 * Interface of an information control closer. An information control closer
|
|
246 * monitors its information control and its subject control and closes the
|
|
247 * information control if necessary.
|
|
248 * <p>
|
|
249 * Clients must implement this interface in order to equip an information
|
|
250 * control manager accordingly.
|
|
251 */
|
|
252 public interface IInformationControlCloser {
|
|
253
|
|
254 /**
|
|
255 * Sets the closer's subject control. This is the control that parents
|
|
256 * the information control and from which the subject of the information
|
|
257 * to be shown is retrieved. <p>
|
|
258 * Must be called before <code>start</code>. May again be called
|
|
259 * between <code>start</code> and <code>stop</code>.
|
|
260 *
|
|
261 * @param subject the subject control
|
|
262 */
|
|
263 public void setSubjectControl(Control subject);
|
|
264
|
|
265 /**
|
|
266 * Sets the closer's information control, the one to close if necessary. <p>
|
|
267 * Must be called before <code>start</code>. May again be called
|
|
268 * between <code>start</code> and <code>stop</code>.
|
|
269 *
|
|
270 * @param control the information control
|
|
271 */
|
|
272 public void setInformationControl(IInformationControl control);
|
|
273
|
|
274 /**
|
|
275 * Tells this closer to start monitoring the subject and the information
|
|
276 * control. The presented information is considered valid for the given
|
|
277 * area of the subject control's display.
|
|
278 *
|
|
279 * @param subjectArea the area for which the presented information is valid
|
|
280 */
|
|
281 public void start(Rectangle subjectArea);
|
|
282
|
|
283 /**
|
|
284 * Tells this closer to stop monitoring the subject and the information control.
|
|
285 */
|
|
286 public void stop();
|
|
287 }
|
|
288
|
|
289
|
|
290
|
|
291 /**
|
|
292 * Constitutes entities to enumerate anchors for the layout of the information control.
|
|
293 */
|
|
294 public static final class Anchor {
|
|
295 private final int fFlag;
|
|
296 private Anchor(int flag) {
|
|
297 fFlag= flag;
|
|
298 }
|
|
299 /**
|
|
300 * Returns the DWT direction flag. One of {@link DWT#BOTTOM}, {@link DWT#TOP},
|
|
301 * {@link DWT#LEFT}, {@link DWT#RIGHT}, {@link DWT#CENTER},
|
|
302 *
|
|
303 * @return the DWT direction flag
|
|
304 * @since 3.3
|
|
305 */
|
|
306 int getSWTFlag() {
|
|
307 return fFlag;
|
|
308 }
|
|
309
|
|
310 public String toString() {
|
|
311 switch (fFlag) {
|
|
312 case DWT.BOTTOM: return "BOTTOM"; //$NON-NLS-1$
|
|
313 case DWT.TOP: return "TOP"; //$NON-NLS-1$
|
|
314 case DWT.LEFT: return "LEFT"; //$NON-NLS-1$
|
|
315 case DWT.RIGHT: return "RIGHT"; //$NON-NLS-1$
|
|
316 case DWT.CENTER: return "CENTER"; //$NON-NLS-1$
|
|
317 default: return Integer.toHexString(fFlag);
|
|
318 }
|
|
319 }
|
|
320 }
|
|
321
|
|
322 /** Internal anchor list. */
|
|
323 private final static Anchor[] ANCHORS= { new Anchor(DWT.TOP), new Anchor(DWT.BOTTOM), new Anchor(DWT.LEFT), new Anchor(DWT.RIGHT) };
|
|
324
|
|
325 /** Anchor representing the top of the information area */
|
|
326 public final static Anchor ANCHOR_TOP= ANCHORS[0];
|
|
327 /** Anchor representing the bottom of the information area */
|
|
328 public final static Anchor ANCHOR_BOTTOM= ANCHORS[1];
|
|
329 /** Anchor representing the left side of the information area */
|
|
330 public final static Anchor ANCHOR_LEFT= ANCHORS[2];
|
|
331 /** Anchor representing the right side of the information area */
|
|
332 public final static Anchor ANCHOR_RIGHT= ANCHORS[3];
|
|
333 /**
|
|
334 * Anchor representing the middle of the subject control
|
|
335 * @since 2.1
|
|
336 */
|
|
337 public final static Anchor ANCHOR_GLOBAL= new Anchor(DWT.CENTER);
|
|
338
|
|
339 /**
|
|
340 * Dialog store constant for the location's x-coordinate.
|
|
341 * @since 3.0
|
|
342 */
|
|
343 public static final String STORE_LOCATION_X= "location.x"; //$NON-NLS-1$
|
|
344 /**
|
|
345 * Dialog store constant for the location's y-coordinate.
|
|
346 * @since 3.0
|
|
347 */
|
|
348 public static final String STORE_LOCATION_Y= "location.y"; //$NON-NLS-1$
|
|
349 /**
|
|
350 * Dialog store constant for the size's width.
|
|
351 * @since 3.0
|
|
352 */
|
|
353 public static final String STORE_SIZE_WIDTH= "size.width"; //$NON-NLS-1$
|
|
354 /**
|
|
355 * Dialog store constant for the size's height.
|
|
356 * @since 3.0
|
|
357 */
|
|
358 public static final String STORE_SIZE_HEIGHT= "size.height"; //$NON-NLS-1$
|
|
359
|
|
360 /**
|
|
361 * Tells whether this class and its subclasses are in debug mode.
|
|
362 * <p>
|
|
363 * Subclasses may use this.
|
|
364 * </p>
|
|
365 * @since 3.4
|
|
366 */
|
|
367 protected static final bool DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("dwtx.jface.text/debug/AbstractInformationControlManager")); //$NON-NLS-1$//$NON-NLS-2$
|
|
368
|
|
369
|
|
370 /** The subject control of the information control */
|
|
371 private Control fSubjectControl;
|
|
372
|
|
373 /** The display area for which the information to be presented is valid */
|
|
374 private Rectangle fSubjectArea;
|
|
375
|
|
376 /** The information to be presented */
|
|
377 private Object fInformation;
|
|
378
|
|
379 /** Indicates whether the information control takes focus when visible */
|
|
380 private bool fTakesFocusWhenVisible= false;
|
|
381
|
|
382 /**
|
|
383 * The information control.
|
|
384 *
|
|
385 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API
|
|
386 * compatibility reasons.
|
|
387 */
|
|
388 protected IInformationControl fInformationControl;
|
|
389
|
|
390 /**
|
|
391 * The information control creator.
|
|
392 *
|
|
393 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API
|
|
394 * compatibility reasons.
|
|
395 */
|
|
396 protected IInformationControlCreator fInformationControlCreator;
|
|
397
|
|
398 /**
|
|
399 * The information control closer.
|
|
400 *
|
|
401 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API
|
|
402 * compatibility reasons.
|
|
403 */
|
|
404 protected IInformationControlCloser fInformationControlCloser;
|
|
405
|
|
406 /**
|
|
407 * Indicates that the information control has been disposed.
|
|
408 *
|
|
409 * <p>This field should not be referenced by subclasses. It is <code>protected</code> for API
|
|
410 * compatibility reasons.
|
|
411 */
|
|
412 protected bool fDisposed= false;
|
|
413
|
|
414 /**
|
|
415 * The information control replacer to be used when this information control
|
|
416 * needs to be replaced with another information control.
|
|
417 *
|
|
418 * @since 3.4
|
|
419 */
|
|
420 private InformationControlReplacer fInformationControlReplacer;
|
|
421
|
|
422 /** Indicates the enable state of this manager */
|
|
423 private bool fEnabled= false;
|
|
424
|
|
425 /** Cached, computed size constraints of the information control in points */
|
|
426 private Point fSizeConstraints;
|
|
427
|
|
428 /** The vertical margin when laying out the information control */
|
|
429 private int fMarginY= 5;
|
|
430
|
|
431 /** The horizontal margin when laying out the information control */
|
|
432 private int fMarginX= 5;
|
|
433
|
|
434 /** The width constraint of the information control in characters */
|
|
435 private int fWidthConstraint= 60;
|
|
436
|
|
437 /** The height constraint of the information control in characters */
|
|
438 private int fHeightConstraint= 6;
|
|
439
|
|
440 /** Indicates whether the size constraints should be enforced as minimal control size */
|
|
441 private bool fEnforceAsMinimalSize= false;
|
|
442
|
|
443 /** Indicates whether the size constraints should be enforced as maximal control size */
|
|
444 private bool fEnforceAsMaximalSize= false;
|
|
445
|
|
446 /** The anchor for laying out the information control in relation to the subject control */
|
|
447 private Anchor fAnchor= ANCHOR_BOTTOM;
|
|
448
|
|
449 /**
|
|
450 * The anchor sequence used to layout the information control if the original anchor
|
|
451 * can not be used because the information control would not fit in the display client area.
|
|
452 * <p>
|
|
453 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or
|
|
454 * is the first one in the sequence if the given anchor is the last one in the sequence.
|
|
455 * <p>
|
|
456 * </p>
|
|
457 * Note: This sequence is ignored if the original anchor is not contained in this sequence.
|
|
458 * </p>
|
|
459 *
|
|
460 * @see #fAnchor
|
|
461 */
|
|
462 private Anchor[] fFallbackAnchors= ANCHORS;
|
|
463
|
|
464 /**
|
|
465 * The custom information control creator.
|
|
466 * @since 3.0
|
|
467 */
|
|
468 private volatile IInformationControlCreator fCustomInformationControlCreator;
|
|
469
|
|
470 /**
|
|
471 * Tells whether a custom information control is in use.
|
|
472 * @since 3.0
|
|
473 */
|
|
474 private bool fIsCustomInformationControl= false;
|
|
475
|
|
476 /**
|
|
477 * The dialog settings for the control's bounds.
|
|
478 * @since 3.0
|
|
479 */
|
|
480 private IDialogSettings fDialogSettings;
|
|
481
|
|
482 /**
|
|
483 * Tells whether the control's location should be read
|
|
484 * from the dialog settings and whether the last
|
|
485 * valid control's size is stored back into the settings.
|
|
486 *
|
|
487 * @since 3.0
|
|
488 */
|
|
489 private bool fIsRestoringLocation;
|
|
490
|
|
491 /**
|
|
492 * Tells whether the control's size should be read
|
|
493 * from the dialog settings and whether the last
|
|
494 * valid control's size is stored back into the settings.
|
|
495 *
|
|
496 * @since 3.0
|
|
497 */
|
|
498 private bool fIsRestoringSize;
|
|
499
|
|
500 /**
|
|
501 * The dispose listener on the subject control.
|
|
502 *
|
|
503 * @since 3.1
|
|
504 */
|
|
505 private DisposeListener fSubjectControlDisposeListener;
|
|
506
|
|
507
|
|
508 /**
|
|
509 * Creates a new information control manager using the given information control creator.
|
|
510 * By default the following configuration is given:
|
|
511 * <ul>
|
|
512 * <li> enabled is false
|
|
513 * <li> horizontal margin is 5 points
|
|
514 * <li> vertical margin is 5 points
|
|
515 * <li> width constraint is 60 characters
|
|
516 * <li> height constraint is 6 characters
|
|
517 * <li> enforce constraints as minimal size is false
|
|
518 * <li> enforce constraints as maximal size is false
|
|
519 * <li> layout anchor is ANCHOR_BOTTOM
|
|
520 * <li> fall back anchors is { ANCHOR_TOP, ANCHOR_BOTTOM, ANCHOR_LEFT, ANCHOR_RIGHT, ANCHOR_GLOBAL }
|
|
521 * <li> takes focus when visible is false
|
|
522 * </ul>
|
|
523 *
|
|
524 * @param creator the information control creator
|
|
525 */
|
|
526 protected AbstractInformationControlManager(IInformationControlCreator creator) {
|
|
527 Assert.isNotNull(creator);
|
|
528 fInformationControlCreator= creator;
|
|
529 }
|
|
530
|
|
531 /**
|
|
532 * Computes the information to be displayed and the area in which the computed
|
|
533 * information is valid. Implementation of this method must finish their computation
|
|
534 * by setting the computation results using <code>setInformation</code>.
|
|
535 */
|
|
536 abstract protected void computeInformation();
|
|
537
|
|
538 /**
|
|
539 * Sets the parameters of the information to be displayed. These are the information itself and
|
|
540 * the area for which the given information is valid. This so called subject area is a graphical
|
|
541 * region of the information control's subject control. This method calls <code>presentInformation()</code>
|
|
542 * to trigger the presentation of the computed information.
|
|
543 *
|
|
544 * @param information the information, or <code>null</code> if none is available
|
|
545 * @param subjectArea the subject area, or <code>null</code> if none is available
|
|
546 */
|
|
547 protected final void setInformation(String information, Rectangle subjectArea) {
|
|
548 setInformation((Object)information, subjectArea);
|
|
549 }
|
|
550
|
|
551 /**
|
|
552 * Sets the parameters of the information to be displayed. These are the information itself and
|
|
553 * the area for which the given information is valid. This so called subject area is a graphical
|
|
554 * region of the information control's subject control. This method calls <code>presentInformation()</code>
|
|
555 * to trigger the presentation of the computed information.
|
|
556 *
|
|
557 * @param information the information, or <code>null</code> if none is available
|
|
558 * @param subjectArea the subject area, or <code>null</code> if none is available
|
|
559 * @since 2.1
|
|
560 */
|
|
561 protected final void setInformation(Object information, Rectangle subjectArea) {
|
|
562 fInformation= information;
|
|
563 fSubjectArea= subjectArea;
|
|
564 presentInformation();
|
|
565 }
|
|
566
|
|
567 /**
|
|
568 * Sets the information control closer for this manager.
|
|
569 *
|
|
570 * @param closer the information control closer for this manager
|
|
571 */
|
|
572 protected void setCloser(IInformationControlCloser closer) {
|
|
573 fInformationControlCloser= closer;
|
|
574 }
|
|
575
|
|
576 /**
|
|
577 * Sets the information control replacer for this manager and disposes the
|
|
578 * old one if set.
|
|
579 *
|
|
580 * @param replacer the information control replacer for this manager, or
|
|
581 * <code>null</code> if no information control replacing should
|
|
582 * take place
|
|
583 * @since 3.4
|
|
584 */
|
|
585 void setInformationControlReplacer(InformationControlReplacer replacer) {
|
|
586 if (fInformationControlReplacer !is null)
|
|
587 fInformationControlReplacer.dispose();
|
|
588 fInformationControlReplacer= replacer;
|
|
589 }
|
|
590
|
|
591 /**
|
|
592 * Returns the current information control replacer or <code>null</code> if none has been installed.
|
|
593 *
|
|
594 * @return the current information control replacer or <code>null</code> if none has been installed
|
|
595 * @since 3.4
|
|
596 */
|
|
597 InformationControlReplacer getInformationControlReplacer() {
|
|
598 return fInformationControlReplacer;
|
|
599 }
|
|
600
|
|
601 /**
|
|
602 * Returns whether an information control replacer has been installed.
|
|
603 *
|
|
604 * @return whether an information control replacer has been installed
|
|
605 * @since 3.4
|
|
606 */
|
|
607 bool hasInformationControlReplacer() {
|
|
608 return fInformationControlReplacer !is null;
|
|
609 }
|
|
610
|
|
611 /**
|
|
612 * Tests whether the given information control is replaceable.
|
|
613 *
|
|
614 * @param iControl information control or <code>null</code> if none
|
|
615 * @return <code>true</code> if information control is replaceable, <code>false</code> otherwise
|
|
616 * @since 3.4
|
|
617 */
|
|
618 bool canReplace(IInformationControl iControl) {
|
|
619 return iControl instanceof IInformationControlExtension3
|
|
620 && iControl instanceof IInformationControlExtension5
|
|
621 && ((IInformationControlExtension5) iControl).getInformationPresenterControlCreator() !is null;
|
|
622 }
|
|
623
|
|
624 /**
|
|
625 * Returns the current information control, or <code>null</code> if none.
|
|
626 *
|
|
627 * @return the current information control, or <code>null</code> if none
|
|
628 * @since 3.4
|
|
629 */
|
|
630 IInformationControl getCurrentInformationControl() {
|
|
631 return fInformationControl;
|
|
632 }
|
|
633
|
|
634 /**
|
|
635 * Tells whether this manager's information control is currently being replaced.
|
|
636 *
|
|
637 * @return <code>true</code> if a replace is in progress
|
|
638 * @since 3.4
|
|
639 */
|
|
640 bool isReplaceInProgress() {
|
|
641 return fInformationControlReplacer !is null && fInformationControlReplacer.isReplacing();
|
|
642 }
|
|
643
|
|
644 /**
|
|
645 * Sets the horizontal and vertical margin to be used when laying out the
|
|
646 * information control relative to the subject control.
|
|
647 *
|
|
648 * @param xMargin the x-margin
|
|
649 * @param yMargin the y-Margin
|
|
650 */
|
|
651 public void setMargins(int xMargin, int yMargin) {
|
|
652 fMarginX= xMargin;
|
|
653 fMarginY= yMargin;
|
|
654 }
|
|
655
|
|
656 /**
|
|
657 * Sets the width- and height constraints of the information control.
|
|
658 *
|
|
659 * @param widthInChar the width constraint in number of characters
|
|
660 * @param heightInChar the height constrain in number of characters
|
|
661 * @param enforceAsMinimalSize indicates whether the constraints describe the minimal allowed size of the control
|
|
662 * @param enforceAsMaximalSize indicates whether the constraints describe the maximal allowed size of the control
|
|
663 */
|
|
664 public void setSizeConstraints(int widthInChar, int heightInChar, bool enforceAsMinimalSize, bool enforceAsMaximalSize) {
|
|
665 fSizeConstraints= null;
|
|
666 fWidthConstraint= widthInChar;
|
|
667 fHeightConstraint= heightInChar;
|
|
668 fEnforceAsMinimalSize= enforceAsMinimalSize;
|
|
669 fEnforceAsMaximalSize= enforceAsMaximalSize;
|
|
670
|
|
671 }
|
|
672
|
|
673 /**
|
|
674 * Tells this information control manager to open the information
|
|
675 * control with the values contained in the given dialog settings
|
|
676 * and to store the control's last valid size in the given dialog
|
|
677 * settings.
|
|
678 * <p>
|
|
679 * Note: This API is only valid if the information control implements
|
|
680 * {@link IInformationControlExtension3}. Not following this restriction
|
|
681 * will later result in an {@link UnsupportedOperationException}.
|
|
682 * </p>
|
|
683 * <p>
|
|
684 * The constants used to store the values are:
|
|
685 * <ul>
|
|
686 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_X}</li>
|
|
687 * <li>{@link AbstractInformationControlManager#STORE_LOCATION_Y}</li>
|
|
688 * <li>{@link AbstractInformationControlManager#STORE_SIZE_WIDTH}</li>
|
|
689 * <li>{@link AbstractInformationControlManager#STORE_SIZE_HEIGHT}</li>
|
|
690 * </ul>
|
|
691 * </p>
|
|
692 *
|
|
693 * @param dialogSettings
|
|
694 * @param restoreLocation <code>true</code> iff the location is must be (re-)stored
|
|
695 * @param restoreSize <code>true</code>iff the size is (re-)stored
|
|
696 * @since 3.0
|
|
697 */
|
|
698 public void setRestoreInformationControlBounds(IDialogSettings dialogSettings, bool restoreLocation, bool restoreSize) {
|
|
699 Assert.isTrue(dialogSettings !is null && (restoreLocation || restoreSize));
|
|
700 fDialogSettings= dialogSettings;
|
|
701 fIsRestoringLocation= restoreLocation;
|
|
702 fIsRestoringSize= restoreSize;
|
|
703 }
|
|
704
|
|
705 /**
|
|
706 * Sets the anchor used for laying out the information control relative to the
|
|
707 * subject control. E.g, using <code>ANCHOR_TOP</code> indicates that the
|
|
708 * information control is position above the area for which the information to
|
|
709 * be displayed is valid.
|
|
710 *
|
|
711 * @param anchor the layout anchor
|
|
712 */
|
|
713 public void setAnchor(Anchor anchor) {
|
|
714 fAnchor= anchor;
|
|
715 }
|
|
716
|
|
717 /**
|
|
718 * Sets the anchors fallback sequence used to layout the information control if the original
|
|
719 * anchor can not be used because the information control would not fit in the display client
|
|
720 * area.
|
|
721 * <p>
|
|
722 * The fallback anchor for a given anchor is the one that comes directly after the given anchor or
|
|
723 * is the first one in the sequence if the given anchor is the last one in the sequence.
|
|
724 * <p>
|
|
725 * </p>
|
|
726 * Note: This sequence is ignored if the original anchor is not contained in this list.
|
|
727 * </p>
|
|
728 *
|
|
729 * @param fallbackAnchors the array with the anchor fallback sequence
|
|
730 * @see #setAnchor(AbstractInformationControlManager.Anchor)
|
|
731 */
|
|
732 public void setFallbackAnchors(Anchor[] fallbackAnchors) {
|
|
733 if (fallbackAnchors !is null) {
|
|
734 fFallbackAnchors= new Anchor[fallbackAnchors.length];
|
|
735 System.arraycopy(fallbackAnchors, 0, fFallbackAnchors, 0, fallbackAnchors.length);
|
|
736 } else
|
|
737 fFallbackAnchors= null;
|
|
738 }
|
|
739
|
|
740 /**
|
|
741 * Sets the temporary custom control creator, overriding this manager's default information control creator.
|
|
742 *
|
|
743 * @param informationControlCreator the creator, possibly <code>null</code>
|
|
744 * @since 3.0
|
|
745 */
|
|
746 protected void setCustomInformationControlCreator(IInformationControlCreator informationControlCreator) {
|
|
747 if (informationControlCreator !is null && fCustomInformationControlCreator instanceof IInformationControlCreatorExtension) {
|
|
748 IInformationControlCreatorExtension extension= (IInformationControlCreatorExtension) fCustomInformationControlCreator;
|
|
749 if (extension.canReplace(informationControlCreator))
|
|
750 return;
|
|
751 }
|
|
752 fCustomInformationControlCreator= informationControlCreator;
|
|
753 }
|
|
754
|
|
755 /**
|
|
756 * Tells the manager whether it should set the focus to the information control when made visible.
|
|
757 *
|
|
758 * @param takesFocus <code>true</code> if information control should take focus when made visible
|
|
759 */
|
|
760 public void takesFocusWhenVisible(bool takesFocus) {
|
|
761 fTakesFocusWhenVisible= takesFocus;
|
|
762 }
|
|
763
|
|
764 /**
|
|
765 * Handles the disposal of the subject control. By default, the information control
|
|
766 * is disposed by calling <code>disposeInformationControl</code>. Subclasses may extend
|
|
767 * this method.
|
|
768 */
|
|
769 protected void handleSubjectControlDisposed() {
|
|
770 disposeInformationControl();
|
|
771 }
|
|
772
|
|
773 /**
|
|
774 * Installs this manager on the given control. The control is now taking the role of
|
|
775 * the subject control. This implementation sets the control also as the information
|
|
776 * control closer's subject control and automatically enables this manager.
|
|
777 *
|
|
778 * @param subjectControl the subject control
|
|
779 */
|
|
780 public void install(Control subjectControl) {
|
|
781 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null)
|
|
782 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener);
|
|
783
|
|
784 fSubjectControl= subjectControl;
|
|
785
|
|
786 if (fSubjectControl !is null)
|
|
787 fSubjectControl.addDisposeListener(getSubjectControlDisposeListener());
|
|
788
|
|
789 if (fInformationControlCloser !is null)
|
|
790 fInformationControlCloser.setSubjectControl(subjectControl);
|
|
791
|
|
792 setEnabled(true);
|
|
793 fDisposed= false;
|
|
794 }
|
|
795
|
|
796 /**
|
|
797 * Returns the dispose listener which gets added
|
|
798 * to the subject control.
|
|
799 *
|
|
800 * @return the dispose listener
|
|
801 * @since 3.1
|
|
802 */
|
|
803 private DisposeListener getSubjectControlDisposeListener() {
|
|
804 if (fSubjectControlDisposeListener is null) {
|
|
805 fSubjectControlDisposeListener= new DisposeListener() {
|
|
806 public void widgetDisposed(DisposeEvent e) {
|
|
807 handleSubjectControlDisposed();
|
|
808 }
|
|
809 };
|
|
810 }
|
|
811 return fSubjectControlDisposeListener;
|
|
812 }
|
|
813
|
|
814 /**
|
|
815 * Returns the subject control of this manager/information control.
|
|
816 *
|
|
817 * @return the subject control
|
|
818 */
|
|
819 protected Control getSubjectControl() {
|
|
820 return fSubjectControl;
|
|
821 }
|
|
822
|
|
823 /**
|
|
824 * Returns the actual subject area.
|
|
825 *
|
|
826 * @return the actual subject area
|
|
827 */
|
|
828 protected Rectangle getSubjectArea() {
|
|
829 return fSubjectArea;
|
|
830 }
|
|
831
|
|
832 /**
|
|
833 * Sets the enable state of this manager.
|
|
834 *
|
|
835 * @param enabled the enable state
|
|
836 * @deprecated visibility will be changed to protected
|
|
837 */
|
|
838 public void setEnabled(bool enabled) {
|
|
839 fEnabled= enabled;
|
|
840 }
|
|
841
|
|
842 /**
|
|
843 * Returns whether this manager is enabled or not.
|
|
844 *
|
|
845 * @return <code>true</code> if this manager is enabled otherwise <code>false</code>
|
|
846 */
|
|
847 protected bool isEnabled() {
|
|
848 return fEnabled;
|
|
849 }
|
|
850
|
|
851 /**
|
|
852 * Computes the size constraints of the information control in points based on the
|
|
853 * default font of the given subject control as well as the size constraints in character
|
|
854 * width.
|
|
855 *
|
|
856 * @param subjectControl the subject control
|
|
857 * @param informationControl the information control whose size constraints are computed
|
|
858 * @return the computed size constraints in points
|
|
859 */
|
|
860 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) {
|
|
861
|
|
862 if (fSizeConstraints is null) {
|
|
863 if (informationControl instanceof IInformationControlExtension5) {
|
|
864 IInformationControlExtension5 iControl5= (IInformationControlExtension5) informationControl;
|
|
865 fSizeConstraints= iControl5.computeSizeConstraints(fWidthConstraint, fHeightConstraint);
|
|
866 if (fSizeConstraints !is null)
|
|
867 return Geometry.copy(fSizeConstraints);
|
|
868 }
|
|
869 if (subjectControl is null)
|
|
870 return null;
|
|
871
|
|
872 GC gc= new GC(subjectControl);
|
|
873 gc.setFont(subjectControl.getFont());
|
|
874 int width= gc.getFontMetrics().getAverageCharWidth();
|
|
875 int height = gc.getFontMetrics().getHeight();
|
|
876 gc.dispose();
|
|
877
|
|
878 fSizeConstraints= new Point (fWidthConstraint * width, fHeightConstraint * height);
|
|
879 }
|
|
880
|
|
881 return new Point(fSizeConstraints.x, fSizeConstraints.y);
|
|
882 }
|
|
883
|
|
884 /**
|
|
885 * Computes the size constraints of the information control in points.
|
|
886 *
|
|
887 * @param subjectControl the subject control
|
|
888 * @param subjectArea the subject area
|
|
889 * @param informationControl the information control whose size constraints are computed
|
|
890 * @return the computed size constraints in points
|
|
891 * @since 3.0
|
|
892 */
|
|
893 protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) {
|
|
894 return computeSizeConstraints(subjectControl, informationControl);
|
|
895 }
|
|
896
|
|
897 /**
|
|
898 * Handles the disposal of the information control. By default, the information
|
|
899 * control closer is stopped.
|
|
900 */
|
|
901 protected void handleInformationControlDisposed() {
|
|
902
|
|
903 storeInformationControlBounds();
|
|
904
|
|
905 if (fInformationControl instanceof IInformationControlExtension5)
|
|
906 fSizeConstraints= null;
|
|
907 fInformationControl= null;
|
|
908 if (fInformationControlCloser !is null) {
|
|
909 fInformationControlCloser.setInformationControl(null); //XXX: null is against the spec
|
|
910 fInformationControlCloser.stop();
|
|
911 }
|
|
912 }
|
|
913
|
|
914 /**
|
|
915 * Returns the information control. If the information control has not been created yet,
|
|
916 * it is automatically created.
|
|
917 *
|
|
918 * @return the information control
|
|
919 */
|
|
920 protected IInformationControl getInformationControl() {
|
|
921
|
|
922 if (fDisposed)
|
|
923 return fInformationControl;
|
|
924
|
|
925 IInformationControlCreator creator= null;
|
|
926
|
|
927 if (fCustomInformationControlCreator is null) {
|
|
928 creator= fInformationControlCreator;
|
|
929 if (fIsCustomInformationControl && fInformationControl !is null) {
|
|
930 if (fInformationControl instanceof IInformationControlExtension5)
|
|
931 fSizeConstraints= null;
|
|
932 fInformationControl.dispose();
|
|
933 fInformationControl= null;
|
|
934 }
|
|
935 fIsCustomInformationControl= false;
|
|
936
|
|
937 } else {
|
|
938
|
|
939 creator= fCustomInformationControlCreator;
|
|
940 if (creator instanceof IInformationControlCreatorExtension) {
|
|
941 IInformationControlCreatorExtension extension= (IInformationControlCreatorExtension) creator;
|
|
942 if (fInformationControl !is null && extension.canReuse(fInformationControl))
|
|
943 return fInformationControl;
|
|
944 }
|
|
945 if (fInformationControl !is null) {
|
|
946 if (fInformationControl instanceof IInformationControlExtension5)
|
|
947 fSizeConstraints= null;
|
|
948 fInformationControl.dispose();
|
|
949 fInformationControl= null;
|
|
950 }
|
|
951 fIsCustomInformationControl= true;
|
|
952 }
|
|
953
|
|
954 if (fInformationControl is null) {
|
|
955 fInformationControl= creator.createInformationControl(fSubjectControl.getShell());
|
|
956 fInformationControl.addDisposeListener(new DisposeListener() {
|
|
957 public void widgetDisposed(DisposeEvent e) {
|
|
958 handleInformationControlDisposed();
|
|
959 }
|
|
960 });
|
|
961
|
|
962 if (fInformationControlCloser !is null)
|
|
963 fInformationControlCloser.setInformationControl(fInformationControl);
|
|
964 }
|
|
965
|
|
966 return fInformationControl;
|
|
967 }
|
|
968
|
|
969 /**
|
|
970 * Computes the display location of the information control. The location is computed
|
|
971 * considering the given subject area, the anchor at the subject area, and the
|
|
972 * size of the information control. This method does not care about whether the information
|
|
973 * control would be completely visible when placed at the result location.
|
|
974 *
|
|
975 * @param subjectArea the subject area
|
|
976 * @param controlSize the size of the information control
|
|
977 * @param anchor the anchor at the subject area
|
|
978 * @return the display location of the information control
|
|
979 */
|
|
980 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) {
|
|
981 int xShift= 0;
|
|
982 int yShift= 0;
|
|
983
|
|
984 switch (anchor.getSWTFlag()) {
|
|
985 case DWT.CENTER:
|
|
986 Point subjectControlSize= fSubjectControl.getSize();
|
|
987 Point location= new Point(subjectControlSize.x / 2, subjectControlSize.y / 2);
|
|
988 location.x -= (controlSize.x / 2);
|
|
989 location.y -= (controlSize.y / 2);
|
|
990 return fSubjectControl.toDisplay(location);
|
|
991 case DWT.BOTTOM:
|
|
992 yShift= subjectArea.height + fMarginY;
|
|
993 break;
|
|
994 case DWT.RIGHT:
|
|
995 xShift= fMarginX + subjectArea.width;
|
|
996 break;
|
|
997 case DWT.TOP:
|
|
998 yShift= -controlSize.y - fMarginY;
|
|
999 break;
|
|
1000 case DWT.LEFT:
|
|
1001 xShift= -controlSize.x - fMarginX;
|
|
1002 break;
|
|
1003 }
|
|
1004
|
|
1005 bool isRTL= fSubjectControl !is null && (fSubjectControl.getStyle() & DWT.RIGHT_TO_LEFT) !is 0;
|
|
1006 if (isRTL)
|
|
1007 xShift += controlSize.x;
|
|
1008
|
|
1009 return fSubjectControl.toDisplay(new Point(subjectArea.x + xShift, subjectArea.y + yShift));
|
|
1010 }
|
|
1011
|
|
1012 /**
|
|
1013 * Computes the area available for an information control given an anchor and the subject area
|
|
1014 * within <code>bounds</code>.
|
|
1015 *
|
|
1016 * @param subjectArea the subject area
|
|
1017 * @param bounds the bounds
|
|
1018 * @param anchor the anchor at the subject area
|
|
1019 * @return the area available at the given anchor relative to the subject area, confined to the
|
|
1020 * monitor's client area
|
|
1021 * @since 3.3
|
|
1022 */
|
|
1023 protected Rectangle computeAvailableArea(Rectangle subjectArea, Rectangle bounds, Anchor anchor) {
|
|
1024 Rectangle area;
|
|
1025 switch (anchor.getSWTFlag()) {
|
|
1026 case DWT.CENTER:
|
|
1027 area= bounds;
|
|
1028 break;
|
|
1029 case DWT.BOTTOM:
|
|
1030 int y= subjectArea.y + subjectArea.height + fMarginY;
|
|
1031 area= new Rectangle(bounds.x, y, bounds.width, bounds.y + bounds.height - y);
|
|
1032 break;
|
|
1033 case DWT.RIGHT:
|
|
1034 int x= subjectArea.x + subjectArea.width + fMarginX;
|
|
1035 area= new Rectangle(x, bounds.y, bounds.x + bounds.width - x, bounds.height);
|
|
1036 break;
|
|
1037 case DWT.TOP:
|
|
1038 area= new Rectangle(bounds.x, bounds.y, bounds.width, subjectArea.y - bounds.y - fMarginY);
|
|
1039 break;
|
|
1040 case DWT.LEFT:
|
|
1041 area= new Rectangle(bounds.x, bounds.y, subjectArea.x - bounds.x - fMarginX, bounds.height);
|
|
1042 break;
|
|
1043 default:
|
|
1044 Assert.isLegal(false);
|
|
1045 return null;
|
|
1046 }
|
|
1047
|
|
1048 // Don't return negative areas if the subjectArea overlaps with the monitor bounds.
|
|
1049 area.intersect(bounds);
|
|
1050 return area;
|
|
1051 }
|
|
1052
|
|
1053 /**
|
|
1054 * Checks whether a control of the given size at the given location would be completely visible
|
|
1055 * in the given display area when laid out by using the given anchor. If not, this method tries
|
|
1056 * to shift the control orthogonal to the direction given by the anchor to make it visible. If possible
|
|
1057 * it updates the location.<p>
|
|
1058 * This method returns <code>true</code> if the potentially updated position results in a
|
|
1059 * completely visible control, or <code>false</code> otherwise.
|
|
1060 *
|
|
1061 *
|
|
1062 * @param location the location of the control
|
|
1063 * @param size the size of the control
|
|
1064 * @param displayArea the display area in which the control should be visible
|
|
1065 * @param anchor anchor for lying out the control
|
|
1066 * @return <code>true</code>if the updated location is useful
|
|
1067 */
|
|
1068 protected bool updateLocation(Point location, Point size, Rectangle displayArea, Anchor anchor) {
|
|
1069
|
|
1070 int displayLowerRightX= displayArea.x + displayArea.width;
|
|
1071 int displayLowerRightY= displayArea.y + displayArea.height;
|
|
1072 int lowerRightX= location.x + size.x;
|
|
1073 int lowerRightY= location.y + size.y;
|
|
1074
|
|
1075 if (ANCHOR_BOTTOM is anchor || ANCHOR_TOP is anchor) {
|
|
1076
|
|
1077 if (ANCHOR_BOTTOM is anchor) {
|
|
1078 if (lowerRightY > displayLowerRightY)
|
|
1079 return false;
|
|
1080 } else {
|
|
1081 if (location.y < displayArea.y)
|
|
1082 return false;
|
|
1083 }
|
|
1084
|
|
1085 if (lowerRightX > displayLowerRightX)
|
|
1086 location.x= location.x - (lowerRightX - displayLowerRightX);
|
|
1087
|
|
1088 return (location.x >= displayArea.x && location.y >= displayArea.y);
|
|
1089
|
|
1090 } else if (ANCHOR_RIGHT is anchor || ANCHOR_LEFT is anchor) {
|
|
1091
|
|
1092 if (ANCHOR_RIGHT is anchor) {
|
|
1093 if (lowerRightX > displayLowerRightX)
|
|
1094 return false;
|
|
1095 } else {
|
|
1096 if (location.x < displayArea.x)
|
|
1097 return false;
|
|
1098 }
|
|
1099
|
|
1100 if (lowerRightY > displayLowerRightY)
|
|
1101 location.y= location.y - (lowerRightY - displayLowerRightY);
|
|
1102
|
|
1103 return (location.x >= displayArea.x && location.y >= displayArea.y);
|
|
1104
|
|
1105 } else if (ANCHOR_GLOBAL is anchor) {
|
|
1106
|
|
1107 if (lowerRightX > displayLowerRightX)
|
|
1108 location.x= location.x - (lowerRightX - displayLowerRightX);
|
|
1109
|
|
1110 if (lowerRightY > displayLowerRightY)
|
|
1111 location.y= location.y - (lowerRightY - displayLowerRightY);
|
|
1112
|
|
1113 return (location.x >= displayArea.x && location.y >= displayArea.y);
|
|
1114 }
|
|
1115
|
|
1116 return false;
|
|
1117 }
|
|
1118
|
|
1119 /**
|
|
1120 * Returns the next fallback anchor as specified by this manager's
|
|
1121 * fallback anchor sequence.
|
|
1122 * <p>
|
|
1123 * The fallback anchor for the given anchor is the one that comes directly after
|
|
1124 * the given anchor or is the first one in the sequence if the given anchor is the
|
|
1125 * last one in the sequence.
|
|
1126 * </p>
|
|
1127 * <p>
|
|
1128 * Note: It is the callers responsibility to prevent an endless loop i.e. to test
|
|
1129 * whether a given anchor has already been used once.
|
|
1130 * then
|
|
1131 * </p>
|
|
1132 *
|
|
1133 * @param anchor the current anchor
|
|
1134 * @return the next fallback anchor or <code>null</code> if no fallback anchor is available
|
|
1135 */
|
|
1136 protected Anchor getNextFallbackAnchor(Anchor anchor) {
|
|
1137
|
|
1138 if (anchor is null || fFallbackAnchors is null)
|
|
1139 return null;
|
|
1140
|
|
1141 for (int i= 0; i < fFallbackAnchors.length; i++) {
|
|
1142 if (fFallbackAnchors[i] is anchor)
|
|
1143 return fFallbackAnchors[i + 1 is fFallbackAnchors.length ? 0 : i + 1];
|
|
1144 }
|
|
1145
|
|
1146 return null;
|
|
1147 }
|
|
1148
|
|
1149 /**
|
|
1150 * Computes the location of the information control depending on the
|
|
1151 * subject area and the size of the information control. This method attempts
|
|
1152 * to find a location at which the information control lies completely in the display's
|
|
1153 * client area while honoring the manager's default anchor. If this isn't possible using the
|
|
1154 * default anchor, the fallback anchors are tried out.
|
|
1155 *
|
|
1156 * @param subjectArea the information area
|
|
1157 * @param controlSize the size of the information control
|
|
1158 * @return the computed location of the information control
|
|
1159 */
|
|
1160 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) {
|
|
1161 Rectangle subjectAreaDisplayRelative= Geometry.toDisplay(fSubjectControl, subjectArea);
|
|
1162
|
|
1163 Point upperLeft;
|
|
1164 Anchor testAnchor= fAnchor;
|
|
1165 Rectangle bestBounds= null;
|
|
1166 int bestArea= Integer.MIN_VALUE;
|
|
1167 Anchor bestAnchor= null;
|
|
1168 do {
|
|
1169
|
|
1170 upperLeft= computeLocation(subjectArea, controlSize, testAnchor);
|
|
1171 Monitor monitor= getClosestMonitor(subjectAreaDisplayRelative, testAnchor);
|
|
1172 if (updateLocation(upperLeft, controlSize, monitor.getClientArea(), testAnchor))
|
|
1173 return upperLeft;
|
|
1174
|
|
1175 // compute available area for this anchor and update if better than best
|
|
1176 Rectangle available= computeAvailableArea(subjectAreaDisplayRelative, monitor.getClientArea(), testAnchor);
|
|
1177 Rectangle proposed= new Rectangle(upperLeft.x, upperLeft.y, controlSize.x, controlSize.y);
|
|
1178 available.intersect(proposed);
|
|
1179 int area= available.width * available.height;
|
|
1180 if (area > bestArea) {
|
|
1181 bestArea= area;
|
|
1182 bestBounds= available;
|
|
1183 bestAnchor= testAnchor;
|
|
1184 }
|
|
1185
|
|
1186 testAnchor= getNextFallbackAnchor(testAnchor);
|
|
1187
|
|
1188 } while (testAnchor !is fAnchor && testAnchor !is null);
|
|
1189
|
|
1190 // no anchor is perfect - select the one with larges area and set the size to not overlap with the subjectArea
|
|
1191 if (bestAnchor !is ANCHOR_GLOBAL)
|
|
1192 Geometry.set(controlSize, Geometry.getSize(bestBounds));
|
|
1193 return Geometry.getLocation(bestBounds);
|
|
1194 }
|
|
1195
|
|
1196 /**
|
|
1197 * Gets the closest monitor given an anchor and the subject area.
|
|
1198 *
|
|
1199 * @param area the subject area
|
|
1200 * @param anchor the anchor
|
|
1201 * @return the monitor closest to the edge of <code>area</code> defined by
|
|
1202 * <code>anchor</code>
|
|
1203 * @since 3.3
|
|
1204 */
|
|
1205 private Monitor getClosestMonitor(Rectangle area, Anchor anchor) {
|
|
1206 Point center;
|
|
1207 if (ANCHOR_GLOBAL is anchor)
|
|
1208 center= Geometry.centerPoint(area);
|
|
1209 else
|
|
1210 center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag()));
|
|
1211 return getClosestMonitor(fSubjectControl.getDisplay(), Geometry.createRectangle(center, new Point(0, 0)));
|
|
1212 }
|
|
1213
|
|
1214 /**
|
|
1215 * Copied from dwtx.jface.window.Window. Returns the monitor whose client area contains
|
|
1216 * the given point. If no monitor contains the point, returns the monitor that is closest to the
|
|
1217 * point. If this is ever made public, it should be moved into a separate utility class.
|
|
1218 *
|
|
1219 * @param display the display to search for monitors
|
|
1220 * @param rectangle the rectangle to find the closest monitor for (display coordinates)
|
|
1221 * @return the monitor closest to the given point
|
|
1222 * @since 3.3
|
|
1223 */
|
|
1224 private Monitor getClosestMonitor(Display display, Rectangle rectangle) {
|
|
1225 int closest = Integer.MAX_VALUE;
|
|
1226
|
|
1227 Point toFind= Geometry.centerPoint(rectangle);
|
|
1228 Monitor[] monitors = display.getMonitors();
|
|
1229 Monitor result = monitors[0];
|
|
1230
|
|
1231 for (int idx = 0; idx < monitors.length; idx++) {
|
|
1232 Monitor current = monitors[idx];
|
|
1233
|
|
1234 Rectangle clientArea = current.getClientArea();
|
|
1235
|
|
1236 if (clientArea.contains(toFind)) {
|
|
1237 return current;
|
|
1238 }
|
|
1239
|
|
1240 int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
|
|
1241 if (distance < closest) {
|
|
1242 closest = distance;
|
|
1243 result = current;
|
|
1244 }
|
|
1245 }
|
|
1246
|
|
1247 return result;
|
|
1248 }
|
|
1249
|
|
1250 /**
|
|
1251 * Computes information to be displayed as well as the subject area
|
|
1252 * and initiates that this information is presented in the information control.
|
|
1253 * This happens only if this controller is enabled.
|
|
1254 */
|
|
1255 public void showInformation() {
|
|
1256 if (fEnabled)
|
|
1257 doShowInformation();
|
|
1258 }
|
|
1259
|
|
1260 /**
|
|
1261 * Computes information to be displayed as well as the subject area
|
|
1262 * and initiates that this information is presented in the information control.
|
|
1263 */
|
|
1264 protected void doShowInformation() {
|
|
1265 fSubjectArea= null;
|
|
1266 fInformation= null;
|
|
1267 computeInformation();
|
|
1268 }
|
|
1269
|
|
1270 /**
|
|
1271 * Presents the information in the information control or hides the information
|
|
1272 * control if no information should be presented. The information has previously
|
|
1273 * been set using <code>setInformation</code>.
|
|
1274 */
|
|
1275 protected void presentInformation() {
|
|
1276 bool hasContents= false;
|
|
1277 if (fInformation instanceof String)
|
|
1278 hasContents= ((String)fInformation).trim().length() > 0;
|
|
1279 else
|
|
1280 hasContents= (fInformation !is null);
|
|
1281
|
|
1282 if (fSubjectArea !is null && hasContents)
|
|
1283 internalShowInformationControl(fSubjectArea, fInformation);
|
|
1284 else
|
|
1285 hideInformationControl();
|
|
1286 }
|
|
1287
|
|
1288 /**
|
|
1289 * Opens the information control with the given information and the specified
|
|
1290 * subject area. It also activates the information control closer.
|
|
1291 *
|
|
1292 * @param subjectArea the information area
|
|
1293 * @param information the information
|
|
1294 */
|
|
1295 private void internalShowInformationControl(Rectangle subjectArea, Object information) {
|
|
1296 if (this instanceof InformationControlReplacer) {
|
|
1297 ((InformationControlReplacer) this).showInformationControl(subjectArea, information);
|
|
1298 return;
|
|
1299 }
|
|
1300
|
|
1301 IInformationControl informationControl= getInformationControl();
|
|
1302 if (informationControl !is null) {
|
|
1303
|
|
1304 Point sizeConstraints= computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl);
|
|
1305 if (informationControl instanceof IInformationControlExtension3) {
|
|
1306 IInformationControlExtension3 iControl3= (IInformationControlExtension3) informationControl;
|
|
1307 Rectangle trim= iControl3.computeTrim();
|
|
1308 sizeConstraints.x += trim.width;
|
|
1309 sizeConstraints.y += trim.height;
|
|
1310 }
|
|
1311 informationControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y);
|
|
1312
|
|
1313 if (informationControl instanceof IInformationControlExtension2)
|
|
1314 ((IInformationControlExtension2)informationControl).setInput(information);
|
|
1315 else
|
|
1316 informationControl.setInformation(information.toString());
|
|
1317
|
|
1318 if (informationControl instanceof IInformationControlExtension) {
|
|
1319 IInformationControlExtension extension= (IInformationControlExtension)informationControl;
|
|
1320 if (!extension.hasContents())
|
|
1321 return;
|
|
1322 }
|
|
1323
|
|
1324 Point size= null;
|
|
1325 Point location= null;
|
|
1326 Rectangle bounds= restoreInformationControlBounds();
|
|
1327
|
|
1328 if (bounds !is null) {
|
|
1329 if (bounds.x > -1 && bounds.y > -1)
|
|
1330 location= Geometry.getLocation(bounds);
|
|
1331
|
|
1332 if (bounds.width > -1 && bounds.height > -1)
|
|
1333 size= Geometry.getSize(bounds);
|
|
1334 }
|
|
1335
|
|
1336 if (size is null)
|
|
1337 size= informationControl.computeSizeHint();
|
|
1338
|
|
1339 if (fEnforceAsMinimalSize)
|
|
1340 size= Geometry.max(size, sizeConstraints);
|
|
1341 if (fEnforceAsMaximalSize)
|
|
1342 size= Geometry.min(size, sizeConstraints);
|
|
1343
|
|
1344 if (location is null)
|
|
1345 location= computeInformationControlLocation(subjectArea, size);
|
|
1346
|
|
1347 Rectangle controlBounds= Geometry.createRectangle(location, size);
|
|
1348 cropToClosestMonitor(controlBounds);
|
|
1349 location= Geometry.getLocation(controlBounds);
|
|
1350 size= Geometry.getSize(controlBounds);
|
|
1351 informationControl.setLocation(location);
|
|
1352 informationControl.setSize(size.x, size.y);
|
|
1353
|
|
1354 showInformationControl(subjectArea);
|
|
1355 }
|
|
1356 }
|
|
1357
|
|
1358 /**
|
|
1359 * Crops the given bounds such that they lie completely on the closest monitor.
|
|
1360 *
|
|
1361 * @param bounds shell bounds to crop
|
|
1362 * @since 3.4
|
|
1363 */
|
|
1364 void cropToClosestMonitor(Rectangle bounds) {
|
|
1365 Rectangle monitorBounds= getClosestMonitor(fSubjectControl.getDisplay(), bounds).getClientArea();
|
|
1366 bounds.intersect(monitorBounds);
|
|
1367 }
|
|
1368
|
|
1369 /**
|
|
1370 * Hides the information control and stops the information control closer.
|
|
1371 */
|
|
1372 protected void hideInformationControl() {
|
|
1373 if (fInformationControl !is null) {
|
|
1374 storeInformationControlBounds();
|
|
1375 fInformationControl.setVisible(false);
|
|
1376 if (fInformationControlCloser !is null)
|
|
1377 fInformationControlCloser.stop();
|
|
1378 }
|
|
1379 }
|
|
1380
|
|
1381 /**
|
|
1382 * Shows the information control and starts the information control closer.
|
|
1383 * This method may not be called by clients.
|
|
1384 *
|
|
1385 * @param subjectArea the information area
|
|
1386 */
|
|
1387 protected void showInformationControl(Rectangle subjectArea) {
|
|
1388 fInformationControl.setVisible(true);
|
|
1389
|
|
1390 if (fTakesFocusWhenVisible)
|
|
1391 fInformationControl.setFocus();
|
|
1392
|
|
1393 if (fInformationControlCloser !is null)
|
|
1394 fInformationControlCloser.start(subjectArea);
|
|
1395 }
|
|
1396
|
|
1397 /**
|
|
1398 * Replaces this manager's information control as defined by
|
|
1399 * the information control replacer.
|
|
1400 * <strong>Must only be called when {@link #fInformationControl} instanceof {@link IInformationControlExtension3}!</strong>
|
|
1401 *
|
|
1402 * @param takeFocus <code>true</code> iff the replacing information control should take focus
|
|
1403 *
|
|
1404 * @since 3.4
|
|
1405 */
|
|
1406 void replaceInformationControl(bool takeFocus) {
|
|
1407 if (fInformationControlReplacer !is null && canReplace(fInformationControl)) {
|
|
1408 IInformationControlExtension3 iControl3= (IInformationControlExtension3) fInformationControl;
|
|
1409 Rectangle b= iControl3.getBounds();
|
|
1410 Rectangle t= iControl3.computeTrim();
|
|
1411 Rectangle contentBounds= new Rectangle(b.x - t.x, b.y - t.y, b.width - t.width, b.height - t.height);
|
|
1412 IInformationControlCreator informationPresenterControlCreator= ((IInformationControlExtension5) fInformationControl).getInformationPresenterControlCreator();
|
|
1413 fInformationControlReplacer.replaceInformationControl(informationPresenterControlCreator, contentBounds, fInformation, fSubjectArea, takeFocus);
|
|
1414 }
|
|
1415 hideInformationControl();
|
|
1416 }
|
|
1417
|
|
1418 /**
|
|
1419 * Disposes this manager's information control.
|
|
1420 */
|
|
1421 public void disposeInformationControl() {
|
|
1422 if (fInformationControl !is null) {
|
|
1423 fInformationControl.dispose();
|
|
1424 handleInformationControlDisposed();
|
|
1425 }
|
|
1426 }
|
|
1427
|
|
1428 /**
|
|
1429 * Disposes this manager and if necessary all dependent parts such as
|
|
1430 * the information control. For symmetry it first disables this manager.
|
|
1431 */
|
|
1432 public void dispose() {
|
|
1433 if (!fDisposed) {
|
|
1434
|
|
1435 fDisposed= true;
|
|
1436
|
|
1437 setEnabled(false);
|
|
1438 disposeInformationControl();
|
|
1439
|
|
1440 if (fInformationControlReplacer !is null) {
|
|
1441 fInformationControlReplacer.dispose();
|
|
1442 fInformationControlReplacer= null;
|
|
1443 }
|
|
1444
|
|
1445 if (fSubjectControl !is null && !fSubjectControl.isDisposed() && fSubjectControlDisposeListener !is null)
|
|
1446 fSubjectControl.removeDisposeListener(fSubjectControlDisposeListener);
|
|
1447 fSubjectControl= null;
|
|
1448 fSubjectControlDisposeListener= null;
|
|
1449
|
|
1450 fIsCustomInformationControl= false;
|
|
1451 fCustomInformationControlCreator= null;
|
|
1452 fInformationControlCreator= null;
|
|
1453 fInformationControlCloser= null;
|
|
1454 }
|
|
1455 }
|
|
1456
|
|
1457 // ------ control's size handling dialog settings ------
|
|
1458
|
|
1459 /**
|
|
1460 * Stores the information control's bounds.
|
|
1461 *
|
|
1462 * @since 3.0
|
|
1463 */
|
|
1464 protected void storeInformationControlBounds() {
|
|
1465 if (fDialogSettings is null || fInformationControl is null || !(fIsRestoringLocation || fIsRestoringSize))
|
|
1466 return;
|
|
1467
|
|
1468 if (!(fInformationControl instanceof IInformationControlExtension3))
|
|
1469 throw new UnsupportedOperationException();
|
|
1470
|
|
1471 bool controlRestoresSize= ((IInformationControlExtension3)fInformationControl).restoresSize();
|
|
1472 bool controlRestoresLocation= ((IInformationControlExtension3)fInformationControl).restoresLocation();
|
|
1473
|
|
1474 Rectangle bounds= ((IInformationControlExtension3)fInformationControl).getBounds();
|
|
1475 if (bounds is null)
|
|
1476 return;
|
|
1477
|
|
1478 if (fIsRestoringSize && controlRestoresSize) {
|
|
1479 fDialogSettings.put(STORE_SIZE_WIDTH, bounds.width);
|
|
1480 fDialogSettings.put(STORE_SIZE_HEIGHT, bounds.height);
|
|
1481 }
|
|
1482 if (fIsRestoringLocation && controlRestoresLocation) {
|
|
1483 fDialogSettings.put(STORE_LOCATION_X, bounds.x);
|
|
1484 fDialogSettings.put(STORE_LOCATION_Y, bounds.y);
|
|
1485 }
|
|
1486 }
|
|
1487 /**
|
|
1488 * Restores the information control's bounds.
|
|
1489 *
|
|
1490 * @return the stored bounds
|
|
1491 * @since 3.0
|
|
1492 */
|
|
1493 protected Rectangle restoreInformationControlBounds() {
|
|
1494 if (fDialogSettings is null || !(fIsRestoringLocation || fIsRestoringSize))
|
|
1495 return null;
|
|
1496
|
|
1497 if (!(fInformationControl instanceof IInformationControlExtension3))
|
|
1498 throw new UnsupportedOperationException();
|
|
1499
|
|
1500 bool controlRestoresSize= ((IInformationControlExtension3)fInformationControl).restoresSize();
|
|
1501 bool controlRestoresLocation= ((IInformationControlExtension3)fInformationControl).restoresLocation();
|
|
1502
|
|
1503 Rectangle bounds= new Rectangle(-1, -1, -1, -1);
|
|
1504
|
|
1505 if (fIsRestoringSize && controlRestoresSize) {
|
|
1506 try {
|
|
1507 bounds.width= fDialogSettings.getInt(STORE_SIZE_WIDTH);
|
|
1508 bounds.height= fDialogSettings.getInt(STORE_SIZE_HEIGHT);
|
|
1509 } catch (NumberFormatException ex) {
|
|
1510 bounds.width= -1;
|
|
1511 bounds.height= -1;
|
|
1512 }
|
|
1513 }
|
|
1514
|
|
1515 if (fIsRestoringLocation && controlRestoresLocation) {
|
|
1516 try {
|
|
1517 bounds.x= fDialogSettings.getInt(STORE_LOCATION_X);
|
|
1518 bounds.y= fDialogSettings.getInt(STORE_LOCATION_Y);
|
|
1519 } catch (NumberFormatException ex) {
|
|
1520 bounds.x= -1;
|
|
1521 bounds.y= -1;
|
|
1522 }
|
|
1523 }
|
|
1524
|
|
1525 // sanity check
|
|
1526 if (bounds.x is -1 && bounds.y is -1 && bounds.width is -1 && bounds.height is -1)
|
|
1527 return null;
|
|
1528
|
|
1529 Rectangle maxBounds= null;
|
|
1530 if (fSubjectControl !is null && !fSubjectControl.isDisposed())
|
|
1531 maxBounds= fSubjectControl.getDisplay().getBounds();
|
|
1532 else {
|
|
1533 // fallback
|
|
1534 Display display= Display.getCurrent();
|
|
1535 if (display is null)
|
|
1536 display= Display.getDefault();
|
|
1537 if (display !is null && !display.isDisposed())
|
|
1538 maxBounds= display.getBounds();
|
|
1539 }
|
|
1540
|
|
1541
|
|
1542 if (bounds.width > -1 && bounds.height > -1) {
|
|
1543 if (maxBounds !is null) {
|
|
1544 bounds.width= Math.min(bounds.width, maxBounds.width);
|
|
1545 bounds.height= Math.min(bounds.height, maxBounds.height);
|
|
1546 }
|
|
1547
|
|
1548 // Enforce an absolute minimal size
|
|
1549 bounds.width= Math.max(bounds.width, 30);
|
|
1550 bounds.height= Math.max(bounds.height, 30);
|
|
1551 }
|
|
1552
|
|
1553 if (bounds.x > -1 && bounds.y > -1 && maxBounds !is null) {
|
|
1554 bounds.x= Math.max(bounds.x, maxBounds.x);
|
|
1555 bounds.y= Math.max(bounds.y, maxBounds.y);
|
|
1556
|
|
1557 if (bounds .width > -1 && bounds.height > -1) {
|
|
1558 bounds.x= Math.min(bounds.x, maxBounds.width - bounds.width);
|
|
1559 bounds.y= Math.min(bounds.y, maxBounds.height - bounds.height);
|
|
1560 }
|
|
1561 }
|
|
1562
|
|
1563 return bounds;
|
|
1564 }
|
|
1565
|
|
1566 /**
|
|
1567 * Returns an adapter that gives access to internal methods.
|
|
1568 * <p>
|
|
1569 * <strong>Note:</strong> This method is not intended to be referenced or overridden by clients.</p>
|
|
1570 *
|
|
1571 * @return the replaceable information control accessor
|
|
1572 * @since 3.4
|
|
1573 * @noreference This method is not intended to be referenced by clients.
|
|
1574 * @nooverride This method is not intended to be re-implemented or extended by clients.
|
|
1575 */
|
|
1576 public InternalAccessor getInternalAccessor() {
|
|
1577 return new MyInternalAccessor();
|
|
1578 }
|
|
1579 }
|