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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.DefaultInformationControl;
|
|
14
|
131
|
15 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport
|
|
16 import dwtx.jface.text.DefaultTextHover; // packageimport
|
|
17 import dwtx.jface.text.AbstractInformationControl; // packageimport
|
|
18 import dwtx.jface.text.TextUtilities; // packageimport
|
|
19 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport
|
|
20 import dwtx.jface.text.AbstractInformationControlManager; // 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.IWidgetTokenOwnerExtension; // packageimport
|
|
66 import dwtx.jface.text.DocumentClone; // packageimport
|
|
67 import dwtx.jface.text.DefaultUndoManager; // packageimport
|
|
68 import dwtx.jface.text.IFindReplaceTarget; // packageimport
|
|
69 import dwtx.jface.text.IAutoEditStrategy; // packageimport
|
|
70 import dwtx.jface.text.ILineTrackerExtension; // packageimport
|
|
71 import dwtx.jface.text.IUndoManagerExtension; // packageimport
|
|
72 import dwtx.jface.text.TextSelection; // packageimport
|
|
73 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport
|
|
74 import dwtx.jface.text.IAutoIndentStrategy; // packageimport
|
|
75 import dwtx.jface.text.IPainter; // packageimport
|
|
76 import dwtx.jface.text.IInformationControl; // packageimport
|
|
77 import dwtx.jface.text.IInformationControlExtension3; // packageimport
|
|
78 import dwtx.jface.text.ITextViewerExtension6; // packageimport
|
|
79 import dwtx.jface.text.IInformationControlExtension4; // packageimport
|
|
80 import dwtx.jface.text.DefaultLineTracker; // packageimport
|
|
81 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport
|
|
82 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport
|
|
83 import dwtx.jface.text.ITextHover; // packageimport
|
|
84 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport
|
|
85 import dwtx.jface.text.ILineTracker; // packageimport
|
|
86 import dwtx.jface.text.Line; // packageimport
|
|
87 import dwtx.jface.text.ITextViewerExtension; // packageimport
|
|
88 import dwtx.jface.text.IDocumentAdapter; // packageimport
|
|
89 import dwtx.jface.text.TextEvent; // packageimport
|
|
90 import dwtx.jface.text.BadLocationException; // packageimport
|
|
91 import dwtx.jface.text.AbstractDocument; // packageimport
|
|
92 import dwtx.jface.text.AbstractLineTracker; // packageimport
|
|
93 import dwtx.jface.text.TreeLineTracker; // packageimport
|
|
94 import dwtx.jface.text.ITextPresentationListener; // packageimport
|
|
95 import dwtx.jface.text.Region; // packageimport
|
|
96 import dwtx.jface.text.ITextViewer; // packageimport
|
|
97 import dwtx.jface.text.IDocumentInformationMapping; // packageimport
|
|
98 import dwtx.jface.text.MarginPainter; // packageimport
|
|
99 import dwtx.jface.text.IPaintPositionManager; // packageimport
|
|
100 import dwtx.jface.text.TextPresentation; // packageimport
|
|
101 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport
|
|
102 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport
|
|
103 import dwtx.jface.text.ISelectionValidator; // packageimport
|
|
104 import dwtx.jface.text.IDocumentExtension; // packageimport
|
|
105 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport
|
|
106 import dwtx.jface.text.ConfigurableLineTracker; // packageimport
|
|
107 import dwtx.jface.text.SlaveDocumentEvent; // packageimport
|
|
108 import dwtx.jface.text.IDocumentListener; // packageimport
|
|
109 import dwtx.jface.text.PaintManager; // packageimport
|
|
110 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport
|
|
111 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport
|
|
112 import dwtx.jface.text.IDocumentExtension3; // packageimport
|
|
113 import dwtx.jface.text.Position; // packageimport
|
|
114 import dwtx.jface.text.TextMessages; // packageimport
|
|
115 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport
|
|
116 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport
|
|
117 import dwtx.jface.text.IPositionUpdater; // packageimport
|
|
118 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport
|
|
119 import dwtx.jface.text.ListLineTracker; // packageimport
|
|
120 import dwtx.jface.text.ITextInputListener; // packageimport
|
|
121 import dwtx.jface.text.BadPositionCategoryException; // packageimport
|
|
122 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport
|
|
123 import dwtx.jface.text.IInputChangedListener; // packageimport
|
|
124 import dwtx.jface.text.ITextOperationTarget; // packageimport
|
|
125 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport
|
|
126 import dwtx.jface.text.ITextViewerExtension7; // packageimport
|
|
127 import dwtx.jface.text.IInformationControlExtension5; // packageimport
|
|
128 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport
|
|
129 import dwtx.jface.text.JFaceTextUtil; // packageimport
|
|
130 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport
|
|
131 import dwtx.jface.text.TabsToSpacesConverter; // packageimport
|
|
132 import dwtx.jface.text.CursorLinePainter; // packageimport
|
|
133 import dwtx.jface.text.ITextHoverExtension; // packageimport
|
|
134 import dwtx.jface.text.IEventConsumer; // packageimport
|
|
135 import dwtx.jface.text.IDocument; // packageimport
|
|
136 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport
|
|
137 import dwtx.jface.text.DocumentCommand; // packageimport
|
|
138 import dwtx.jface.text.TypedPosition; // packageimport
|
|
139 import dwtx.jface.text.IEditingSupportRegistry; // packageimport
|
|
140 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport
|
|
141 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport
|
|
142 import dwtx.jface.text.IEditingSupport; // packageimport
|
|
143 import dwtx.jface.text.IMarkSelection; // packageimport
|
|
144 import dwtx.jface.text.ISlaveDocumentManager; // packageimport
|
|
145 import dwtx.jface.text.DocumentEvent; // packageimport
|
|
146 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport
|
|
147 import dwtx.jface.text.ITextStore; // packageimport
|
|
148 import dwtx.jface.text.JFaceTextMessages; // packageimport
|
|
149 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport
|
|
150 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport
|
|
151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport
|
|
152 import dwtx.jface.text.TextAttribute; // packageimport
|
|
153 import dwtx.jface.text.ITextViewerExtension4; // packageimport
|
|
154 import dwtx.jface.text.ITypedRegion; // packageimport
|
|
155
|
|
156
|
129
|
157 import dwt.dwthelper.utils;
|
|
158
|
|
159
|
|
160
|
|
161 import dwt.DWT;
|
|
162 import dwt.custom.StyledText;
|
|
163 import dwt.events.DisposeEvent;
|
|
164 import dwt.events.DisposeListener;
|
|
165 import dwt.graphics.Color;
|
|
166 import dwt.graphics.Drawable;
|
|
167 import dwt.graphics.Point;
|
|
168 import dwt.graphics.Rectangle;
|
|
169 import dwt.layout.FillLayout;
|
|
170 import dwt.widgets.Composite;
|
|
171 import dwt.widgets.Display;
|
|
172 import dwt.widgets.Shell;
|
|
173 import dwtx.jface.action.ToolBarManager;
|
|
174 import dwtx.jface.internal.text.html.HTMLTextPresenter;
|
|
175 import dwtx.jface.resource.JFaceResources;
|
|
176 import dwtx.jface.util.Geometry;
|
|
177
|
|
178
|
|
179 /**
|
|
180 * Default implementation of {@link dwtx.jface.text.IInformationControl}.
|
|
181 * <p>
|
|
182 * Displays textual information in a {@link dwt.custom.StyledText}
|
|
183 * widget. Before displaying, the information set to this information control is
|
|
184 * processed by an <code>IInformationPresenter</code>.
|
|
185 *
|
|
186 * @since 2.0
|
|
187 */
|
|
188 public class DefaultInformationControl : AbstractInformationControl , DisposeListener {
|
|
189
|
|
190 /**
|
|
191 * An information presenter determines the style presentation
|
|
192 * of information displayed in the default information control.
|
|
193 * The interface can be implemented by clients.
|
|
194 */
|
|
195 public interface IInformationPresenter {
|
|
196
|
|
197 /**
|
|
198 * Updates the given presentation of the given information and
|
|
199 * thereby may manipulate the information to be displayed. The manipulation
|
|
200 * could be the extraction of textual encoded style information etc. Returns the
|
|
201 * manipulated information.
|
|
202 * <p>
|
|
203 * <strong>Note:</strong> The given display must only be used for measuring.</p>
|
|
204 *
|
|
205 * @param display the display of the information control
|
|
206 * @param hoverInfo the information to be presented
|
|
207 * @param presentation the presentation to be updated
|
|
208 * @param maxWidth the maximal width in pixels
|
|
209 * @param maxHeight the maximal height in pixels
|
|
210 *
|
|
211 * @return the manipulated information
|
|
212 * @deprecated As of 3.2, replaced by {@link DefaultInformationControl.IInformationPresenterExtension#updatePresentation(Drawable, String, TextPresentation, int, int)}
|
|
213 */
|
|
214 String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight);
|
|
215 }
|
|
216
|
|
217
|
|
218 /**
|
|
219 * An information presenter determines the style presentation
|
|
220 * of information displayed in the default information control.
|
|
221 * The interface can be implemented by clients.
|
|
222 *
|
|
223 * @since 3.2
|
|
224 */
|
|
225 public interface IInformationPresenterExtension {
|
|
226
|
|
227 /**
|
|
228 * Updates the given presentation of the given information and
|
|
229 * thereby may manipulate the information to be displayed. The manipulation
|
|
230 * could be the extraction of textual encoded style information etc. Returns the
|
|
231 * manipulated information.
|
|
232 * <p>
|
|
233 * Replaces {@link DefaultInformationControl.IInformationPresenter#updatePresentation(Display, String, TextPresentation, int, int)}
|
|
234 * Implementations should use the font of the given <code>drawable</code> to calculate
|
|
235 * the size of the text to be presented.
|
|
236 * </p>
|
|
237 *
|
|
238 * @param drawable the drawable of the information control
|
|
239 * @param hoverInfo the information to be presented
|
|
240 * @param presentation the presentation to be updated
|
|
241 * @param maxWidth the maximal width in pixels
|
|
242 * @param maxHeight the maximal height in pixels
|
|
243 *
|
|
244 * @return the manipulated information
|
|
245 */
|
|
246 String updatePresentation(Drawable drawable, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight);
|
|
247 }
|
|
248
|
|
249
|
|
250 /**
|
|
251 * Inner border thickness in pixels.
|
|
252 * @since 3.1
|
|
253 */
|
|
254 private static final int INNER_BORDER= 1;
|
|
255
|
|
256 /** The control's text widget */
|
|
257 private StyledText fText;
|
|
258 /** The information presenter, or <code>null</code> if none. */
|
|
259 private final IInformationPresenter fPresenter;
|
|
260 /** A cached text presentation */
|
|
261 private final TextPresentation fPresentation= new TextPresentation();
|
|
262
|
|
263 /**
|
|
264 * Additional styles to use for the text control.
|
|
265 * @since 3.4, previously called <code>fTextStyle</code>
|
|
266 */
|
|
267 private final int fAdditionalTextStyles;
|
|
268
|
|
269 /**
|
|
270 * Creates a default information control with the given shell as parent. An information
|
|
271 * presenter that can handle simple HTML is used to process the information to be displayed.
|
|
272 *
|
|
273 * @param parent the parent shell
|
|
274 * @param isResizeable <code>true</code> if the control should be resizable
|
|
275 * @since 3.4
|
|
276 */
|
|
277 public DefaultInformationControl(Shell parent, bool isResizeable) {
|
|
278 super(parent, isResizeable);
|
|
279 fAdditionalTextStyles= isResizeable ? DWT.V_SCROLL | DWT.H_SCROLL : DWT.NONE;
|
|
280 fPresenter= new HTMLTextPresenter(!isResizeable);
|
|
281 create();
|
|
282 }
|
|
283
|
|
284 /**
|
|
285 * Creates a default information control with the given shell as parent. An information
|
|
286 * presenter that can handle simple HTML is used to process the information to be displayed.
|
|
287 *
|
|
288 * @param parent the parent shell
|
|
289 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field
|
|
290 * @since 3.4
|
|
291 */
|
|
292 public DefaultInformationControl(Shell parent, String statusFieldText) {
|
|
293 this(parent, statusFieldText, new HTMLTextPresenter(true));
|
|
294 }
|
|
295
|
|
296 /**
|
|
297 * Creates a default information control with the given shell as parent. The
|
|
298 * given information presenter is used to process the information to be
|
|
299 * displayed.
|
|
300 *
|
|
301 * @param parent the parent shell
|
|
302 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field
|
|
303 * @param presenter the presenter to be used, or <code>null</code> if no presenter should be used
|
|
304 * @since 3.4
|
|
305 */
|
|
306 public DefaultInformationControl(Shell parent, String statusFieldText, IInformationPresenter presenter) {
|
|
307 super(parent, statusFieldText);
|
|
308 fAdditionalTextStyles= DWT.NONE;
|
|
309 fPresenter= presenter;
|
|
310 create();
|
|
311 }
|
|
312
|
|
313 /**
|
|
314 * Creates a resizable default information control with the given shell as parent. An
|
|
315 * information presenter that can handle simple HTML is used to process the information to be
|
|
316 * displayed.
|
|
317 *
|
|
318 * @param parent the parent shell
|
|
319 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired
|
|
320 * @since 3.4
|
|
321 */
|
|
322 public DefaultInformationControl(Shell parent, ToolBarManager toolBarManager) {
|
|
323 this(parent, toolBarManager, new HTMLTextPresenter(false));
|
|
324 }
|
|
325
|
|
326 /**
|
|
327 * Creates a resizable default information control with the given shell as
|
|
328 * parent. The given information presenter is used to process the
|
|
329 * information to be displayed.
|
|
330 *
|
|
331 * @param parent the parent shell
|
|
332 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired
|
|
333 * @param presenter the presenter to be used, or <code>null</code> if no presenter should be used
|
|
334 * @since 3.4
|
|
335 */
|
|
336 public DefaultInformationControl(Shell parent, ToolBarManager toolBarManager, IInformationPresenter presenter) {
|
|
337 super(parent, toolBarManager);
|
|
338 fAdditionalTextStyles= DWT.V_SCROLL | DWT.H_SCROLL;
|
|
339 fPresenter= presenter;
|
|
340 create();
|
|
341 }
|
|
342
|
|
343 /**
|
|
344 * Creates a default information control with the given shell as parent.
|
|
345 * No information presenter is used to process the information
|
|
346 * to be displayed.
|
|
347 *
|
|
348 * @param parent the parent shell
|
|
349 */
|
|
350 public DefaultInformationControl(Shell parent) {
|
|
351 this(parent, (String)null, null);
|
|
352 }
|
|
353
|
|
354 /**
|
|
355 * Creates a default information control with the given shell as parent. The given
|
|
356 * information presenter is used to process the information to be displayed.
|
|
357 *
|
|
358 * @param parent the parent shell
|
|
359 * @param presenter the presenter to be used
|
|
360 */
|
|
361 public DefaultInformationControl(Shell parent, IInformationPresenter presenter) {
|
|
362 this(parent, (String)null, presenter);
|
|
363 }
|
|
364
|
|
365 /**
|
|
366 * Creates a default information control with the given shell as parent. The
|
|
367 * given information presenter is used to process the information to be
|
|
368 * displayed. The given styles are applied to the created styled text
|
|
369 * widget.
|
|
370 *
|
|
371 * @param parent the parent shell
|
|
372 * @param shellStyle the additional styles for the shell
|
|
373 * @param style the additional styles for the styled text widget
|
|
374 * @param presenter the presenter to be used
|
|
375 * @deprecated As of 3.4, replaced by simpler constructors
|
|
376 */
|
|
377 public DefaultInformationControl(Shell parent, int shellStyle, int style, IInformationPresenter presenter) {
|
|
378 this(parent, shellStyle, style, presenter, null);
|
|
379 }
|
|
380
|
|
381 /**
|
|
382 * Creates a default information control with the given shell as parent. The
|
|
383 * given information presenter is used to process the information to be
|
|
384 * displayed. The given styles are applied to the created styled text
|
|
385 * widget.
|
|
386 *
|
|
387 * @param parentShell the parent shell
|
|
388 * @param shellStyle the additional styles for the shell
|
|
389 * @param style the additional styles for the styled text widget
|
|
390 * @param presenter the presenter to be used
|
|
391 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field
|
|
392 * @since 3.0
|
|
393 * @deprecated As of 3.4, replaced by simpler constructors
|
|
394 */
|
|
395 public DefaultInformationControl(Shell parentShell, int shellStyle, final int style, IInformationPresenter presenter, String statusFieldText) {
|
|
396 super(parentShell, DWT.NO_FOCUS | DWT.ON_TOP | shellStyle, statusFieldText, null);
|
|
397 fAdditionalTextStyles= style;
|
|
398 fPresenter= presenter;
|
|
399 create();
|
|
400 }
|
|
401
|
|
402 /**
|
|
403 * Creates a default information control with the given shell as parent. The
|
|
404 * given information presenter is used to process the information to be
|
|
405 * displayed.
|
|
406 *
|
|
407 * @param parent the parent shell
|
|
408 * @param textStyles the additional styles for the styled text widget
|
|
409 * @param presenter the presenter to be used
|
|
410 * @deprecated As of 3.4, replaced by {@link #DefaultInformationControl(Shell, DefaultInformationControl.IInformationPresenter)}
|
|
411 */
|
|
412 public DefaultInformationControl(Shell parent, int textStyles, IInformationPresenter presenter) {
|
|
413 this(parent, textStyles, presenter, null);
|
|
414 }
|
|
415
|
|
416 /**
|
|
417 * Creates a default information control with the given shell as parent. The
|
|
418 * given information presenter is used to process the information to be
|
|
419 * displayed.
|
|
420 *
|
|
421 * @param parent the parent shell
|
|
422 * @param textStyles the additional styles for the styled text widget
|
|
423 * @param presenter the presenter to be used
|
|
424 * @param statusFieldText the text to be used in the status field or <code>null</code> to hide the status field
|
|
425 * @since 3.0
|
|
426 * @deprecated As of 3.4, replaced by {@link #DefaultInformationControl(Shell, String, DefaultInformationControl.IInformationPresenter)}
|
|
427 */
|
|
428 public DefaultInformationControl(Shell parent, int textStyles, IInformationPresenter presenter, String statusFieldText) {
|
|
429 super(parent, statusFieldText);
|
|
430 fAdditionalTextStyles= textStyles;
|
|
431 fPresenter= presenter;
|
|
432 create();
|
|
433 }
|
|
434
|
|
435 /*
|
|
436 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite)
|
|
437 */
|
|
438 protected void createContent(Composite parent) {
|
|
439 fText= new StyledText(parent, DWT.MULTI | DWT.READ_ONLY | fAdditionalTextStyles);
|
|
440 fText.setForeground(parent.getForeground());
|
|
441 fText.setBackground(parent.getBackground());
|
|
442 fText.setFont(JFaceResources.getDialogFont());
|
|
443 FillLayout layout= (FillLayout)parent.getLayout();
|
|
444 if (fText.getWordWrap()) {
|
|
445 // indent does not work for wrapping StyledText, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56342 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=115432
|
|
446 layout.marginHeight= INNER_BORDER;
|
|
447 layout.marginWidth= INNER_BORDER;
|
|
448 } else {
|
|
449 fText.setIndent(INNER_BORDER);
|
|
450 }
|
|
451 }
|
|
452
|
|
453 /*
|
|
454 * @see IInformationControl#setInformation(String)
|
|
455 */
|
|
456 public void setInformation(String content) {
|
|
457 if (fPresenter is null) {
|
|
458 fText.setText(content);
|
|
459 } else {
|
|
460 fPresentation.clear();
|
|
461
|
|
462 int maxWidth= -1;
|
|
463 int maxHeight= -1;
|
|
464 Point constraints= getSizeConstraints();
|
|
465 if (constraints !is null) {
|
|
466 maxWidth= constraints.x;
|
|
467 maxHeight= constraints.y;
|
|
468 if (fText.getWordWrap()) {
|
|
469 maxWidth-= INNER_BORDER * 2;
|
|
470 maxHeight-= INNER_BORDER * 2;
|
|
471 } else {
|
|
472 maxWidth-= INNER_BORDER; // indent
|
|
473 }
|
|
474 Rectangle trim= computeTrim();
|
|
475 maxWidth-= trim.width;
|
|
476 maxHeight-= trim.height;
|
|
477 maxWidth-= fText.getCaret().getSize().x; // StyledText adds a border at the end of the line for the caret.
|
|
478 }
|
|
479 if (isResizable())
|
|
480 maxHeight= Integer.MAX_VALUE;
|
|
481
|
|
482 if (fPresenter instanceof IInformationPresenterExtension)
|
|
483 content= ((IInformationPresenterExtension)fPresenter).updatePresentation(fText, content, fPresentation, maxWidth, maxHeight);
|
|
484 else
|
|
485 content= fPresenter.updatePresentation(getShell().getDisplay(), content, fPresentation, maxWidth, maxHeight);
|
|
486
|
|
487 if (content !is null) {
|
|
488 fText.setText(content);
|
|
489 TextPresentation.applyTextPresentation(fPresentation, fText);
|
|
490 } else {
|
|
491 fText.setText(""); //$NON-NLS-1$
|
|
492 }
|
|
493 }
|
|
494 }
|
|
495
|
|
496 /*
|
|
497 * @see IInformationControl#setVisible(bool)
|
|
498 */
|
|
499 public void setVisible(bool visible) {
|
|
500 if (visible) {
|
|
501 if (fText.getWordWrap()) {
|
|
502 Point currentSize= getShell().getSize();
|
|
503 getShell().pack(true);
|
|
504 Point newSize= getShell().getSize();
|
|
505 if (newSize.x > currentSize.x || newSize.y > currentSize.y)
|
|
506 setSize(currentSize.x, currentSize.y); // restore previous size
|
|
507 }
|
|
508 }
|
|
509
|
|
510 super.setVisible(visible);
|
|
511 }
|
|
512
|
|
513 /*
|
|
514 * @see IInformationControl#computeSizeHint()
|
|
515 */
|
|
516 public Point computeSizeHint() {
|
|
517 // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=117602
|
|
518 int widthHint= DWT.DEFAULT;
|
|
519 Point constraints= getSizeConstraints();
|
|
520 if (constraints !is null && fText.getWordWrap())
|
|
521 widthHint= constraints.x;
|
|
522
|
|
523 return getShell().computeSize(widthHint, DWT.DEFAULT, true);
|
|
524 }
|
|
525
|
|
526 /*
|
|
527 * @see dwtx.jface.text.AbstractInformationControl#computeTrim()
|
|
528 */
|
|
529 public Rectangle computeTrim() {
|
|
530 return Geometry.add(super.computeTrim(), fText.computeTrim(0, 0, 0, 0));
|
|
531 }
|
|
532
|
|
533 /*
|
|
534 * @see IInformationControl#setForegroundColor(Color)
|
|
535 */
|
|
536 public void setForegroundColor(Color foreground) {
|
|
537 super.setForegroundColor(foreground);
|
|
538 fText.setForeground(foreground);
|
|
539 }
|
|
540
|
|
541 /*
|
|
542 * @see IInformationControl#setBackgroundColor(Color)
|
|
543 */
|
|
544 public void setBackgroundColor(Color background) {
|
|
545 super.setBackgroundColor(background);
|
|
546 fText.setBackground(background);
|
|
547 }
|
|
548
|
|
549 /*
|
|
550 * @see IInformationControlExtension#hasContents()
|
|
551 */
|
|
552 public bool hasContents() {
|
|
553 return fText.getCharCount() > 0;
|
|
554 }
|
|
555
|
|
556 /**
|
|
557 * @see dwt.events.DisposeListener#widgetDisposed(dwt.events.DisposeEvent)
|
|
558 * @since 3.0
|
|
559 * @deprecated As of 3.2, no longer used and called
|
|
560 */
|
|
561 public void widgetDisposed(DisposeEvent event) {
|
|
562 }
|
|
563
|
|
564 /*
|
|
565 * @see dwtx.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
|
|
566 * @since 3.4
|
|
567 */
|
|
568 public IInformationControlCreator getInformationPresenterControlCreator() {
|
|
569 return new IInformationControlCreator() {
|
|
570 /*
|
|
571 * @see dwtx.jface.text.IInformationControlCreator#createInformationControl(dwt.widgets.Shell)
|
|
572 */
|
|
573 public IInformationControl createInformationControl(Shell parent) {
|
|
574 return new DefaultInformationControl(parent, (ToolBarManager) null, fPresenter);
|
|
575 }
|
|
576 };
|
|
577 }
|
|
578
|
|
579 }
|