001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.texteditor;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.custom.ScrolledComposite;
014: import org.eclipse.swt.events.DisposeEvent;
015: import org.eclipse.swt.events.DisposeListener;
016: import org.eclipse.swt.graphics.Color;
017: import org.eclipse.swt.layout.GridData;
018: import org.eclipse.swt.layout.GridLayout;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Control;
021: import org.eclipse.swt.widgets.Display;
022: import org.eclipse.swt.widgets.Label;
023:
024: import org.eclipse.jface.resource.JFaceResources;
025: import org.eclipse.jface.util.IPropertyChangeListener;
026: import org.eclipse.jface.util.PropertyChangeEvent;
027:
028: /**
029: * A form consisting of a title, a banner, and a info text. Banner and info text are
030: * separated by a separator line. This form must be handled like a SWT widget.
031: *
032: * @since 2.0
033: * @deprecated since 3.0. there is no replacement, use org.eclipse.ui.forms to define a component with a similar look and function.
034: */
035: public class InfoForm {
036:
037: /** The form's root widget */
038: private ScrolledComposite fScrolledComposite;
039: /** The background color */
040: private Color fBackgroundColor;
041: /** The foreground color */
042: private Color fForegroundColor;
043: /** The separator's color */
044: private Color fSeparatorColor;
045: /** The form header */
046: private Label fHeader;
047: /** The form banner */
048: private Label fBanner;
049: /** The form text */
050: private Label fText;
051: /** The preference change listener */
052: private IPropertyChangeListener fPropertyChangeListener;
053:
054: /**
055: * Creates a new info form.
056: * @param parent the parent composite
057: */
058: public InfoForm(Composite parent) {
059:
060: Display display = parent.getDisplay();
061: fBackgroundColor = display
062: .getSystemColor(SWT.COLOR_LIST_BACKGROUND);
063: fForegroundColor = display
064: .getSystemColor(SWT.COLOR_LIST_FOREGROUND);
065: fSeparatorColor = new Color(display, 152, 170, 203);
066:
067: fPropertyChangeListener = new IPropertyChangeListener() {
068: public void propertyChange(PropertyChangeEvent event) {
069: handlePropertyChange(event);
070: }
071: };
072: JFaceResources.getFontRegistry().addListener(
073: fPropertyChangeListener);
074:
075: fScrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL
076: | SWT.V_SCROLL);
077: fScrolledComposite.setAlwaysShowScrollBars(false);
078: fScrolledComposite.setExpandHorizontal(true);
079: fScrolledComposite.setExpandVertical(true);
080: fScrolledComposite.addDisposeListener(new DisposeListener() {
081: public void widgetDisposed(DisposeEvent e) {
082: JFaceResources.getFontRegistry().removeListener(
083: fPropertyChangeListener);
084: fScrolledComposite = null;
085: fSeparatorColor.dispose();
086: fSeparatorColor = null;
087: fHeader = null;
088: fBanner = null;
089: fText = null;
090: }
091: });
092:
093: Composite composite = createComposite(fScrolledComposite);
094: composite.setLayout(new GridLayout());
095:
096: fHeader = createHeader(composite, null);
097: createLabel(composite, null);
098: createLabel(composite, null);
099:
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(
112: SWT.DEFAULT, SWT.DEFAULT));
113:
114: createActionControls(composite);
115: }
116:
117: /**
118: * Hook method for creating an appropriate action control.
119: * @param parent the action control's parent control
120: */
121: protected void createActionControls(Composite parent) {
122: }
123:
124: /**
125: * Returns the control of this form.
126: * @return the root control of this form
127: */
128: public Control getControl() {
129: return fScrolledComposite;
130: }
131:
132: /**
133: * Sets the header text of this info form.
134: * @param header the header text
135: */
136: public void setHeaderText(String header) {
137: fHeader.setText(header);
138: }
139:
140: /**
141: * Sets the banner text of this info form.
142: * @param banner the banner text
143: */
144: public void setBannerText(String banner) {
145: fBanner.setText(banner);
146: }
147:
148: /**
149: * Sets the info of this info form
150: * @param info the info text
151: */
152: public void setInfo(String info) {
153: fText.setText(info);
154: }
155:
156: /*
157: * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
158: */
159: protected void handlePropertyChange(PropertyChangeEvent event) {
160:
161: if (fHeader != null)
162: fHeader.setFont(JFaceResources.getHeaderFont());
163:
164: if (fBanner != null)
165: fBanner.setFont(JFaceResources.getBannerFont());
166:
167: Control control = fScrolledComposite.getContent();
168: fScrolledComposite.setMinSize(control.computeSize(SWT.DEFAULT,
169: SWT.DEFAULT));
170: fScrolledComposite.setContent(control);
171:
172: fScrolledComposite.layout(true);
173: fScrolledComposite.redraw();
174: }
175:
176: /*
177: * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createComposite(Composite)
178: */
179: private Composite createComposite(Composite parent) {
180: Composite composite = new Composite(parent, SWT.NONE);
181: composite.setBackground(fBackgroundColor);
182: return composite;
183: }
184:
185: /*
186: * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createCompositeSeparator(Composite)
187: */
188: private Composite createCompositeSeparator(Composite parent) {
189: Composite composite = new Composite(parent, SWT.NONE);
190: composite.setBackground(fSeparatorColor);
191: return composite;
192: }
193:
194: /*
195: * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createLabel(Composite, String)
196: */
197: private Label createLabel(Composite parent, String text) {
198: Label label = new Label(parent, SWT.NONE);
199: GridData data = new GridData(GridData.FILL_HORIZONTAL);
200: label.setLayoutData(data);
201:
202: if (text != null)
203: label.setText(text);
204: label.setBackground(fBackgroundColor);
205: label.setForeground(fForegroundColor);
206: return label;
207: }
208:
209: /*
210: * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createHeader(Composite, String)
211: */
212: private Label createHeader(Composite parent, String text) {
213: Label label = new Label(parent, SWT.NONE);
214: GridData data = new GridData(GridData.FILL_HORIZONTAL);
215: label.setLayoutData(data);
216:
217: if (text != null)
218: label.setText(text);
219: label.setBackground(fBackgroundColor);
220: label.setForeground(fForegroundColor);
221: label.setFont(JFaceResources.getHeaderFont());
222: return label;
223: }
224:
225: /*
226: * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createBanner(Composite, String)
227: */
228: private Label createBanner(Composite parent, String text) {
229: Label label = new Label(parent, SWT.NONE);
230: if (text != null)
231: label.setText(text);
232: label.setBackground(fBackgroundColor);
233: label.setForeground(fForegroundColor);
234: label.setFont(JFaceResources.getBannerFont());
235: return label;
236: }
237: }
|