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
.apache
.log4j
.Logger
;
13 import org
.eclipse
.swt
.events
.FocusEvent
;
14 import org
.eclipse
.swt
.events
.FocusListener
;
15 import org
.eclipse
.swt
.graphics
.Color
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.ui
.forms
.IManagedForm
;
18 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
19 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
22 * Draws a border on a Composite on an IManagedForm when it gets focus,
23 * undraws it when the Composite loses focus.
28 public class CompositeBorderDecorator
implements FocusListener
{
29 private static final Logger logger
= Logger
.getLogger(CompositeBorderDecorator
.class);
31 private FormToolkit toolkit
;
32 private ScrolledForm scrolledForm
;
33 private Composite borderedComposite
;
36 * If true, the <code>borderedComposite</code>'s border is erased when
39 private boolean doLoseFocus
= true;
41 public CompositeBorderDecorator(Composite composite
, IManagedForm form
) {
43 this.borderedComposite
= composite
;
44 this.toolkit
= form
.getToolkit();
45 this.scrolledForm
= form
.getForm();
47 // Make sure composite retains its color scheme after being adapted to toolkit
48 Color backgroundColor
= composite
.getBackground();
50 toolkit
.adapt(composite
);
52 composite
.setBackground(backgroundColor
);
57 public void focusGained(FocusEvent e
) {
62 public void focusLost(FocusEvent e
) {
68 public void setBorderedComposite(Composite borderedComposite
) {
69 this.borderedComposite
= borderedComposite
;
73 * If this is set to true, border will disappear when focus is lost.
74 * Otherwise, it will remain until explicitly erased.
78 public void setLoseFocus(boolean doLoseFocus
) {
79 this.doLoseFocus
= doLoseFocus
;
83 * Removes the border from <code>borderedComposite</code>.
85 public void unpaintBorder() {
90 * Adds a border to <code>borderedComposite</code>.
92 public void paintBorder() {
93 paintBorder(FormToolkit
.TEXT_BORDER
);
96 private void paintBorder(String border
) {
97 borderedComposite
.setData(FormToolkit
.KEY_DRAW_BORDER
, border
);
98 toolkit
.paintBordersFor(borderedComposite
.getParent());
99 scrolledForm
.reflow(false);