comparison org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/ScrolledForm.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.ui.forms.widgets.ScrolledForm;
14
15 import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
16 import org.eclipse.ui.forms.widgets.Form;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.graphics.Color;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Menu;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.ui.forms.IMessage;
26
27 import java.lang.all;
28 import java.util.Set;
29
30 /**
31 * ScrolledForm is a control that is capable of scrolling an instance of the
32 * Form class. It should be created in a parent that will allow it to use all
33 * the available area (for example, a shell, a view or an editor).
34 * <p>
35 * Children of the form should typically be created using FormToolkit to match
36 * the appearance and behaviour. When creating children, use a form body as a
37 * parent by calling 'getBody()' on the form instance. Example:
38 *
39 * <pre>
40 * FormToolkit toolkit = new FormToolkit(parent.getDisplay());
41 * ScrolledForm form = toolkit.createScrolledForm(parent);
42 * form.setText(&quot;Sample form&quot;);
43 * form.getBody().setLayout(new GridLayout());
44 * toolkit.createButton(form.getBody(), &quot;Checkbox&quot;, SWT.CHECK);
45 * </pre>
46 *
47 * <p>
48 * No layout manager has been set on the body. Clients are required to set the
49 * desired layout manager explicitly.
50 * <p>
51 * Although the class is not final, it is not expected to be be extended.
52 *
53 * @since 3.0
54 * @noextend This class is not intended to be subclassed by clients.
55 */
56 public class ScrolledForm : SharedScrolledComposite {
57 private Form content;
58
59 public this(Composite parent) {
60 this(parent, SWT.V_SCROLL | SWT.H_SCROLL);
61 }
62
63 /**
64 * Creates the form control as a child of the provided parent.
65 *
66 * @param parent
67 * the parent widget
68 */
69 public this(Composite parent, int style) {
70 super(parent, style);
71 super.setMenu(parent.getMenu());
72 content = new Form(this, SWT.NULL);
73 super.setContent(content);
74 content.setMenu(getMenu());
75 }
76
77 /**
78 * Passes the menu to the body.
79 *
80 * @param menu
81 */
82 public void setMenu(Menu menu) {
83 super.setMenu(menu);
84 if (content !is null)
85 content.setMenu(menu);
86 }
87
88 /**
89 * Returns the title text that will be rendered at the top of the form.
90 *
91 * @return the title text
92 */
93 public String getText() {
94 return content.getText();
95 }
96
97 /**
98 * Returns the title image that will be rendered to the left of the title.
99 *
100 * @return the title image
101 */
102 public Image getImage() {
103 return content.getImage();
104 }
105
106 /**
107 * Sets the foreground color of the form. This color will also be used for
108 * the body.
109 */
110 public void setForeground(Color fg) {
111 super.setForeground(fg);
112 content.setForeground(fg);
113 }
114
115 /**
116 * Sets the background color of the form. This color will also be used for
117 * the body.
118 */
119 public void setBackground(Color bg) {
120 super.setBackground(bg);
121 content.setBackground(bg);
122 }
123
124 /**
125 * The form sets the content widget. This method should not be called by
126 * classes that instantiate this widget.
127 */
128 public final void setContent(Control c) {
129 }
130
131 /**
132 * Sets the text to be rendered at the top of the form above the body as a
133 * title.
134 * <p>
135 * <strong>Note:</strong> Mnemonics are indicated by an '&amp;' that causes
136 * the next character to be the mnemonic. Mnemonics are not applicable in
137 * the case of the form title but need to be taken into acount due to the
138 * usage of the underlying widget that renders mnemonics in the title area.
139 * The mnemonic indicator character '&amp;' can be escaped by doubling it in
140 * the string, causing a single '&amp;' to be displayed.
141 * </p>
142 *
143 * @param text
144 * the title text
145 */
146 public void setText(String text) {
147 content.setText(text);
148 reflow(true);
149 }
150
151 /**
152 * Sets the image to be rendered to the left of the title.
153 *
154 * @param image
155 * the title image or <code>null</code> for no image.
156 */
157 public void setImage(Image image) {
158 content.setImage(image);
159 reflow(true);
160 }
161
162 /**
163 * Returns the optional background image of this form. The image is rendered
164 * starting at the position 0,0 and is painted behind the title.
165 *
166 * @return Returns the background image.
167 */
168 public Image getBackgroundImage() {
169 return content.getBackgroundImage();
170 }
171
172 /**
173 * Sets the optional background image to be rendered behind the title
174 * starting at the position 0,0.
175 *
176 * @param backgroundImage
177 * The backgroundImage to set.
178 */
179 public void setBackgroundImage(Image backgroundImage) {
180 content.setBackgroundImage(backgroundImage);
181 }
182
183 /**
184 * Returns the tool bar manager that is used to manage tool items in the
185 * form's title area.
186 *
187 * @return form tool bar manager
188 */
189 public IToolBarManager getToolBarManager() {
190 return content.getToolBarManager();
191 }
192
193 /**
194 * Updates the local tool bar manager if used. Does nothing if local tool
195 * bar manager has not been created yet.
196 */
197 public void updateToolBar() {
198 content.updateToolBar();
199 }
200
201 /**
202 * Returns the container that occupies the body of the form (the form area
203 * below the title). Use this container as a parent for the controls that
204 * should be in the form. No layout manager has been set on the form body.
205 *
206 * @return Returns the body of the form.
207 */
208 public Composite getBody() {
209 return content.getBody();
210 }
211
212 /**
213 * Returns the instance of the form owned by the scrolled form.
214 *
215 * @return the form instance
216 */
217 public Form getForm() {
218 return content;
219 }
220
221 /**
222 * Sets the form's busy state. Busy form will display 'busy' animation in
223 * the area of the title image.
224 *
225 * @param busy
226 * the form's busy state
227 * @see Form#setBusy(bool)
228 * @since 3.3
229 */
230
231 public void setBusy(bool busy) {
232 content.setBusy(busy);
233 reflow(true);
234 }
235
236 /**
237 * Sets the optional head client.
238 *
239 * @param headClient
240 * the optional child of the head
241 * @see Form#setHeadClient(Control)
242 * @since 3.3
243 */
244 public void setHeadClient(Control headClient) {
245 content.setHeadClient(headClient);
246 reflow(true);
247 }
248
249 /**
250 * Sets the form message.
251 *
252 * @param newMessage
253 * the message text or <code>null</code> to reset.
254 * @param newType
255 * as defined in
256 * {@link org.eclipse.jface.dialogs.IMessageProvider}.
257 * @param messages
258 * an optional array of children that itemize individual
259 * messages or <code>null</code> for a simple message.
260 * @since 3.3
261 * @see Form#setMessage(String, int)
262 */
263 public void setMessage(String newMessage, int newType, IMessage[] messages) {
264 content.setMessage(newMessage, newType, messages);
265 reflow(true);
266 }
267
268 /*
269 * (non-Javadoc)
270 *
271 * @see org.eclipse.ui.forms.IMessageContainer#setMessage(java.lang.String,
272 * int)
273 */
274 public void setMessage(String newMessage, int newType) {
275 this.setMessage(newMessage, newType, null);
276 }
277
278 /*
279 * (non-Javadoc)
280 *
281 * @see org.eclipse.jface.dialogs.IMessageProvider#getMessage()
282 */
283 public String getMessage() {
284 return content.getMessage();
285 }
286
287 /*
288 * (non-Javadoc)
289 *
290 * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
291 */
292 public int getMessageType() {
293 return content.getMessageType();
294 }
295 }