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