KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > widgets > ScrolledForm


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 package org.eclipse.ui.forms.widgets;
12
13 import org.eclipse.jface.action.IToolBarManager;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Menu;
20 import org.eclipse.ui.forms.IMessage;
21
22 /**
23  * ScrolledForm is a control that is capable of scrolling an instance of the
24  * Form class. It should be created in a parent that will allow it to use all
25  * the available area (for example, a shell, a view or an editor).
26  * <p>
27  * Children of the form should typically be created using FormToolkit to match
28  * the appearance and behaviour. When creating children, use a form body as a
29  * parent by calling 'getBody()' on the form instance. Example:
30  *
31  * <pre>
32  * FormToolkit toolkit = new FormToolkit(parent.getDisplay());
33  * ScrolledForm form = toolkit.createScrolledForm(parent);
34  * form.setText(&quot;Sample form&quot;);
35  * form.getBody().setLayout(new GridLayout());
36  * toolkit.createButton(form.getBody(), &quot;Checkbox&quot;, SWT.CHECK);
37  * </pre>
38  *
39  * <p>
40  * No layout manager has been set on the body. Clients are required to set the
41  * desired layout manager explicitly.
42  * <p>
43  * Although the class is not final, it is not expected to be be extended.
44  *
45  * @since 3.0
46  */

47 public class ScrolledForm extends SharedScrolledComposite {
48     private Form content;
49
50     public ScrolledForm(Composite parent) {
51         this(parent, SWT.V_SCROLL | SWT.H_SCROLL);
52     }
53
54     /**
55      * Creates the form control as a child of the provided parent.
56      *
57      * @param parent
58      * the parent widget
59      */

60     public ScrolledForm(Composite parent, int style) {
61         super(parent, style);
62         super.setMenu(parent.getMenu());
63         content = new Form(this, SWT.NULL);
64         super.setContent(content);
65         content.setMenu(getMenu());
66     }
67
68     /**
69      * Passes the menu to the body.
70      *
71      * @param menu
72      */

73     public void setMenu(Menu menu) {
74         super.setMenu(menu);
75         if (content != null)
76             content.setMenu(menu);
77     }
78
79     /**
80      * Returns the title text that will be rendered at the top of the form.
81      *
82      * @return the title text
83      */

84     public String JavaDoc getText() {
85         return content.getText();
86     }
87
88     /**
89      * Returns the title image that will be rendered to the left of the title.
90      *
91      * @return the title image
92      */

93     public Image getImage() {
94         return content.getImage();
95     }
96
97     /**
98      * Sets the foreground color of the form. This color will also be used for
99      * the body.
100      */

101     public void setForeground(Color fg) {
102         super.setForeground(fg);
103         content.setForeground(fg);
104     }
105
106     /**
107      * Sets the background color of the form. This color will also be used for
108      * the body.
109      */

110     public void setBackground(Color bg) {
111         super.setBackground(bg);
112         content.setBackground(bg);
113     }
114
115     /**
116      * The form sets the content widget. This method should not be called by
117      * classes that instantiate this widget.
118      */

119     public final void setContent(Control c) {
120     }
121
122     /**
123      * Sets the text to be rendered at the top of the form above the body as a
124      * title.
125      * <p>
126      * <strong>Note:</strong> Mnemonics are indicated by an '&amp;' that causes
127      * the next character to be the mnemonic. Mnemonics are not applicable in
128      * the case of the form title but need to be taken into acount due to the
129      * usage of the underlying widget that renders mnemonics in the title area.
130      * The mnemonic indicator character '&amp;' can be escaped by doubling it in
131      * the string, causing a single '&amp;' to be displayed.
132      * </p>
133      *
134      * @param text
135      * the title text
136      */

137     public void setText(String JavaDoc text) {
138         content.setText(text);
139         reflow(true);
140     }
141
142     /**
143      * Sets the image to be rendered to the left of the title.
144      *
145      * @param image
146      * the title image or <code>null</code> for no image.
147      */

148     public void setImage(Image image) {
149         content.setImage(image);
150         reflow(true);
151     }
152
153     /**
154      * Returns the optional background image of this form. The image is rendered
155      * starting at the position 0,0 and is painted behind the title.
156      *
157      * @return Returns the background image.
158      */

159     public Image getBackgroundImage() {
160         return content.getBackgroundImage();
161     }
162
163     /**
164      * Sets the optional background image to be rendered behind the title
165      * starting at the position 0,0.
166      *
167      * @param backgroundImage
168      * The backgroundImage to set.
169      */

170     public void setBackgroundImage(Image backgroundImage) {
171         content.setBackgroundImage(backgroundImage);
172     }
173
174     /**
175      * Returns the tool bar manager that is used to manage tool items in the
176      * form's title area.
177      *
178      * @return form tool bar manager
179      */

180     public IToolBarManager getToolBarManager() {
181         return content.getToolBarManager();
182     }
183
184     /**
185      * Updates the local tool bar manager if used. Does nothing if local tool
186      * bar manager has not been created yet.
187      */

188     public void updateToolBar() {
189         content.updateToolBar();
190     }
191
192     /**
193      * Returns the container that occupies the body of the form (the form area
194      * below the title). Use this container as a parent for the controls that
195      * should be in the form. No layout manager has been set on the form body.
196      *
197      * @return Returns the body of the form.
198      */

199     public Composite getBody() {
200         return content.getBody();
201     }
202
203     /**
204      * Returns the instance of the form owned by the scrolled form.
205      *
206      * @return the form instance
207      */

208     public Form getForm() {
209         return content;
210     }
211
212     /**
213      * Sets the form's busy state. Busy form will display 'busy' animation in
214      * the area of the title image.
215      *
216      * @param busy
217      * the form's busy state
218      * @see Form#setBusy(boolean)
219      * @since 3.3
220      */

221
222     public void setBusy(boolean busy) {
223         content.setBusy(busy);
224         reflow(true);
225     }
226
227     /**
228      * Sets the optional head client.
229      *
230      * @param headClient
231      * the optional child of the head
232      * @see Form#setHeadClient(Control)
233      * @since 3.3
234      */

235     public void setHeadClient(Control headClient) {
236         content.setHeadClient(headClient);
237         reflow(true);
238     }
239
240     /**
241      * Sets the form message.
242      *
243      * @param newMessage
244      * the message text or <code>null</code> to reset.
245      * @param newType
246      * as defined in
247      * {@link org.eclipse.jface.dialogs.IMessageProvider}.
248      * @param messages
249      * an optional array of children that itemize individual
250      * messages or <code>null</code> for a simple message.
251      * @since 3.3
252      * @see Form#setMessage(String, int)
253      */

254     public void setMessage(String JavaDoc newMessage, int newType, IMessage[] messages) {
255         content.setMessage(newMessage, newType, messages);
256         reflow(true);
257     }
258
259     /*
260      * (non-Javadoc)
261      *
262      * @see org.eclipse.ui.forms.IMessageContainer#setMessage(java.lang.String,
263      * int)
264      */

265     public void setMessage(String JavaDoc newMessage, int newType) {
266         this.setMessage(newMessage, newType, null);
267     }
268
269     /*
270      * (non-Javadoc)
271      *
272      * @see org.eclipse.jface.dialogs.IMessageProvider#getMessage()
273      */

274     public String JavaDoc getMessage() {
275         return content.getMessage();
276     }
277
278     /*
279      * (non-Javadoc)
280      *
281      * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
282      */

283     public int getMessageType() {
284         return content.getMessageType();
285     }
286 }
287
Popular Tags