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.internal.text.html.BrowserInformationControl;
|
|
14
|
131
|
15 import dwtx.jface.internal.text.html.HTML2TextReader; // packageimport
|
|
16 import dwtx.jface.internal.text.html.HTMLPrinter; // packageimport
|
|
17 import dwtx.jface.internal.text.html.SubstitutionTextReader; // packageimport
|
|
18 import dwtx.jface.internal.text.html.HTMLTextPresenter; // packageimport
|
|
19 import dwtx.jface.internal.text.html.BrowserInput; // packageimport
|
|
20 import dwtx.jface.internal.text.html.SingleCharReader; // packageimport
|
|
21 import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport
|
|
22 import dwtx.jface.internal.text.html.HTMLMessages; // packageimport
|
|
23
|
|
24
|
129
|
25 import dwt.dwthelper.utils;
|
|
26
|
|
27 import java.io.IOException;
|
|
28 import java.io.StringReader;
|
|
29 import java.util.Iterator;
|
|
30
|
|
31 import dwt.DWT;
|
|
32 import dwt.DWTError;
|
|
33 import dwt.browser.Browser;
|
|
34 import dwt.browser.LocationListener;
|
|
35 import dwt.browser.ProgressAdapter;
|
|
36 import dwt.browser.ProgressEvent;
|
|
37 import dwt.custom.StyleRange;
|
|
38 import dwt.events.KeyEvent;
|
|
39 import dwt.events.KeyListener;
|
|
40 import dwt.graphics.Color;
|
|
41 import dwt.graphics.Font;
|
|
42 import dwt.graphics.FontData;
|
|
43 import dwt.graphics.GC;
|
|
44 import dwt.graphics.Point;
|
|
45 import dwt.graphics.Rectangle;
|
|
46 import dwt.graphics.TextLayout;
|
|
47 import dwt.graphics.TextStyle;
|
|
48 import dwt.widgets.Composite;
|
|
49 import dwt.widgets.Display;
|
|
50 import dwt.widgets.Menu;
|
|
51 import dwt.widgets.Shell;
|
|
52 import dwt.widgets.Slider;
|
|
53 import dwtx.core.runtime.Assert;
|
|
54 import dwtx.core.runtime.ListenerList;
|
|
55 import dwtx.jface.action.ToolBarManager;
|
|
56 import dwtx.jface.resource.JFaceResources;
|
|
57 import dwtx.jface.text.AbstractInformationControl;
|
|
58 import dwtx.jface.text.IDelayedInputChangeProvider;
|
|
59 import dwtx.jface.text.IInformationControlExtension2;
|
|
60 import dwtx.jface.text.IInputChangedListener;
|
|
61 import dwtx.jface.text.TextPresentation;
|
|
62
|
|
63
|
|
64 /**
|
|
65 * Displays HTML information in a {@link dwt.browser.Browser} widget.
|
|
66 * <p>
|
|
67 * This {@link IInformationControlExtension2} expects {@link #setInput(Object)} to be
|
|
68 * called with an argument of type {@link BrowserInformationControlInput}.
|
|
69 * </p>
|
|
70 * <p>
|
|
71 * Moved into this package from <code>dwtx.jface.internal.text.revisions</code>.</p>
|
|
72 * <p>
|
|
73 * This class may be instantiated; it is not intended to be subclassed.</p>
|
|
74 * <p>
|
|
75 * Current problems:
|
|
76 * <ul>
|
|
77 * <li>the size computation is too small</li>
|
|
78 * <li>focusLost event is not sent - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532</li>
|
|
79 * </ul>
|
|
80 * </p>
|
|
81 *
|
|
82 * @since 3.2
|
|
83 */
|
|
84 public class BrowserInformationControl : AbstractInformationControl , IInformationControlExtension2, IDelayedInputChangeProvider {
|
|
85
|
|
86
|
|
87 /**
|
|
88 * Tells whether the DWT Browser widget and hence this information
|
|
89 * control is available.
|
|
90 *
|
|
91 * @param parent the parent component used for checking or <code>null</code> if none
|
|
92 * @return <code>true</code> if this control is available
|
|
93 */
|
|
94 public static bool isAvailable(Composite parent) {
|
|
95 if (!fgAvailabilityChecked) {
|
|
96 try {
|
|
97 Browser browser= new Browser(parent, DWT.NONE);
|
|
98 browser.dispose();
|
|
99 fgIsAvailable= true;
|
|
100
|
|
101 Slider sliderV= new Slider(parent, DWT.VERTICAL);
|
|
102 Slider sliderH= new Slider(parent, DWT.HORIZONTAL);
|
|
103 int width= sliderV.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
|
|
104 int height= sliderH.computeSize(DWT.DEFAULT, DWT.DEFAULT).y;
|
|
105 fgScrollBarSize= new Point(width, height);
|
|
106 sliderV.dispose();
|
|
107 sliderH.dispose();
|
|
108 } catch (DWTError er) {
|
|
109 fgIsAvailable= false;
|
|
110 } finally {
|
|
111 fgAvailabilityChecked= true;
|
|
112 }
|
|
113 }
|
|
114
|
|
115 return fgIsAvailable;
|
|
116 }
|
|
117
|
|
118
|
|
119 /**
|
|
120 * Minimal size constraints.
|
|
121 * @since 3.2
|
|
122 */
|
|
123 private static final int MIN_WIDTH= 80;
|
|
124 private static final int MIN_HEIGHT= 50;
|
|
125
|
|
126
|
|
127 /**
|
|
128 * Availability checking cache.
|
|
129 */
|
|
130 private static bool fgIsAvailable= false;
|
|
131 private static bool fgAvailabilityChecked= false;
|
|
132
|
|
133 /**
|
|
134 * Cached scroll bar width and height
|
|
135 * @since 3.4
|
|
136 */
|
|
137 private static Point fgScrollBarSize;
|
|
138
|
|
139 /** The control's browser widget */
|
|
140 private Browser fBrowser;
|
|
141 /** Tells whether the browser has content */
|
|
142 private bool fBrowserHasContent;
|
|
143 /** Text layout used to approximate size of content when rendered in browser */
|
|
144 private TextLayout fTextLayout;
|
|
145 /** Bold text style */
|
|
146 private TextStyle fBoldStyle;
|
|
147
|
|
148 private BrowserInformationControlInput fInput;
|
|
149
|
|
150 /**
|
|
151 * <code>true</code> iff the browser has completed loading of the last
|
|
152 * input set via {@link #setInformation(String)}.
|
|
153 * @since 3.4
|
|
154 */
|
|
155 private bool fCompleted= false;
|
|
156
|
|
157 /**
|
|
158 * The listener to be notified when a delayed location changing event happened.
|
|
159 * @since 3.4
|
|
160 */
|
|
161 private IInputChangedListener fDelayedInputChangeListener;
|
|
162
|
|
163 /**
|
|
164 * The listeners to be notified when the input changed.
|
|
165 * @since 3.4
|
|
166 */
|
|
167 private ListenerList/*<IInputChangedListener>*/ fInputChangeListeners= new ListenerList(ListenerList.IDENTITY);
|
|
168
|
|
169 /**
|
|
170 * The symbolic name of the font used for size computations, or <code>null</code> to use dialog font.
|
|
171 * @since 3.4
|
|
172 */
|
|
173 private final String fSymbolicFontName;
|
|
174
|
|
175
|
|
176 /**
|
|
177 * Creates a browser information control with the given shell as parent.
|
|
178 *
|
|
179 * @param parent the parent shell
|
|
180 * @param symbolicFontName the symbolic name of the font used for size computations
|
|
181 * @param resizable <code>true</code> if the control should be resizable
|
|
182 * @since 3.4
|
|
183 */
|
|
184 public BrowserInformationControl(Shell parent, String symbolicFontName, bool resizable) {
|
|
185 super(parent, resizable);
|
|
186 fSymbolicFontName= symbolicFontName;
|
|
187 create();
|
|
188 }
|
|
189
|
|
190 /**
|
|
191 * Creates a browser information control with the given shell as parent.
|
|
192 *
|
|
193 * @param parent the parent shell
|
|
194 * @param symbolicFontName the symbolic name of the font used for size computations
|
|
195 * @param statusFieldText the text to be used in the optional status field
|
|
196 * or <code>null</code> if the status field should be hidden
|
|
197 * @since 3.4
|
|
198 */
|
|
199 public BrowserInformationControl(Shell parent, String symbolicFontName, String statusFieldText) {
|
|
200 super(parent, statusFieldText);
|
|
201 fSymbolicFontName= symbolicFontName;
|
|
202 create();
|
|
203 }
|
|
204
|
|
205 /**
|
|
206 * Creates a browser information control with the given shell as parent.
|
|
207 *
|
|
208 * @param parent the parent shell
|
|
209 * @param symbolicFontName the symbolic name of the font used for size computations
|
|
210 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired
|
|
211 * @since 3.4
|
|
212 */
|
|
213 public BrowserInformationControl(Shell parent, String symbolicFontName, ToolBarManager toolBarManager) {
|
|
214 super(parent, toolBarManager);
|
|
215 fSymbolicFontName= symbolicFontName;
|
|
216 create();
|
|
217 }
|
|
218
|
|
219 /*
|
|
220 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite)
|
|
221 */
|
|
222 protected void createContent(Composite parent) {
|
|
223 fBrowser= new Browser(parent, DWT.NONE);
|
|
224
|
|
225 Display display= getShell().getDisplay();
|
|
226 fBrowser.setForeground(display.getSystemColor(DWT.COLOR_INFO_FOREGROUND));
|
|
227 fBrowser.setBackground(display.getSystemColor(DWT.COLOR_INFO_BACKGROUND));
|
|
228 fBrowser.addKeyListener(new KeyListener() {
|
|
229
|
|
230 public void keyPressed(KeyEvent e) {
|
|
231 if (e.character is 0x1B) // ESC
|
|
232 getShell().dispose(); // XXX: Just hide? Would avoid constant recreations.
|
|
233 }
|
|
234
|
|
235 public void keyReleased(KeyEvent e) {}
|
|
236 });
|
|
237
|
|
238 fBrowser.addProgressListener(new ProgressAdapter() {
|
|
239 public void completed(ProgressEvent event) {
|
|
240 fCompleted= true;
|
|
241 }
|
|
242 });
|
|
243
|
|
244 // Replace browser's built-in context menu with none
|
|
245 fBrowser.setMenu(new Menu(getShell(), DWT.NONE));
|
|
246
|
|
247 createTextLayout();
|
|
248 }
|
|
249
|
|
250 /**
|
|
251 * {@inheritDoc}
|
|
252 * @deprecated use {@link #setInput(Object)}
|
|
253 */
|
|
254 public void setInformation(final String content) {
|
|
255 setInput(new BrowserInformationControlInput(null) {
|
|
256 public String getHtml() {
|
|
257 return content;
|
|
258 }
|
|
259
|
|
260 public String getInputName() {
|
|
261 return ""; //$NON-NLS-1$
|
|
262 }
|
|
263
|
|
264 public Object getInputElement() {
|
|
265 return content;
|
|
266 }
|
|
267 });
|
|
268 }
|
|
269
|
|
270 /**
|
|
271 * {@inheritDoc} This control can handle {@link String} and
|
|
272 * {@link BrowserInformationControlInput}.
|
|
273 */
|
|
274 public void setInput(Object input) {
|
|
275 Assert.isLegal(input is null || input instanceof String || input instanceof BrowserInformationControlInput);
|
|
276
|
|
277 if (input instanceof String) {
|
|
278 setInformation((String)input);
|
|
279 return;
|
|
280 }
|
|
281
|
|
282 fInput= (BrowserInformationControlInput)input;
|
|
283
|
|
284 String content= null;
|
|
285 if (fInput !is null)
|
|
286 content= fInput.getHtml();
|
|
287
|
|
288 fBrowserHasContent= content !is null && content.length() > 0;
|
|
289
|
|
290 if (!fBrowserHasContent)
|
|
291 content= "<html><body ></html>"; //$NON-NLS-1$
|
|
292
|
|
293 bool RTL= (getShell().getStyle() & DWT.RIGHT_TO_LEFT) !is 0;
|
|
294 bool resizable= isResizable();
|
|
295
|
|
296 // The default "overflow:auto" would not result in a predictable width for the client area
|
|
297 // and the re-wrapping would cause visual noise
|
|
298 String[] styles= null;
|
|
299 if (RTL && resizable)
|
|
300 styles= new String[] { "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
301 else if (RTL && !resizable)
|
|
302 styles= new String[] { "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
303 else if (!resizable)
|
|
304 //XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even in non-broken words :-(see e.g. Javadoc of String).
|
|
305 // Re-check whether we really still need this now that the Javadoc Hover header already sets this style.
|
|
306 styles= new String[] { "overflow:hidden;"/*, "word-wrap: break-word;"*/ }; //$NON-NLS-1$
|
|
307 else
|
|
308 styles= new String[] { "overflow:scroll;" }; //$NON-NLS-1$
|
|
309
|
|
310 StringBuffer buffer= new StringBuffer(content);
|
|
311 HTMLPrinter.insertStyles(buffer, styles);
|
|
312 content= buffer.toString();
|
|
313
|
|
314 /*
|
|
315 * XXX: Should add some JavaScript here that shows something like
|
|
316 * "(continued...)" or "..." at the end of the visible area when the page overflowed
|
|
317 * with "overflow:hidden;".
|
|
318 */
|
|
319
|
|
320 fCompleted= false;
|
|
321 fBrowser.setText(content);
|
|
322
|
|
323 Object[] listeners= fInputChangeListeners.getListeners();
|
|
324 for (int i= 0; i < listeners.length; i++)
|
|
325 ((IInputChangedListener)listeners[i]).inputChanged(fInput);
|
|
326 }
|
|
327
|
|
328 /*
|
|
329 * @see IInformationControl#setVisible(bool)
|
|
330 */
|
|
331 public void setVisible(bool visible) {
|
|
332 Shell shell= getShell();
|
|
333 if (shell.isVisible() is visible)
|
|
334 return;
|
|
335
|
|
336 if (!visible) {
|
|
337 super.setVisible(false);
|
|
338 setInput(null);
|
|
339 return;
|
|
340 }
|
|
341
|
|
342 /*
|
|
343 * The Browser widget flickers when made visible while it is not completely loaded.
|
|
344 * The fix is to delay the call to setVisible until either loading is completed
|
|
345 * (see ProgressListener in constructor), or a timeout has been reached.
|
|
346 */
|
|
347 final Display display= shell.getDisplay();
|
|
348
|
|
349 // Make sure the display wakes from sleep after timeout:
|
|
350 display.timerExec(100, new Runnable() {
|
|
351 public void run() {
|
|
352 fCompleted= true;
|
|
353 }
|
|
354 });
|
|
355
|
|
356 while (!fCompleted) {
|
|
357 // Drive the event loop to process the events required to load the browser widget's contents:
|
|
358 if (!display.readAndDispatch()) {
|
|
359 display.sleep();
|
|
360 }
|
|
361 }
|
|
362
|
|
363 shell= getShell();
|
|
364 if (shell is null || shell.isDisposed())
|
|
365 return;
|
|
366
|
|
367 /*
|
|
368 * Avoids flickering when replacing hovers, especially on Vista in ON_CLICK mode.
|
|
369 * Causes flickering on GTK. Carbon does not care.
|
|
370 */
|
|
371 if ("win32".equals(DWT.getPlatform())) //$NON-NLS-1$
|
|
372 shell.moveAbove(null);
|
|
373
|
|
374 super.setVisible(true);
|
|
375 }
|
|
376
|
|
377 /*
|
|
378 * @see dwtx.jface.text.AbstractInformationControl#setSize(int, int)
|
|
379 */
|
|
380 public void setSize(int width, int height) {
|
|
381 fBrowser.setRedraw(false); // avoid flickering
|
|
382 try {
|
|
383 super.setSize(width, height);
|
|
384 } finally {
|
|
385 fBrowser.setRedraw(true);
|
|
386 }
|
|
387 }
|
|
388
|
|
389 /**
|
|
390 * Creates and initializes the text layout used
|
|
391 * to compute the size hint.
|
|
392 *
|
|
393 * @since 3.2
|
|
394 */
|
|
395 private void createTextLayout() {
|
|
396 fTextLayout= new TextLayout(fBrowser.getDisplay());
|
|
397
|
|
398 // Initialize fonts
|
|
399 Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName);
|
|
400 fTextLayout.setFont(font);
|
|
401 fTextLayout.setWidth(-1);
|
|
402 FontData[] fontData= font.getFontData();
|
|
403 for (int i= 0; i < fontData.length; i++)
|
|
404 fontData[i].setStyle(DWT.BOLD);
|
|
405 font= new Font(getShell().getDisplay(), fontData);
|
|
406 fBoldStyle= new TextStyle(font, null, null);
|
|
407
|
|
408 // Compute and set tab width
|
|
409 fTextLayout.setText(" "); //$NON-NLS-1$
|
|
410 int tabWidth = fTextLayout.getBounds().width;
|
|
411 fTextLayout.setTabs(new int[] {tabWidth});
|
|
412
|
|
413 fTextLayout.setText(""); //$NON-NLS-1$
|
|
414 }
|
|
415
|
|
416 /*
|
|
417 * @see IInformationControl#dispose()
|
|
418 */
|
|
419 public void dispose() {
|
|
420 if (fTextLayout !is null) {
|
|
421 fTextLayout.dispose();
|
|
422 fTextLayout= null;
|
|
423 }
|
|
424 if (fBoldStyle !is null) {
|
|
425 fBoldStyle.font.dispose();
|
|
426 fBoldStyle= null;
|
|
427 }
|
|
428 fBrowser= null;
|
|
429
|
|
430 super.dispose();
|
|
431 }
|
|
432
|
|
433 /*
|
|
434 * @see IInformationControl#computeSizeHint()
|
|
435 */
|
|
436 public Point computeSizeHint() {
|
|
437 Point sizeConstraints= getSizeConstraints();
|
|
438 Rectangle trim= computeTrim();
|
|
439 int height= trim.height;
|
|
440
|
|
441 //FIXME: The HTML2TextReader does not render <p> like a browser.
|
|
442 // Instead of inserting an empty line, it just adds a single line break.
|
|
443 // Furthermore, the indentation of <dl><dd> elements is too small (e.g with a long @see line)
|
|
444 TextPresentation presentation= new TextPresentation();
|
|
445 HTML2TextReader reader= new HTML2TextReader(new StringReader(fInput.getHtml()), presentation);
|
|
446 String text;
|
|
447 try {
|
|
448 text= reader.getString();
|
|
449 } catch (IOException e) {
|
|
450 text= ""; //$NON-NLS-1$
|
|
451 }
|
|
452
|
|
453 fTextLayout.setText(text);
|
|
454 fTextLayout.setWidth(sizeConstraints is null ? DWT.DEFAULT : sizeConstraints.x - trim.width);
|
|
455 Iterator iter= presentation.getAllStyleRangeIterator();
|
|
456 while (iter.hasNext()) {
|
|
457 StyleRange sr= (StyleRange)iter.next();
|
|
458 if (sr.fontStyle is DWT.BOLD)
|
|
459 fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1);
|
|
460 }
|
|
461
|
|
462 Rectangle bounds= fTextLayout.getBounds(); // does not return minimum width, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217446
|
|
463 int lineCount= fTextLayout.getLineCount();
|
|
464 int textWidth= 0;
|
|
465 for (int i= 0; i < lineCount; i++) {
|
|
466 Rectangle rect= fTextLayout.getLineBounds(i);
|
|
467 int lineWidth= rect.x + rect.width;
|
|
468 if (i is 0)
|
|
469 lineWidth += fInput.getLeadingImageWidth();
|
|
470 textWidth= Math.max(textWidth, lineWidth);
|
|
471 }
|
|
472 bounds.width= textWidth;
|
|
473 fTextLayout.setText(""); //$NON-NLS-1$
|
|
474
|
|
475 int minWidth= bounds.width;
|
|
476 height= height + bounds.height;
|
|
477
|
|
478 // Add some air to accommodate for different browser renderings
|
|
479 minWidth+= 15;
|
|
480 height+= 15;
|
|
481
|
|
482
|
|
483 // Apply max size constraints
|
|
484 if (sizeConstraints !is null) {
|
|
485 if (sizeConstraints.x !is DWT.DEFAULT)
|
|
486 minWidth= Math.min(sizeConstraints.x, minWidth + trim.width);
|
|
487 if (sizeConstraints.y !is DWT.DEFAULT)
|
|
488 height= Math.min(sizeConstraints.y, height);
|
|
489 }
|
|
490
|
|
491 // Ensure minimal size
|
|
492 int width= Math.max(MIN_WIDTH, minWidth);
|
|
493 height= Math.max(MIN_HEIGHT, height);
|
|
494
|
|
495 return new Point(width, height);
|
|
496 }
|
|
497
|
|
498 /*
|
|
499 * @see dwtx.jface.text.IInformationControlExtension3#computeTrim()
|
|
500 */
|
|
501 public Rectangle computeTrim() {
|
|
502 Rectangle trim= super.computeTrim();
|
|
503 if (isResizable()) {
|
|
504 bool RTL= (getShell().getStyle() & DWT.RIGHT_TO_LEFT) !is 0;
|
|
505 if (RTL) {
|
|
506 trim.x-= fgScrollBarSize.x;
|
|
507 }
|
|
508 trim.width+= fgScrollBarSize.x;
|
|
509 trim.height+= fgScrollBarSize.y;
|
|
510 }
|
|
511 return trim;
|
|
512 }
|
|
513
|
|
514 /**
|
|
515 * Adds the listener to the collection of listeners who will be
|
|
516 * notified when the current location has changed or is about to change.
|
|
517 *
|
|
518 * @param listener the location listener
|
|
519 * @since 3.4
|
|
520 */
|
|
521 public void addLocationListener(LocationListener listener) {
|
|
522 fBrowser.addLocationListener(listener);
|
|
523 }
|
|
524
|
|
525 /*
|
|
526 * @see IInformationControl#setForegroundColor(Color)
|
|
527 */
|
|
528 public void setForegroundColor(Color foreground) {
|
|
529 super.setForegroundColor(foreground);
|
|
530 fBrowser.setForeground(foreground);
|
|
531 }
|
|
532
|
|
533 /*
|
|
534 * @see IInformationControl#setBackgroundColor(Color)
|
|
535 */
|
|
536 public void setBackgroundColor(Color background) {
|
|
537 super.setBackgroundColor(background);
|
|
538 fBrowser.setBackground(background);
|
|
539 }
|
|
540
|
|
541 /*
|
|
542 * @see IInformationControlExtension#hasContents()
|
|
543 */
|
|
544 public bool hasContents() {
|
|
545 return fBrowserHasContent;
|
|
546 }
|
|
547
|
|
548 /**
|
|
549 * Adds a listener for input changes to this input change provider.
|
|
550 * Has no effect if an identical listener is already registered.
|
|
551 *
|
|
552 * @param inputChangeListener the listener to add
|
|
553 * @since 3.4
|
|
554 */
|
|
555 public void addInputChangeListener(IInputChangedListener inputChangeListener) {
|
|
556 Assert.isNotNull(inputChangeListener);
|
|
557 fInputChangeListeners.add(inputChangeListener);
|
|
558 }
|
|
559
|
|
560 /**
|
|
561 * Removes the given input change listener from this input change provider.
|
|
562 * Has no effect if an identical listener is not registered.
|
|
563 *
|
|
564 * @param inputChangeListener the listener to remove
|
|
565 * @since 3.4
|
|
566 */
|
|
567 public void removeInputChangeListener(IInputChangedListener inputChangeListener) {
|
|
568 fInputChangeListeners.remove(inputChangeListener);
|
|
569 }
|
|
570
|
|
571 /*
|
|
572 * @see dwtx.jface.text.IDelayedInputChangeProvider#setDelayedInputChangeListener(dwtx.jface.text.IInputChangedListener)
|
|
573 * @since 3.4
|
|
574 */
|
|
575 public void setDelayedInputChangeListener(IInputChangedListener inputChangeListener) {
|
|
576 fDelayedInputChangeListener= inputChangeListener;
|
|
577 }
|
|
578
|
|
579 /**
|
|
580 * Tells whether a delayed input change listener is registered.
|
|
581 *
|
|
582 * @return <code>true</code> iff a delayed input change
|
|
583 * listener is currently registered
|
|
584 * @since 3.4
|
|
585 */
|
|
586 public bool hasDelayedInputChangeListener() {
|
|
587 return fDelayedInputChangeListener !is null;
|
|
588 }
|
|
589
|
|
590 /**
|
|
591 * Notifies listeners of a delayed input change.
|
|
592 *
|
|
593 * @param newInput the new input, or <code>null</code> to request cancellation
|
|
594 * @since 3.4
|
|
595 */
|
|
596 public void notifyDelayedInputChange(Object newInput) {
|
|
597 if (fDelayedInputChangeListener !is null)
|
|
598 fDelayedInputChangeListener.inputChanged(newInput);
|
|
599 }
|
|
600
|
|
601 /*
|
|
602 * @see java.lang.Object#toString()
|
|
603 * @since 3.4
|
|
604 */
|
|
605 public String toString() {
|
|
606 String style= (getShell().getStyle() & DWT.RESIZE) is 0 ? "fixed" : "resizeable"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
607 return super.toString() + " - style: " + style; //$NON-NLS-1$
|
|
608 }
|
|
609
|
|
610 /**
|
|
611 * @return the current browser input or <code>null</code>
|
|
612 */
|
|
613 public BrowserInformationControlInput getInput() {
|
|
614 return fInput;
|
|
615 }
|
|
616
|
|
617 /*
|
|
618 * @see dwtx.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int)
|
|
619 */
|
|
620 public Point computeSizeConstraints(int widthInChars, int heightInChars) {
|
|
621 if (fSymbolicFontName is null)
|
|
622 return null;
|
|
623
|
|
624 GC gc= new GC(fBrowser);
|
|
625 Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName);
|
|
626 gc.setFont(font);
|
|
627 int width= gc.getFontMetrics().getAverageCharWidth();
|
|
628 int height= gc.getFontMetrics().getHeight();
|
|
629 gc.dispose();
|
|
630
|
|
631 return new Point(widthInChars * width, heightInChars * height);
|
|
632 }
|
|
633
|
|
634 }
|