KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > InfoForm


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

11
12
13 package org.eclipse.ui.texteditor;
14
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.ScrolledComposite;
18 import org.eclipse.swt.events.DisposeEvent;
19 import org.eclipse.swt.events.DisposeListener;
20 import org.eclipse.swt.graphics.Color;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.swt.widgets.Label;
27
28 import org.eclipse.jface.resource.JFaceResources;
29 import org.eclipse.jface.util.IPropertyChangeListener;
30 import org.eclipse.jface.util.PropertyChangeEvent;
31
32
33 /**
34  * A form consisting of a title, a banner, and a info text. Banner and info text are
35  * separated by a separator line. This form must be handled like a SWT widget.
36  *
37  * @since 2.0
38  * @deprecated since 3.0. there is no replacement, use org.eclipse.ui.forms to define a component with a similar look and function.
39  */

40 public class InfoForm {
41
42     /** The form's root widget */
43     private ScrolledComposite fScrolledComposite;
44     /** The background color */
45     private Color fBackgroundColor;
46     /** The foreground color */
47     private Color fForegroundColor;
48     /** The separator's color */
49     private Color fSeparatorColor;
50     /** The form header */
51     private Label fHeader;
52     /** The form banner */
53     private Label fBanner;
54     /** The form text */
55     private Label fText;
56     /** The preference change listener */
57     private IPropertyChangeListener fPropertyChangeListener;
58
59     /**
60      * Creates a new info form.
61      * @param parent the parent composite
62      */

63     public InfoForm(Composite parent) {
64
65         Display display= parent.getDisplay();
66         fBackgroundColor= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
67         fForegroundColor= display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
68         fSeparatorColor= new Color(display, 152, 170, 203);
69
70         fPropertyChangeListener= new IPropertyChangeListener() {
71             public void propertyChange(PropertyChangeEvent event) {
72                 handlePropertyChange(event);
73             }
74         };
75         JFaceResources.getFontRegistry().addListener(fPropertyChangeListener);
76
77         fScrolledComposite= new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
78         fScrolledComposite.setAlwaysShowScrollBars(false);
79         fScrolledComposite.setExpandHorizontal(true);
80         fScrolledComposite.setExpandVertical(true);
81         fScrolledComposite.addDisposeListener(new DisposeListener() {
82             public void widgetDisposed(DisposeEvent e) {
83                 JFaceResources.getFontRegistry().removeListener(fPropertyChangeListener);
84                 fScrolledComposite= null;
85                 fSeparatorColor.dispose();
86                 fSeparatorColor= null;
87                 fHeader= null;
88                 fBanner= null;
89                 fText= null;
90             }
91         });
92
93         Composite composite= createComposite(fScrolledComposite);
94         composite.setLayout(new GridLayout());
95
96         fHeader= createHeader(composite, null);
97         createLabel(composite, null);
98         createLabel(composite, null);
99
100         fBanner= createBanner(composite, null);
101
102         Composite separator= createCompositeSeparator(composite);
103         GridData data= new GridData(GridData.FILL_HORIZONTAL);
104         data.heightHint= 2;
105         separator.setLayoutData(data);
106
107         fText= createLabel(composite, null);
108         createLabel(composite, null);
109
110         fScrolledComposite.setContent(composite);
111         fScrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
112
113         createActionControls(composite);
114     }
115
116     /**
117      * Hook method for creating an appropriate action control.
118      * @param parent the action control's parent control
119      */

120     protected void createActionControls(Composite parent) {
121     }
122
123     /**
124      * Returns the control of this form.
125      * @return the root control of this form
126      */

127     public Control getControl() {
128         return fScrolledComposite;
129     }
130
131     /**
132      * Sets the header text of this info form.
133      * @param header the header text
134      */

135     public void setHeaderText(String JavaDoc header) {
136         fHeader.setText(header);
137     }
138
139     /**
140      * Sets the banner text of this info form.
141      * @param banner the banner text
142      */

143     public void setBannerText(String JavaDoc banner) {
144         fBanner.setText(banner);
145     }
146
147     /**
148      * Sets the info of this info form
149      * @param info the info text
150      */

151     public void setInfo(String JavaDoc info) {
152         fText.setText(info);
153     }
154
155     /*
156      * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
157      */

158     protected void handlePropertyChange(PropertyChangeEvent event) {
159
160         if (fHeader != null)
161             fHeader.setFont(JFaceResources.getHeaderFont());
162
163         if (fBanner != null)
164             fBanner.setFont(JFaceResources.getBannerFont());
165
166         Control control= fScrolledComposite.getContent();
167         fScrolledComposite.setMinSize(control.computeSize(SWT.DEFAULT, SWT.DEFAULT));
168         fScrolledComposite.setContent(control);
169
170         fScrolledComposite.layout(true);
171         fScrolledComposite.redraw();
172     }
173
174     /*
175      * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createComposite(Composite)
176      */

177     private Composite createComposite(Composite parent) {
178         Composite composite = new Composite(parent, SWT.NONE);
179         composite.setBackground(fBackgroundColor);
180         return composite;
181     }
182
183     /*
184      * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createCompositeSeparator(Composite)
185      */

186     private Composite createCompositeSeparator(Composite parent) {
187         Composite composite = new Composite(parent, SWT.NONE);
188         composite.setBackground(fSeparatorColor);
189         return composite;
190     }
191
192     /*
193      * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createLabel(Composite, String)
194      */

195     private Label createLabel(Composite parent, String JavaDoc text) {
196         Label label = new Label(parent, SWT.NONE);
197         GridData data= new GridData(GridData.FILL_HORIZONTAL);
198         label.setLayoutData(data);
199
200         if (text != null)
201             label.setText(text);
202         label.setBackground(fBackgroundColor);
203         label.setForeground(fForegroundColor);
204         return label;
205     }
206
207     /*
208      * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createHeader(Composite, String)
209      */

210     private Label createHeader(Composite parent, String JavaDoc text) {
211         Label label = new Label(parent, SWT.NONE);
212         GridData data= new GridData(GridData.FILL_HORIZONTAL);
213         label.setLayoutData(data);
214
215         if (text != null)
216             label.setText(text);
217         label.setBackground(fBackgroundColor);
218         label.setForeground(fForegroundColor);
219         label.setFont(JFaceResources.getHeaderFont());
220         return label;
221     }
222
223     /*
224      * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createBanner(Composite, String)
225      */

226     private Label createBanner(Composite parent, String JavaDoc text) {
227         Label label = new Label(parent, SWT.NONE);
228         if (text != null)
229             label.setText(text);
230         label.setBackground(fBackgroundColor);
231         label.setForeground(fForegroundColor);
232         label.setFont(JFaceResources.getBannerFont());
233         return label;
234     }
235 }
236
Popular Tags