2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
;
12 import org
.eclipse
.swt
.events
.FocusEvent
;
13 import org
.eclipse
.swt
.events
.FocusListener
;
14 import org
.eclipse
.swt
.graphics
.Color
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.ui
.forms
.IManagedForm
;
17 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
18 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
21 * Draws a border on a Composite on an IManagedForm when it gets focus,
22 * undraws it when the Composite loses focus.
27 public class CompositeBorderDecorator
implements FocusListener
{
29 private FormToolkit toolkit
;
30 private ScrolledForm scrolledForm
;
31 private Composite borderedComposite
;
34 * If true, the <code>borderedComposite</code>'s border is erased when
37 private boolean doLoseFocus
= true;
39 public CompositeBorderDecorator(Composite composite
, IManagedForm form
) {
41 this.borderedComposite
= composite
;
42 this.toolkit
= form
.getToolkit();
43 this.scrolledForm
= form
.getForm();
45 // Make sure composite retains its color scheme after being adapted to toolkit
46 Color backgroundColor
= composite
.getBackground();
48 toolkit
.adapt(composite
);
50 composite
.setBackground(backgroundColor
);
55 public void focusGained(FocusEvent e
) {
60 public void focusLost(FocusEvent e
) {
66 public void setBorderedComposite(Composite borderedComposite
) {
67 this.borderedComposite
= borderedComposite
;
71 * If this is set to true, border will disappear when focus is lost.
72 * Otherwise, it will remain until explicitly erased.
76 public void setLoseFocus(boolean doLoseFocus
) {
77 this.doLoseFocus
= doLoseFocus
;
81 * Removes the border from <code>borderedComposite</code>.
83 public void unpaintBorder() {
88 * Adds a border to <code>borderedComposite</code>.
90 public void paintBorder() {
91 paintBorder(FormToolkit
.TEXT_BORDER
);
94 private void paintBorder(String border
) {
95 borderedComposite
.setData(FormToolkit
.KEY_DRAW_BORDER
, border
);
96 toolkit
.paintBordersFor(borderedComposite
.getParent());
97 scrolledForm
.reflow(false);