001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.forms.widgets;
011:
012: import org.eclipse.jface.action.IToolBarManager;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.graphics.Color;
015: import org.eclipse.swt.graphics.Image;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.swt.widgets.Menu;
019: import org.eclipse.ui.forms.IMessage;
020:
021: /**
022: * ScrolledForm is a control that is capable of scrolling an instance of the
023: * Form class. It should be created in a parent that will allow it to use all
024: * the available area (for example, a shell, a view or an editor).
025: * <p>
026: * Children of the form should typically be created using FormToolkit to match
027: * the appearance and behaviour. When creating children, use a form body as a
028: * parent by calling 'getBody()' on the form instance. Example:
029: *
030: * <pre>
031: * FormToolkit toolkit = new FormToolkit(parent.getDisplay());
032: * ScrolledForm form = toolkit.createScrolledForm(parent);
033: * form.setText("Sample form");
034: * form.getBody().setLayout(new GridLayout());
035: * toolkit.createButton(form.getBody(), "Checkbox", SWT.CHECK);
036: * </pre>
037: *
038: * <p>
039: * No layout manager has been set on the body. Clients are required to set the
040: * desired layout manager explicitly.
041: * <p>
042: * Although the class is not final, it is not expected to be be extended.
043: *
044: * @since 3.0
045: */
046: public class ScrolledForm extends SharedScrolledComposite {
047: private Form content;
048:
049: public ScrolledForm(Composite parent) {
050: this (parent, SWT.V_SCROLL | SWT.H_SCROLL);
051: }
052:
053: /**
054: * Creates the form control as a child of the provided parent.
055: *
056: * @param parent
057: * the parent widget
058: */
059: public ScrolledForm(Composite parent, int style) {
060: super (parent, style);
061: super .setMenu(parent.getMenu());
062: content = new Form(this , SWT.NULL);
063: super .setContent(content);
064: content.setMenu(getMenu());
065: }
066:
067: /**
068: * Passes the menu to the body.
069: *
070: * @param menu
071: */
072: public void setMenu(Menu menu) {
073: super .setMenu(menu);
074: if (content != null)
075: content.setMenu(menu);
076: }
077:
078: /**
079: * Returns the title text that will be rendered at the top of the form.
080: *
081: * @return the title text
082: */
083: public String getText() {
084: return content.getText();
085: }
086:
087: /**
088: * Returns the title image that will be rendered to the left of the title.
089: *
090: * @return the title image
091: */
092: public Image getImage() {
093: return content.getImage();
094: }
095:
096: /**
097: * Sets the foreground color of the form. This color will also be used for
098: * the body.
099: */
100: public void setForeground(Color fg) {
101: super .setForeground(fg);
102: content.setForeground(fg);
103: }
104:
105: /**
106: * Sets the background color of the form. This color will also be used for
107: * the body.
108: */
109: public void setBackground(Color bg) {
110: super .setBackground(bg);
111: content.setBackground(bg);
112: }
113:
114: /**
115: * The form sets the content widget. This method should not be called by
116: * classes that instantiate this widget.
117: */
118: public final void setContent(Control c) {
119: }
120:
121: /**
122: * Sets the text to be rendered at the top of the form above the body as a
123: * title.
124: * <p>
125: * <strong>Note:</strong> Mnemonics are indicated by an '&' that causes
126: * the next character to be the mnemonic. Mnemonics are not applicable in
127: * the case of the form title but need to be taken into acount due to the
128: * usage of the underlying widget that renders mnemonics in the title area.
129: * The mnemonic indicator character '&' can be escaped by doubling it in
130: * the string, causing a single '&' to be displayed.
131: * </p>
132: *
133: * @param text
134: * the title text
135: */
136: public void setText(String text) {
137: content.setText(text);
138: reflow(true);
139: }
140:
141: /**
142: * Sets the image to be rendered to the left of the title.
143: *
144: * @param image
145: * the title image or <code>null</code> for no image.
146: */
147: public void setImage(Image image) {
148: content.setImage(image);
149: reflow(true);
150: }
151:
152: /**
153: * Returns the optional background image of this form. The image is rendered
154: * starting at the position 0,0 and is painted behind the title.
155: *
156: * @return Returns the background image.
157: */
158: public Image getBackgroundImage() {
159: return content.getBackgroundImage();
160: }
161:
162: /**
163: * Sets the optional background image to be rendered behind the title
164: * starting at the position 0,0.
165: *
166: * @param backgroundImage
167: * The backgroundImage to set.
168: */
169: public void setBackgroundImage(Image backgroundImage) {
170: content.setBackgroundImage(backgroundImage);
171: }
172:
173: /**
174: * Returns the tool bar manager that is used to manage tool items in the
175: * form's title area.
176: *
177: * @return form tool bar manager
178: */
179: public IToolBarManager getToolBarManager() {
180: return content.getToolBarManager();
181: }
182:
183: /**
184: * Updates the local tool bar manager if used. Does nothing if local tool
185: * bar manager has not been created yet.
186: */
187: public void updateToolBar() {
188: content.updateToolBar();
189: }
190:
191: /**
192: * Returns the container that occupies the body of the form (the form area
193: * below the title). Use this container as a parent for the controls that
194: * should be in the form. No layout manager has been set on the form body.
195: *
196: * @return Returns the body of the form.
197: */
198: public Composite getBody() {
199: return content.getBody();
200: }
201:
202: /**
203: * Returns the instance of the form owned by the scrolled form.
204: *
205: * @return the form instance
206: */
207: public Form getForm() {
208: return content;
209: }
210:
211: /**
212: * Sets the form's busy state. Busy form will display 'busy' animation in
213: * the area of the title image.
214: *
215: * @param busy
216: * the form's busy state
217: * @see Form#setBusy(boolean)
218: * @since 3.3
219: */
220:
221: public void setBusy(boolean busy) {
222: content.setBusy(busy);
223: reflow(true);
224: }
225:
226: /**
227: * Sets the optional head client.
228: *
229: * @param headClient
230: * the optional child of the head
231: * @see Form#setHeadClient(Control)
232: * @since 3.3
233: */
234: public void setHeadClient(Control headClient) {
235: content.setHeadClient(headClient);
236: reflow(true);
237: }
238:
239: /**
240: * Sets the form message.
241: *
242: * @param newMessage
243: * the message text or <code>null</code> to reset.
244: * @param newType
245: * as defined in
246: * {@link org.eclipse.jface.dialogs.IMessageProvider}.
247: * @param messages
248: * an optional array of children that itemize individual
249: * messages or <code>null</code> for a simple message.
250: * @since 3.3
251: * @see Form#setMessage(String, int)
252: */
253: public void setMessage(String newMessage, int newType,
254: 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 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 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: }
|