Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a1a537f70d6dc4abc8039094aa8c45ed16ee944 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*******************************************************************************
 * Copyright (c) 2000, 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/


package org.eclipse.ui.texteditor;


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;


/**
 * A form consisting of a title, a banner, and an info text. Banner and info text are
 * separated by a separator line. This form must be handled like an SWT widget.
 *
 * @since 2.0
 * @deprecated since 3.0. there is no replacement, use org.eclipse.ui.forms to define a component with a similar look and function.
 */
@Deprecated
public class InfoForm {

	/** The form's root widget */
	private ScrolledComposite fScrolledComposite;
	/** The background color */
	private Color fBackgroundColor;
	/** The foreground color */
	private Color fForegroundColor;
	/** The separator's color */
	private Color fSeparatorColor;
	/** The form header */
	private Label fHeader;
	/** The form banner */
	private Label fBanner;
	/** The form text */
	private StyledText fText;
	/** The preference change listener */
	private IPropertyChangeListener fPropertyChangeListener;

	/**
	 * Creates a new info form.
	 * @param parent the parent composite
	 */
	public InfoForm(Composite parent) {

		Display display= parent.getDisplay();
		fBackgroundColor= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
		fForegroundColor= display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
		fSeparatorColor= new Color(display, 152, 170, 203);

		fPropertyChangeListener = event -> handlePropertyChange(event);
		JFaceResources.getFontRegistry().addListener(fPropertyChangeListener);

		fScrolledComposite= new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
		fScrolledComposite.setAlwaysShowScrollBars(false);
		fScrolledComposite.setExpandHorizontal(true);
		fScrolledComposite.setExpandVertical(true);
		fScrolledComposite.addDisposeListener(e -> {
			JFaceResources.getFontRegistry().removeListener(fPropertyChangeListener);
			fScrolledComposite = null;
			fSeparatorColor.dispose();
			fSeparatorColor = null;
			fHeader = null;
			fBanner = null;
			fText = null;
		});

		Composite composite= createComposite(fScrolledComposite);
		composite.setLayout(new GridLayout());

		fHeader= createHeader(composite, null);
		createLabel(composite, null);
		createLabel(composite, null);

		fBanner= createBanner(composite, null);

		Composite separator= createCompositeSeparator(composite);
		GridData data= new GridData(GridData.FILL_HORIZONTAL);
		data.heightHint= 2;
		separator.setLayoutData(data);

		fText= createText(composite, null);
		createLabel(composite, null);

		fScrolledComposite.setContent(composite);
		fScrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

		createActionControls(composite);
	}

	/**
	 * Hook method for creating an appropriate action control.
	 * @param parent the action control's parent control
	 */
	protected void createActionControls(Composite parent) {
	}

	/**
	 * Returns the control of this form.
	 * @return the root control of this form
	 */
	public Control getControl() {
		return fScrolledComposite;
	}

	/**
	 * Sets the header text of this info form.
	 * @param header the header text
	 */
	public void setHeaderText(String header) {
		fHeader.setText(header);
	}

	/**
	 * Sets the banner text of this info form.
	 * @param banner the banner text
	 */
	public void setBannerText(String banner) {
		fBanner.setText(banner);
	}

	/**
	 * Sets the info of this info form
	 * @param info the info text
	 */
	public void setInfo(String info) {
		fText.setText(info);
	}

    /**
	 * Handles the property change.
	 *
	 * @param event the property change event object describing which property changed and how
	 */
	protected void handlePropertyChange(PropertyChangeEvent event) {

		if (fHeader != null)
			fHeader.setFont(JFaceResources.getHeaderFont());

		if (fBanner != null)
			fBanner.setFont(JFaceResources.getBannerFont());

		Control control= fScrolledComposite.getContent();
		fScrolledComposite.setMinSize(control.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		fScrolledComposite.setContent(control);

		fScrolledComposite.layout(true);
		fScrolledComposite.redraw();
	}

	/*
	 * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createComposite(Composite)
	 */
	private Composite createComposite(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setBackground(fBackgroundColor);
		return composite;
	}

	/*
	 * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createCompositeSeparator(Composite)
	 */
	private Composite createCompositeSeparator(Composite parent) {
		Composite composite = new Composite(parent, SWT.NO_FOCUS);
		composite.setBackground(fSeparatorColor);
		return composite;
	}

	/*
	 * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createLabel(Composite, String)
	 */
	private Label createLabel(Composite parent, String text) {
		Label label = new Label(parent, SWT.NONE);
		GridData data= new GridData(GridData.FILL_HORIZONTAL);
		label.setLayoutData(data);

		if (text != null)
			label.setText(text);
		label.setBackground(fBackgroundColor);
		label.setForeground(fForegroundColor);
		return label;
	}

	private StyledText createText(Composite parent, String text) {
		StyledText widget = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI);
		GridData data= new GridData(GridData.FILL_HORIZONTAL);
		widget.setLayoutData(data);

		if (text != null)
			widget.setText(text);
		widget.setBackground(fBackgroundColor);
		widget.setForeground(fForegroundColor);
		widget.setCaret(null);
		return widget;
	}

	/*
	 * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createHeader(Composite, String)
	 */
	private Label createHeader(Composite parent, String text) {
		Label label = new Label(parent, SWT.NONE);
		GridData data= new GridData(GridData.FILL_HORIZONTAL);
		label.setLayoutData(data);

		if (text != null)
			label.setText(text);
		label.setBackground(fBackgroundColor);
		label.setForeground(fForegroundColor);
		label.setFont(JFaceResources.getHeaderFont());
		return label;
	}

	/*
	 * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createBanner(Composite, String)
	 */
	private Label createBanner(Composite parent, String text) {
		Label label = new Label(parent, SWT.NONE);
		if (text != null)
			label.setText(text);
		label.setBackground(fBackgroundColor);
		label.setForeground(fForegroundColor);
		label.setFont(JFaceResources.getBannerFont());
		return label;
	}
}

Back to the top