75
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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 * Michael Williamson (eclipse-bugs@magnaworks.com) - patch (see Bugzilla #92545)
|
|
11 * Port to the D programming language:
|
|
12 * Frank Benoit <benoit@tionex.de>
|
|
13 *******************************************************************************/
|
|
14 module dwtx.ui.forms.widgets.FormToolkit;
|
|
15
|
|
16 import dwtx.ui.forms.widgets.Hyperlink;
|
|
17 import dwtx.ui.forms.widgets.ImageHyperlink;
|
|
18 import dwtx.ui.forms.widgets.ExpandableComposite;
|
|
19 import dwtx.ui.forms.widgets.Form;
|
|
20 import dwtx.ui.forms.widgets.ScrolledPageBook;
|
|
21 import dwtx.ui.forms.widgets.ScrolledForm;
|
|
22 import dwtx.ui.forms.widgets.FormText;
|
|
23 import dwtx.ui.forms.widgets.Section;
|
|
24 import dwtx.ui.forms.widgets.LayoutComposite;
|
|
25
|
|
26 import dwt.DWT;
|
|
27 import dwt.custom.CCombo;
|
|
28 import dwt.custom.ScrolledComposite;
|
|
29 import dwt.events.FocusAdapter;
|
|
30 import dwt.events.FocusEvent;
|
|
31 import dwt.events.KeyAdapter;
|
|
32 import dwt.events.KeyEvent;
|
|
33 import dwt.events.MouseAdapter;
|
|
34 import dwt.events.MouseEvent;
|
|
35 import dwt.events.PaintEvent;
|
|
36 import dwt.events.PaintListener;
|
|
37 import dwt.graphics.Color;
|
|
38 import dwt.graphics.Font;
|
|
39 import dwt.graphics.GC;
|
|
40 import dwt.graphics.Point;
|
|
41 import dwt.graphics.RGB;
|
|
42 import dwt.graphics.Rectangle;
|
|
43 import dwt.widgets.Button;
|
|
44 import dwt.widgets.Composite;
|
|
45 import dwt.widgets.Control;
|
|
46 import dwt.widgets.Display;
|
|
47 import dwt.widgets.Event;
|
|
48 import dwt.widgets.Label;
|
|
49 import dwt.widgets.Listener;
|
|
50 import dwt.widgets.Table;
|
|
51 import dwt.widgets.Text;
|
|
52 import dwt.widgets.Tree;
|
|
53 import dwt.widgets.Widget;
|
|
54 import dwtx.jface.resource.JFaceResources;
|
|
55 import dwtx.jface.window.Window;
|
|
56 import dwtx.ui.forms.FormColors;
|
|
57 import dwtx.ui.forms.HyperlinkGroup;
|
|
58 import dwtx.ui.forms.IFormColors;
|
|
59 import dwtx.ui.internal.forms.widgets.FormFonts;
|
|
60 import dwtx.ui.internal.forms.widgets.FormUtil;
|
|
61
|
|
62 import dwt.dwthelper.utils;
|
|
63
|
|
64 /**
|
|
65 * The toolkit is responsible for creating DWT controls adapted to work in
|
|
66 * Eclipse forms. In addition to changing their presentation properties (fonts,
|
|
67 * colors etc.), various listeners are attached to make them behave correctly in
|
|
68 * the form context.
|
|
69 * <p>
|
|
70 * In addition to being the control factory, the toolkit is also responsible for
|
|
71 * painting flat borders for select controls, managing hyperlink groups and
|
|
72 * control colors.
|
|
73 * <p>
|
|
74 * The toolkit creates some of the most common controls used to populate Eclipse
|
|
75 * forms. Controls that must be created using their constructors,
|
|
76 * <code>adapt()</code> method is available to change its properties in the
|
|
77 * same way as with the supported toolkit controls.
|
|
78 * <p>
|
|
79 * Typically, one toolkit object is created per workbench part (for example, an
|
|
80 * editor or a form wizard). The toolkit is disposed when the part is disposed.
|
|
81 * To conserve resources, it is possible to create one color object for the
|
|
82 * entire plug-in and share it between several toolkits. The plug-in is
|
|
83 * responsible for disposing the colors (disposing the toolkit that uses shared
|
|
84 * color object will not dispose the colors).
|
|
85 * <p>
|
|
86 * FormToolkit is normally instantiated, but can also be subclassed if some of
|
|
87 * the methods needs to be modified. In those cases, <code>super</code> must
|
|
88 * be called to preserve normal behaviour.
|
|
89 *
|
|
90 * @since 3.0
|
|
91 */
|
|
92 public class FormToolkit {
|
|
93 public static const String KEY_DRAW_BORDER = "FormWidgetFactory.drawBorder"; //$NON-NLS-1$
|
|
94
|
|
95 public static const String TREE_BORDER = "treeBorder"; //$NON-NLS-1$
|
|
96
|
|
97 public static const String TEXT_BORDER = "textBorder"; //$NON-NLS-1$
|
|
98
|
|
99 private int borderStyle = DWT.NULL;
|
|
100
|
|
101 private FormColors colors;
|
|
102
|
|
103 private int orientation;
|
|
104
|
|
105 // private KeyListener deleteListener;
|
|
106 private BorderPainter borderPainter;
|
|
107
|
|
108 private BoldFontHolder boldFontHolder;
|
|
109
|
|
110 private HyperlinkGroup hyperlinkGroup;
|
|
111
|
|
112 /* default */
|
|
113 VisibilityHandler visibilityHandler;
|
|
114
|
|
115 /* default */
|
|
116 KeyboardHandler keyboardHandler;
|
|
117
|
|
118 private class BorderPainter : PaintListener {
|
|
119 public void paintControl(PaintEvent event) {
|
|
120 Composite composite = cast(Composite) event.widget;
|
|
121 Control[] children = composite.getChildren();
|
|
122 for (int i = 0; i < children.length; i++) {
|
|
123 Control c = children[i];
|
|
124 bool inactiveBorder = false;
|
|
125 bool textBorder = false;
|
|
126 if (!c.isVisible())
|
|
127 continue;
|
|
128 /*
|
|
129 * if (c.getEnabled() is false && !(c instanceof CCombo))
|
|
130 * continue;
|
|
131 */
|
|
132 if (null !is cast(Hyperlink)c )
|
|
133 continue;
|
|
134 Object flag = c.getData(KEY_DRAW_BORDER);
|
|
135 if (flag !is null) {
|
|
136 if (flag.opEquals(Boolean.FALSE))
|
|
137 continue;
|
|
138 if (flag.opEquals(stringcast(TREE_BORDER)))
|
|
139 inactiveBorder = true;
|
|
140 else if (flag.opEquals(stringcast(TEXT_BORDER)))
|
|
141 textBorder = true;
|
|
142 }
|
|
143 if (getBorderStyle() is DWT.BORDER) {
|
|
144 if (!inactiveBorder && !textBorder) {
|
|
145 continue;
|
|
146 }
|
|
147 if (null !is cast(Text)c || null !is cast(Table)c
|
|
148 || null !is cast(Tree)c )
|
|
149 continue;
|
|
150 }
|
|
151 if (!inactiveBorder
|
|
152 && (null !is cast(Text)c || null !is cast(CCombo)c || textBorder)) {
|
|
153 Rectangle b = c.getBounds();
|
|
154 GC gc = event.gc;
|
|
155 gc.setForeground(c.getBackground());
|
|
156 gc.drawRectangle(b.x - 1, b.y - 1, b.width + 1,
|
|
157 b.height + 1);
|
|
158 // gc.setForeground(getBorderStyle() is DWT.BORDER ? colors
|
|
159 // .getBorderColor() : colors.getForeground());
|
|
160 gc.setForeground(colors.getBorderColor());
|
|
161 if (null !is cast(CCombo)c )
|
|
162 gc.drawRectangle(b.x - 1, b.y - 1, b.width + 1,
|
|
163 b.height + 1);
|
|
164 else
|
|
165 gc.drawRectangle(b.x - 1, b.y - 2, b.width + 1,
|
|
166 b.height + 3);
|
|
167 } else if (inactiveBorder || null !is cast(Table)c
|
|
168 || null !is cast(Tree)c ) {
|
|
169 Rectangle b = c.getBounds();
|
|
170 GC gc = event.gc;
|
|
171 gc.setForeground(colors.getBorderColor());
|
|
172 gc.drawRectangle(b.x - 1, b.y - 1, b.width + 1,
|
|
173 b.height + 1);
|
|
174 }
|
|
175 }
|
|
176 }
|
|
177 }
|
|
178
|
|
179 private static class VisibilityHandler : FocusAdapter {
|
|
180 public void focusGained(FocusEvent e) {
|
|
181 Widget w = e.widget;
|
|
182 if (null !is cast(Control)w ) {
|
|
183 FormUtil.ensureVisible(cast(Control) w);
|
|
184 }
|
|
185 }
|
|
186 }
|
|
187
|
|
188 private static class KeyboardHandler : KeyAdapter {
|
|
189 public void keyPressed(KeyEvent e) {
|
|
190 Widget w = e.widget;
|
|
191 if (null !is cast(Control)w ) {
|
|
192 if (e.doit)
|
|
193 FormUtil.processKey(e.keyCode, cast(Control) w);
|
|
194 }
|
|
195 }
|
|
196 }
|
|
197
|
|
198 private class BoldFontHolder {
|
|
199 private Font normalFont;
|
|
200
|
|
201 private Font boldFont;
|
|
202
|
|
203 public this() {
|
|
204 }
|
|
205
|
|
206 public Font getBoldFont(Font font) {
|
|
207 createBoldFont(font);
|
|
208 return boldFont;
|
|
209 }
|
|
210
|
|
211 private void createBoldFont(Font font) {
|
|
212 if (normalFont is null || !normalFont.opEquals(font)) {
|
|
213 normalFont = font;
|
|
214 dispose();
|
|
215 }
|
|
216 if (boldFont is null) {
|
|
217 boldFont = FormFonts.getInstance().getBoldFont(colors.getDisplay(),
|
|
218 normalFont);
|
|
219 }
|
|
220 }
|
|
221
|
|
222 public void dispose() {
|
|
223 if (boldFont !is null) {
|
|
224 FormFonts.getInstance().markFinished(boldFont);
|
|
225 boldFont = null;
|
|
226 }
|
|
227 }
|
|
228 }
|
|
229
|
|
230 /**
|
|
231 * Creates a toolkit that is self-sufficient (will manage its own colors).
|
|
232 *
|
|
233 */
|
|
234 public this(Display display) {
|
|
235 this(new FormColors(display));
|
|
236 }
|
|
237
|
|
238 /**
|
|
239 * Creates a toolkit that will use the provided (shared) colors. The toolkit
|
|
240 * will dispose the colors if and only if they are <b>not</b> marked as
|
|
241 * shared via the <code>markShared()</code> method.
|
|
242 *
|
|
243 * @param colors
|
|
244 * the shared colors
|
|
245 */
|
|
246 public this(FormColors colors) {
|
|
247 orientation = Window.getDefaultOrientation();
|
|
248 this.colors = colors;
|
|
249 initialize();
|
|
250 }
|
|
251
|
|
252 /**
|
|
253 * Creates a button as a part of the form.
|
|
254 *
|
|
255 * @param parent
|
|
256 * the button parent
|
|
257 * @param text
|
|
258 * an optional text for the button (can be <code>null</code>)
|
|
259 * @param style
|
|
260 * the button style (for example, <code>DWT.PUSH</code>)
|
|
261 * @return the button widget
|
|
262 */
|
|
263 public Button createButton(Composite parent, String text, int style) {
|
|
264 Button button = new Button(parent, style | DWT.FLAT | orientation);
|
|
265 if (text !is null)
|
|
266 button.setText(text);
|
|
267 adapt(button, true, true);
|
|
268 return button;
|
|
269 }
|
|
270
|
|
271 /**
|
|
272 * Creates the composite as a part of the form.
|
|
273 *
|
|
274 * @param parent
|
|
275 * the composite parent
|
|
276 * @return the composite widget
|
|
277 */
|
|
278 public Composite createComposite(Composite parent) {
|
|
279 return createComposite(parent, DWT.NULL);
|
|
280 }
|
|
281
|
|
282 /**
|
|
283 * Creates the composite as part of the form using the provided style.
|
|
284 *
|
|
285 * @param parent
|
|
286 * the composite parent
|
|
287 * @param style
|
|
288 * the composite style
|
|
289 * @return the composite widget
|
|
290 */
|
|
291 public Composite createComposite(Composite parent, int style) {
|
|
292 Composite composite = new LayoutComposite(parent, style | orientation);
|
|
293 adapt(composite);
|
|
294 return composite;
|
|
295 }
|
|
296
|
|
297 /**
|
|
298 * Creats the composite that can server as a separator between various parts
|
|
299 * of a form. Separator height should be controlled by setting the height
|
|
300 * hint on the layout data for the composite.
|
|
301 *
|
|
302 * @param parent
|
|
303 * the separator parent
|
|
304 * @return the separator widget
|
|
305 */
|
|
306 public Composite createCompositeSeparator(Composite parent) {
|
|
307 final Composite composite = new Composite(parent, orientation);
|
85
|
308 // DWT FIXME: problem with DMD and anonclass/nested func
|
|
309 composite.addListener(DWT.Paint, dgListener( &dwtWorkaround, composite));
|
|
310 if (null !is cast(Section)parent )
|
|
311 (cast(Section) parent).setSeparatorControl(composite);
|
|
312 return composite;
|
|
313 }
|
|
314 // DWT FIXME: problem with DMD and anonclass/nested func
|
|
315 private void dwtWorkaround (Event e, Composite composite) {
|
75
|
316 if (composite.isDisposed())
|
|
317 return;
|
|
318 Rectangle bounds = composite.getBounds();
|
|
319 GC gc = e.gc;
|
|
320 gc.setForeground(colors.getColor(IFormColors.SEPARATOR));
|
|
321 if (colors.getBackground() !is null)
|
|
322 gc.setBackground(colors.getBackground());
|
|
323 gc.fillGradientRectangle(0, 0, bounds.width, bounds.height,
|
|
324 false);
|
85
|
325 }
|
75
|
326 /**
|
|
327 * Creates a label as a part of the form.
|
|
328 *
|
|
329 * @param parent
|
|
330 * the label parent
|
|
331 * @param text
|
|
332 * the label text
|
|
333 * @return the label widget
|
|
334 */
|
|
335 public Label createLabel(Composite parent, String text) {
|
|
336 return createLabel(parent, text, DWT.NONE);
|
|
337 }
|
|
338
|
|
339 /**
|
|
340 * Creates a label as a part of the form.
|
|
341 *
|
|
342 * @param parent
|
|
343 * the label parent
|
|
344 * @param text
|
|
345 * the label text
|
|
346 * @param style
|
|
347 * the label style
|
|
348 * @return the label widget
|
|
349 */
|
|
350 public Label createLabel(Composite parent, String text, int style) {
|
|
351 Label label = new Label(parent, style | orientation);
|
|
352 if (text !is null)
|
|
353 label.setText(text);
|
|
354 adapt(label, false, false);
|
|
355 return label;
|
|
356 }
|
|
357
|
|
358 /**
|
|
359 * Creates a hyperlink as a part of the form. The hyperlink will be added to
|
|
360 * the hyperlink group that belongs to this toolkit.
|
|
361 *
|
|
362 * @param parent
|
|
363 * the hyperlink parent
|
|
364 * @param text
|
|
365 * the text of the hyperlink
|
|
366 * @param style
|
|
367 * the hyperlink style
|
|
368 * @return the hyperlink widget
|
|
369 */
|
|
370 public Hyperlink createHyperlink(Composite parent, String text, int style) {
|
|
371 Hyperlink hyperlink = new Hyperlink(parent, style | orientation);
|
|
372 if (text !is null)
|
|
373 hyperlink.setText(text);
|
|
374 hyperlink.addFocusListener(visibilityHandler);
|
|
375 hyperlink.addKeyListener(keyboardHandler);
|
|
376 hyperlinkGroup.add(hyperlink);
|
|
377 return hyperlink;
|
|
378 }
|
|
379
|
|
380 /**
|
|
381 * Creates an image hyperlink as a part of the form. The hyperlink will be
|
|
382 * added to the hyperlink group that belongs to this toolkit.
|
|
383 *
|
|
384 * @param parent
|
|
385 * the hyperlink parent
|
|
386 * @param style
|
|
387 * the hyperlink style
|
|
388 * @return the image hyperlink widget
|
|
389 */
|
|
390 public ImageHyperlink createImageHyperlink(Composite parent, int style) {
|
|
391 ImageHyperlink hyperlink = new ImageHyperlink(parent, style
|
|
392 | orientation);
|
|
393 hyperlink.addFocusListener(visibilityHandler);
|
|
394 hyperlink.addKeyListener(keyboardHandler);
|
|
395 hyperlinkGroup.add(hyperlink);
|
|
396 return hyperlink;
|
|
397 }
|
|
398
|
|
399 /**
|
|
400 * Creates a rich text as a part of the form.
|
|
401 *
|
|
402 * @param parent
|
|
403 * the rich text parent
|
|
404 * @param trackFocus
|
|
405 * if <code>true</code>, the toolkit will monitor focus
|
|
406 * transfers to ensure that the hyperlink in focus is visible in
|
|
407 * the form.
|
|
408 * @return the rich text widget
|
|
409 */
|
|
410 public FormText createFormText(Composite parent, bool trackFocus) {
|
|
411 FormText engine = new FormText(parent, DWT.WRAP | orientation);
|
|
412 engine.marginWidth = 1;
|
|
413 engine.marginHeight = 0;
|
|
414 engine.setHyperlinkSettings(getHyperlinkGroup());
|
|
415 adapt(engine, trackFocus, true);
|
|
416 engine.setMenu(parent.getMenu());
|
|
417 return engine;
|
|
418 }
|
|
419
|
|
420 /**
|
|
421 * Adapts a control to be used in a form that is associated with this
|
|
422 * toolkit. This involves adjusting colors and optionally adding handlers to
|
|
423 * ensure focus tracking and keyboard management.
|
|
424 *
|
|
425 * @param control
|
|
426 * a control to adapt
|
|
427 * @param trackFocus
|
|
428 * if <code>true</code>, form will be scrolled horizontally
|
|
429 * and/or vertically if needed to ensure that the control is
|
|
430 * visible when it gains focus. Set it to <code>false</code> if
|
|
431 * the control is not capable of gaining focus.
|
|
432 * @param trackKeyboard
|
|
433 * if <code>true</code>, the control that is capable of
|
|
434 * gaining focus will be tracked for certain keys that are
|
|
435 * important to the underlying form (for example, PageUp,
|
|
436 * PageDown, ScrollUp, ScrollDown etc.). Set it to
|
|
437 * <code>false</code> if the control is not capable of gaining
|
|
438 * focus or these particular key event are already used by the
|
|
439 * control.
|
|
440 */
|
|
441 public void adapt(Control control, bool trackFocus, bool trackKeyboard) {
|
|
442 control.setBackground(colors.getBackground());
|
|
443 control.setForeground(colors.getForeground());
|
|
444 if (null !is cast(ExpandableComposite)control ) {
|
|
445 ExpandableComposite ec = cast(ExpandableComposite) control;
|
|
446 if (ec.toggle_package !is null) {
|
|
447 if (trackFocus)
|
|
448 ec.toggle_package.addFocusListener(visibilityHandler);
|
|
449 if (trackKeyboard)
|
|
450 ec.toggle_package.addKeyListener(keyboardHandler);
|
|
451 }
|
|
452 if (ec.textLabel_package !is null) {
|
|
453 if (trackFocus)
|
|
454 ec.textLabel_package.addFocusListener(visibilityHandler);
|
|
455 if (trackKeyboard)
|
|
456 ec.textLabel_package.addKeyListener(keyboardHandler);
|
|
457 }
|
|
458 return;
|
|
459 }
|
|
460 if (trackFocus)
|
|
461 control.addFocusListener(visibilityHandler);
|
|
462 if (trackKeyboard)
|
|
463 control.addKeyListener(keyboardHandler);
|
|
464 }
|
|
465
|
|
466 /**
|
|
467 * Adapts a composite to be used in a form associated with this toolkit.
|
|
468 *
|
|
469 * @param composite
|
|
470 * the composite to adapt
|
|
471 */
|
|
472 public void adapt(Composite composite) {
|
|
473 composite.setBackground(colors.getBackground());
|
|
474 composite.addMouseListener(new class MouseAdapter {
|
|
475 public void mouseDown(MouseEvent e) {
|
|
476 (cast(Control) e.widget).setFocus();
|
|
477 }
|
|
478 });
|
|
479 composite.setMenu(composite.getParent().getMenu());
|
|
480 }
|
|
481
|
|
482 /**
|
|
483 * A helper method that ensures the provided control is visible when
|
|
484 * ScrolledComposite is somewhere in the parent chain. If scroll bars are
|
|
485 * visible and the control is clipped, the client of the scrolled composite
|
|
486 * will be scrolled to reveal the control.
|
|
487 *
|
|
488 * @param c
|
|
489 * the control to reveal
|
|
490 */
|
|
491 public static void ensureVisible(Control c) {
|
|
492 FormUtil.ensureVisible(c);
|
|
493 }
|
|
494
|
|
495 /**
|
|
496 * Creates a section as a part of the form.
|
|
497 *
|
|
498 * @param parent
|
|
499 * the section parent
|
|
500 * @param sectionStyle
|
|
501 * the section style
|
|
502 * @return the section widget
|
|
503 */
|
|
504 public Section createSection(Composite parent, int sectionStyle) {
|
|
505 Section section = new Section(parent, orientation, sectionStyle);
|
|
506 section.setMenu(parent.getMenu());
|
|
507 adapt(section, true, true);
|
|
508 if (section.toggle_package !is null) {
|
|
509 section.toggle_package.setHoverDecorationColor(colors
|
|
510 .getColor(IFormColors.TB_TOGGLE_HOVER));
|
|
511 section.toggle_package.setDecorationColor(colors
|
|
512 .getColor(IFormColors.TB_TOGGLE));
|
|
513 }
|
|
514 section.setFont(boldFontHolder.getBoldFont(parent.getFont()));
|
|
515 if ((sectionStyle & Section.TITLE_BAR) !is 0
|
|
516 || (sectionStyle & Section.SHORT_TITLE_BAR) !is 0) {
|
|
517 colors.initializeSectionToolBarColors();
|
|
518 section.setTitleBarBackground(colors.getColor(IFormColors.TB_BG));
|
|
519 section.setTitleBarBorderColor(colors
|
|
520 .getColor(IFormColors.TB_BORDER));
|
|
521 section.setTitleBarForeground(colors
|
|
522 .getColor(IFormColors.TB_TOGGLE));
|
|
523 }
|
|
524 return section;
|
|
525 }
|
|
526
|
|
527 /**
|
|
528 * Creates an expandable composite as a part of the form.
|
|
529 *
|
|
530 * @param parent
|
|
531 * the expandable composite parent
|
|
532 * @param expansionStyle
|
|
533 * the expandable composite style
|
|
534 * @return the expandable composite widget
|
|
535 */
|
|
536 public ExpandableComposite createExpandableComposite(Composite parent,
|
|
537 int expansionStyle) {
|
|
538 ExpandableComposite ec = new ExpandableComposite(parent, orientation,
|
|
539 expansionStyle);
|
|
540 ec.setMenu(parent.getMenu());
|
|
541 adapt(ec, true, true);
|
|
542 ec.setFont(boldFontHolder.getBoldFont(ec.getFont()));
|
|
543 return ec;
|
|
544 }
|
|
545
|
|
546 /**
|
|
547 * Creates a separator label as a part of the form.
|
|
548 *
|
|
549 * @param parent
|
|
550 * the separator parent
|
|
551 * @param style
|
|
552 * the separator style
|
|
553 * @return the separator label
|
|
554 */
|
|
555 public Label createSeparator(Composite parent, int style) {
|
|
556 Label label = new Label(parent, DWT.SEPARATOR | style | orientation);
|
|
557 label.setBackground(colors.getBackground());
|
|
558 label.setForeground(colors.getBorderColor());
|
|
559 return label;
|
|
560 }
|
|
561
|
|
562 /**
|
|
563 * Creates a table as a part of the form.
|
|
564 *
|
|
565 * @param parent
|
|
566 * the table parent
|
|
567 * @param style
|
|
568 * the table style
|
|
569 * @return the table widget
|
|
570 */
|
|
571 public Table createTable(Composite parent, int style) {
|
|
572 Table table = new Table(parent, style | borderStyle | orientation);
|
|
573 adapt(table, false, false);
|
|
574 // hookDeleteListener(table);
|
|
575 return table;
|
|
576 }
|
|
577
|
|
578 /**
|
|
579 * Creates a text as a part of the form.
|
|
580 *
|
|
581 * @param parent
|
|
582 * the text parent
|
|
583 * @param value
|
|
584 * the text initial value
|
|
585 * @return the text widget
|
|
586 */
|
|
587 public Text createText(Composite parent, String value) {
|
|
588 return createText(parent, value, DWT.SINGLE);
|
|
589 }
|
|
590
|
|
591 /**
|
|
592 * Creates a text as a part of the form.
|
|
593 *
|
|
594 * @param parent
|
|
595 * the text parent
|
|
596 * @param value
|
|
597 * the text initial value
|
|
598 * @param style
|
|
599 * the text style
|
|
600 * @return the text widget
|
|
601 */
|
|
602 public Text createText(Composite parent, String value, int style) {
|
|
603 Text text = new Text(parent, borderStyle | style | orientation);
|
|
604 if (value !is null)
|
|
605 text.setText(value);
|
|
606 text.setForeground(colors.getForeground());
|
|
607 text.setBackground(colors.getBackground());
|
|
608 text.addFocusListener(visibilityHandler);
|
|
609 return text;
|
|
610 }
|
|
611
|
|
612 /**
|
|
613 * Creates a tree widget as a part of the form.
|
|
614 *
|
|
615 * @param parent
|
|
616 * the tree parent
|
|
617 * @param style
|
|
618 * the tree style
|
|
619 * @return the tree widget
|
|
620 */
|
|
621 public Tree createTree(Composite parent, int style) {
|
|
622 Tree tree = new Tree(parent, borderStyle | style | orientation);
|
|
623 adapt(tree, false, false);
|
|
624 // hookDeleteListener(tree);
|
|
625 return tree;
|
|
626 }
|
|
627
|
|
628 /**
|
|
629 * Creates a scrolled form widget in the provided parent. If you do not
|
|
630 * require scrolling because there is already a scrolled composite up the
|
|
631 * parent chain, use 'createForm' instead.
|
|
632 *
|
|
633 * @param parent
|
|
634 * the scrolled form parent
|
|
635 * @return the form that can scroll itself
|
|
636 * @see #createForm
|
|
637 */
|
|
638 public ScrolledForm createScrolledForm(Composite parent) {
|
|
639 ScrolledForm form = new ScrolledForm(parent, DWT.V_SCROLL
|
|
640 | DWT.H_SCROLL | orientation);
|
|
641 form.setExpandHorizontal(true);
|
|
642 form.setExpandVertical(true);
|
|
643 form.setBackground(colors.getBackground());
|
|
644 form.setForeground(colors.getColor(IFormColors.TITLE));
|
|
645 form.setFont(JFaceResources.getHeaderFont());
|
|
646 return form;
|
|
647 }
|
|
648
|
|
649 /**
|
|
650 * Creates a form widget in the provided parent. Note that this widget does
|
|
651 * not scroll its content, so make sure there is a scrolled composite up the
|
|
652 * parent chain. If you require scrolling, use 'createScrolledForm' instead.
|
|
653 *
|
|
654 * @param parent
|
|
655 * the form parent
|
|
656 * @return the form that does not scroll
|
|
657 * @see #createScrolledForm
|
|
658 */
|
|
659 public Form createForm(Composite parent) {
|
|
660 Form formContent = new Form(parent, orientation);
|
|
661 formContent.setBackground(colors.getBackground());
|
|
662 formContent.setForeground(colors.getColor(IFormColors.TITLE));
|
|
663 formContent.setFont(JFaceResources.getHeaderFont());
|
|
664 return formContent;
|
|
665 }
|
|
666
|
|
667 /**
|
|
668 * Takes advantage of the gradients and other capabilities to decorate the
|
|
669 * form heading using colors computed based on the current skin and
|
|
670 * operating system.
|
|
671 *
|
|
672 * @since 3.3
|
|
673 * @param form
|
|
674 * the form to decorate
|
|
675 */
|
|
676
|
|
677 public void decorateFormHeading(Form form) {
|
|
678 Color top = colors.getColor(IFormColors.H_GRADIENT_END);
|
|
679 Color bot = colors.getColor(IFormColors.H_GRADIENT_START);
|
|
680 form.setTextBackground([ top, bot ], [ 100 ],
|
|
681 true);
|
|
682 form.setHeadColor(IFormColors.H_BOTTOM_KEYLINE1, colors
|
|
683 .getColor(IFormColors.H_BOTTOM_KEYLINE1));
|
|
684 form.setHeadColor(IFormColors.H_BOTTOM_KEYLINE2, colors
|
|
685 .getColor(IFormColors.H_BOTTOM_KEYLINE2));
|
|
686 form.setHeadColor(IFormColors.H_HOVER_LIGHT, colors
|
|
687 .getColor(IFormColors.H_HOVER_LIGHT));
|
|
688 form.setHeadColor(IFormColors.H_HOVER_FULL, colors
|
|
689 .getColor(IFormColors.H_HOVER_FULL));
|
|
690 form.setHeadColor(IFormColors.TB_TOGGLE, colors
|
|
691 .getColor(IFormColors.TB_TOGGLE));
|
|
692 form.setHeadColor(IFormColors.TB_TOGGLE_HOVER, colors
|
|
693 .getColor(IFormColors.TB_TOGGLE_HOVER));
|
|
694 form.setSeparatorVisible(true);
|
|
695 }
|
|
696
|
|
697 /**
|
|
698 * Creates a scrolled page book widget as a part of the form.
|
|
699 *
|
|
700 * @param parent
|
|
701 * the page book parent
|
|
702 * @param style
|
|
703 * the text style
|
|
704 * @return the scrolled page book widget
|
|
705 */
|
|
706 public ScrolledPageBook createPageBook(Composite parent, int style) {
|
|
707 ScrolledPageBook book = new ScrolledPageBook(parent, style
|
|
708 | orientation);
|
|
709 adapt(book, true, true);
|
|
710 book.setMenu(parent.getMenu());
|
|
711 return book;
|
|
712 }
|
|
713
|
|
714 /**
|
|
715 * Disposes the toolkit.
|
|
716 */
|
|
717 public void dispose() {
|
|
718 if (colors.isShared() is false) {
|
|
719 colors.dispose();
|
|
720 colors = null;
|
|
721 }
|
|
722 boldFontHolder.dispose();
|
|
723 }
|
|
724
|
|
725 /**
|
|
726 * Returns the hyperlink group that manages hyperlinks for this toolkit.
|
|
727 *
|
|
728 * @return the hyperlink group
|
|
729 */
|
|
730 public HyperlinkGroup getHyperlinkGroup() {
|
|
731 return hyperlinkGroup;
|
|
732 }
|
|
733
|
|
734 /**
|
|
735 * Sets the background color for the entire toolkit. The method delegates
|
|
736 * the call to the FormColors object and also updates the hyperlink group so
|
|
737 * that hyperlinks and other objects are in sync.
|
|
738 *
|
|
739 * @param bg
|
|
740 * the new background color
|
|
741 */
|
|
742 public void setBackground(Color bg) {
|
|
743 hyperlinkGroup.setBackground(bg);
|
|
744 colors.setBackground(bg);
|
|
745 }
|
|
746
|
|
747 /**
|
|
748 * Refreshes the hyperlink colors by loading from JFace settings.
|
|
749 */
|
|
750 public void refreshHyperlinkColors() {
|
|
751 hyperlinkGroup.initializeDefaultForegrounds(colors.getDisplay());
|
|
752 }
|
|
753
|
|
754 /**
|
|
755 * Paints flat borders for widgets created by this toolkit within the
|
|
756 * provided parent. Borders will not be painted if the global border style
|
|
757 * is DWT.BORDER (i.e. if native borders are used). Call this method during
|
|
758 * creation of a form composite to get the borders of its children painted.
|
|
759 * Care should be taken when selection layout margins. At least one pixel
|
|
760 * pargin width and height must be chosen to allow the toolkit to paint the
|
|
761 * border on the parent around the widgets.
|
|
762 * <p>
|
|
763 * Borders are painted for some controls that are selected by the toolkit by
|
|
764 * default. If a control needs a border but is not on its list, it is
|
|
765 * possible to force border in the following way:
|
|
766 *
|
|
767 * <pre>
|
|
768 *
|
|
769 *
|
|
770 *
|
|
771 * widget.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
|
|
772 *
|
|
773 * or
|
|
774 *
|
|
775 * widget.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
|
|
776 *
|
|
777 *
|
|
778 *
|
|
779 * </pre>
|
|
780 *
|
|
781 * @param parent
|
|
782 * the parent that owns the children for which the border needs
|
|
783 * to be painted.
|
|
784 */
|
|
785 public void paintBordersFor(Composite parent) {
|
|
786 // if (borderStyle is DWT.BORDER)
|
|
787 // return;
|
|
788 if (borderPainter is null)
|
|
789 borderPainter = new BorderPainter();
|
|
790 parent.addPaintListener(borderPainter);
|
|
791 }
|
|
792
|
|
793 /**
|
|
794 * Returns the colors used by this toolkit.
|
|
795 *
|
|
796 * @return the color object
|
|
797 */
|
|
798 public FormColors getColors() {
|
|
799 return colors;
|
|
800 }
|
|
801
|
|
802 /**
|
|
803 * Returns the border style used for various widgets created by this
|
|
804 * toolkit. The intent of the toolkit is to create controls with styles that
|
|
805 * yield a 'flat' appearance. On systems where the native borders are
|
|
806 * already flat, we set the style to DWT.BORDER and don't paint the borders
|
|
807 * ourselves. Otherwise, the style is set to DWT.NULL, and borders are
|
|
808 * painted by the toolkit.
|
|
809 *
|
|
810 * @return the global border style
|
|
811 */
|
|
812 public int getBorderStyle() {
|
|
813 return borderStyle;
|
|
814 }
|
|
815
|
|
816 /**
|
|
817 * Returns the margin required around the children whose border is being
|
|
818 * painted by the toolkit using {@link #paintBordersFor(Composite)}. Since
|
|
819 * the border is painted around the controls on the parent, a number of
|
|
820 * pixels needs to be reserved for this border. For windowing systems where
|
|
821 * the native border is used, this margin is 0.
|
|
822 *
|
|
823 * @return the margin in the parent when children have their border painted
|
|
824 * @since 3.3
|
|
825 */
|
|
826 public int getBorderMargin() {
|
|
827 return getBorderStyle() is DWT.BORDER ? 0 : 2;
|
|
828 }
|
|
829
|
|
830 /**
|
|
831 * Sets the border style to be used when creating widgets. The toolkit
|
|
832 * chooses the correct style based on the platform but this value can be
|
|
833 * changed using this method.
|
|
834 *
|
|
835 * @param style
|
|
836 * <code>DWT.BORDER</code> or <code>DWT.NULL</code>
|
|
837 * @see #getBorderStyle
|
|
838 */
|
|
839 public void setBorderStyle(int style) {
|
|
840 this.borderStyle = style;
|
|
841 }
|
|
842
|
|
843 /**
|
|
844 * A utility method that ensures that the control is visible in the scrolled
|
|
845 * composite. The prerequisite for this method is that the control has a
|
|
846 * class that extends ScrolledComposite somewhere in the parent chain. If
|
|
847 * the control is partially or fully clipped, the composite is scrolled to
|
|
848 * set by setting the origin to the control origin.
|
|
849 *
|
|
850 * @param c
|
|
851 * the control to make visible
|
|
852 * @param verticalOnly
|
|
853 * if <code>true</code>, the scrolled composite will be
|
|
854 * scrolled only vertically if needed. Otherwise, the scrolled
|
|
855 * composite origin will be set to the control origin.
|
|
856 * @since 3.1
|
|
857 */
|
|
858 public static void setControlVisible(Control c, bool verticalOnly) {
|
|
859 ScrolledComposite scomp = FormUtil.getScrolledComposite(c);
|
|
860 if (scomp is null)
|
|
861 return;
|
|
862 Point location = FormUtil.getControlLocation(scomp, c);
|
|
863 scomp.setOrigin(location);
|
|
864 }
|
|
865
|
|
866 private void initialize() {
|
|
867 initializeBorderStyle();
|
|
868 hyperlinkGroup = new HyperlinkGroup(colors.getDisplay());
|
|
869 hyperlinkGroup.setBackground(colors.getBackground());
|
|
870 visibilityHandler = new VisibilityHandler();
|
|
871 keyboardHandler = new KeyboardHandler();
|
|
872 boldFontHolder = new BoldFontHolder();
|
|
873 }
|
|
874
|
|
875 private void initializeBorderStyle() {
|
|
876 String osname = System.getProperty("os.name"); //$NON-NLS-1$
|
|
877 String osversion = System.getProperty("os.version"); //$NON-NLS-1$
|
|
878 if (osname.startsWith("Windows") && "5.1".compareTo(osversion) <= 0) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
879 // Skinned widgets used on newer Windows (e.g. XP (5.1), Vista
|
|
880 // (6.0))
|
|
881 // Check for Windows Classic. If not used, set the style to BORDER
|
|
882 RGB rgb = colors.getSystemColor(DWT.COLOR_WIDGET_BACKGROUND);
|
|
883 if (rgb.red !is 212 || rgb.green !is 208 || rgb.blue !is 200)
|
|
884 borderStyle = DWT.BORDER;
|
|
885 } else if (osname.startsWith("Mac")) //$NON-NLS-1$
|
|
886 borderStyle = DWT.BORDER;
|
|
887 }
|
|
888
|
|
889 /**
|
|
890 * Returns the orientation that all the widgets created by this toolkit will
|
|
891 * inherit, if set. Can be <code>DWT.NULL</code>,
|
|
892 * <code>DWT.LEFT_TO_RIGHT</code> and <code>DWT.RIGHT_TO_LEFT</code>.
|
|
893 *
|
|
894 * @return orientation style for this toolkit, or <code>DWT.NULL</code> if
|
|
895 * not set. The default orientation is inherited from the Window
|
|
896 * default orientation.
|
|
897 * @see dwtx.jface.window.Window#getDefaultOrientation()
|
|
898 * @since 3.1
|
|
899 */
|
|
900
|
|
901 public int getOrientation() {
|
|
902 return orientation;
|
|
903 }
|
|
904
|
|
905 /**
|
|
906 * Sets the orientation that all the widgets created by this toolkit will
|
|
907 * inherit. Can be <code>DWT.NULL</code>, <code>DWT.LEFT_TO_RIGHT</code>
|
|
908 * and <code>DWT.RIGHT_TO_LEFT</code>.
|
|
909 *
|
|
910 * @param orientation
|
|
911 * style for this toolkit.
|
|
912 * @since 3.1
|
|
913 */
|
|
914
|
|
915 public void setOrientation(int orientation) {
|
|
916 this.orientation = orientation;
|
|
917 }
|
|
918 }
|