comparison examples/controlexample/SpinnerTab.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children eb84f9418bbf
comparison
equal deleted inserted replaced
76:04f122e90b0a 78:4a04b6759f98
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 examples.controlexample.SpinnerTab;
14
15
16
17 import dwt.DWT;
18 import dwt.events.ControlAdapter;
19 import dwt.events.ControlEvent;
20 import dwt.events.SelectionAdapter;
21 import dwt.events.SelectionEvent;
22 import dwt.layout.GridData;
23 import dwt.layout.GridLayout;
24 import dwt.widgets.Button;
25 import dwt.widgets.Composite;
26 import dwt.widgets.Group;
27 import dwt.widgets.Spinner;
28 import dwt.widgets.TabFolder;
29 import dwt.widgets.Widget;
30
31 import examples.controlexample.Tab;
32 import examples.controlexample.ControlExample;
33 import examples.controlexample.RangeTab;
34
35 class SpinnerTab : RangeTab {
36
37 /* Example widgets and groups that contain them */
38 Spinner spinner1;
39 Group spinnerGroup;
40
41 /* Style widgets added to the "Style" group */
42 Button readOnlyButton, wrapButton;
43
44 /* Spinner widgets added to the "Control" group */
45 Spinner incrementSpinner, pageIncrementSpinner, digitsSpinner;
46
47 /**
48 * Creates the Tab within a given instance of ControlExample.
49 */
50 this(ControlExample instance) {
51 super(instance);
52 }
53
54 /**
55 * Creates the "Control" widget children.
56 */
57 void createControlWidgets () {
58 super.createControlWidgets ();
59 createIncrementGroup ();
60 createPageIncrementGroup ();
61 createDigitsGroup ();
62 }
63
64 /**
65 * Creates the "Example" group.
66 */
67 void createExampleGroup () {
68 super.createExampleGroup ();
69
70 /* Create a group for the spinner */
71 spinnerGroup = new Group (exampleGroup, DWT.NONE);
72 spinnerGroup.setLayout (new GridLayout ());
73 spinnerGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
74 spinnerGroup.setText ("Spinner");
75 }
76
77 /**
78 * Creates the "Example" widgets.
79 */
80 void createExampleWidgets () {
81
82 /* Compute the widget style */
83 int style = getDefaultStyle();
84 if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY;
85 if (borderButton.getSelection ()) style |= DWT.BORDER;
86 if (wrapButton.getSelection ()) style |= DWT.WRAP;
87
88 /* Create the example widgets */
89 spinner1 = new Spinner (spinnerGroup, style);
90 }
91
92 /**
93 * Create a group of widgets to control the increment
94 * attribute of the example widget.
95 */
96 void createIncrementGroup() {
97
98 /* Create the group */
99 Group incrementGroup = new Group (controlGroup, DWT.NONE);
100 incrementGroup.setLayout (new GridLayout ());
101 incrementGroup.setText (ControlExample.getResourceString("Increment"));
102 incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
103
104 /* Create the Spinner widget */
105 incrementSpinner = new Spinner (incrementGroup, DWT.BORDER);
106 incrementSpinner.setMaximum (100000);
107 incrementSpinner.setSelection (getDefaultIncrement());
108 incrementSpinner.setPageIncrement (100);
109 incrementSpinner.setIncrement (1);
110 incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
111
112 /* Add the listeners */
113 incrementSpinner.addSelectionListener (new class() SelectionAdapter {
114 public void widgetSelected (SelectionEvent e) {
115 setWidgetIncrement ();
116 }
117 });
118 }
119
120 /**
121 * Create a group of widgets to control the page increment
122 * attribute of the example widget.
123 */
124 void createPageIncrementGroup() {
125
126 /* Create the group */
127 Group pageIncrementGroup = new Group (controlGroup, DWT.NONE);
128 pageIncrementGroup.setLayout (new GridLayout ());
129 pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment"));
130 pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
131
132 /* Create the Spinner widget */
133 pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER);
134 pageIncrementSpinner.setMaximum (100000);
135 pageIncrementSpinner.setSelection (getDefaultPageIncrement());
136 pageIncrementSpinner.setPageIncrement (100);
137 pageIncrementSpinner.setIncrement (1);
138 pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
139
140 /* Add the listeners */
141 pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter {
142 public void widgetSelected (SelectionEvent event) {
143 setWidgetPageIncrement ();
144 }
145 });
146 }
147
148 /**
149 * Create a group of widgets to control the digits
150 * attribute of the example widget.
151 */
152 void createDigitsGroup() {
153
154 /* Create the group */
155 Group digitsGroup = new Group (controlGroup, DWT.NONE);
156 digitsGroup.setLayout (new GridLayout ());
157 digitsGroup.setText (ControlExample.getResourceString("Digits"));
158 digitsGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
159
160 /* Create the Spinner widget */
161 digitsSpinner = new Spinner (digitsGroup, DWT.BORDER);
162 digitsSpinner.setMaximum (100000);
163 digitsSpinner.setSelection (getDefaultDigits());
164 digitsSpinner.setPageIncrement (100);
165 digitsSpinner.setIncrement (1);
166 digitsSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
167
168 /* Add the listeners */
169 digitsSpinner.addSelectionListener (new class() SelectionAdapter {
170 public void widgetSelected (SelectionEvent e) {
171 setWidgetDigits ();
172 }
173 });
174 }
175
176 /**
177 * Creates the tab folder page.
178 *
179 * @param tabFolder org.eclipse.swt.widgets.TabFolder
180 * @return the new page for the tab folder
181 */
182 Composite createTabFolderPage (TabFolder tabFolder) {
183 super.createTabFolderPage (tabFolder);
184
185 /*
186 * Add a resize listener to the tabFolderPage so that
187 * if the user types into the example widget to change
188 * its preferred size, and then resizes the shell, we
189 * recalculate the preferred size correctly.
190 */
191 tabFolderPage.addControlListener(new class() ControlAdapter {
192 public void controlResized(ControlEvent e) {
193 setExampleWidgetSize ();
194 }
195 });
196
197 return tabFolderPage;
198 }
199
200 /**
201 * Creates the "Style" group.
202 */
203 void createStyleGroup () {
204 orientationButtons = false;
205 super.createStyleGroup ();
206
207 /* Create the extra widgets */
208 readOnlyButton = new Button (styleGroup, DWT.CHECK);
209 readOnlyButton.setText ("DWT.READ_ONLY");
210 wrapButton = new Button (styleGroup, DWT.CHECK);
211 wrapButton.setText ("DWT.WRAP");
212 }
213
214 /**
215 * Gets the "Example" widget children.
216 */
217 Widget [] getExampleWidgets () {
218 return [ cast(Widget) spinner1 ];
219 }
220
221 /**
222 * Returns a list of set/get API method names (without the set/get prefix)
223 * that can be used to set/get values in the example control(s).
224 */
225 char[][] getMethodNames() {
226 return ["Selection", "ToolTipText"];
227 }
228
229 /**
230 * Gets the text for the tab folder item.
231 */
232 char[] getTabText () {
233 return "Spinner";
234 }
235
236 /**
237 * Sets the state of the "Example" widgets.
238 */
239 void setExampleWidgetState () {
240 super.setExampleWidgetState ();
241 readOnlyButton.setSelection ((spinner1.getStyle () & DWT.READ_ONLY) !is 0);
242 wrapButton.setSelection ((spinner1.getStyle () & DWT.WRAP) !is 0);
243 if (!instance.startup) {
244 setWidgetIncrement ();
245 setWidgetPageIncrement ();
246 setWidgetDigits ();
247 }
248 }
249
250 /**
251 * Gets the default maximum of the "Example" widgets.
252 */
253 int getDefaultMaximum () {
254 return spinner1.getMaximum();
255 }
256
257 /**
258 * Gets the default minimim of the "Example" widgets.
259 */
260 int getDefaultMinimum () {
261 return spinner1.getMinimum();
262 }
263
264 /**
265 * Gets the default selection of the "Example" widgets.
266 */
267 int getDefaultSelection () {
268 return spinner1.getSelection();
269 }
270
271 /**
272 * Gets the default increment of the "Example" widgets.
273 */
274 int getDefaultIncrement () {
275 return spinner1.getIncrement();
276 }
277
278 /**
279 * Gets the default page increment of the "Example" widgets.
280 */
281 int getDefaultPageIncrement () {
282 return spinner1.getPageIncrement();
283 }
284
285 /**
286 * Gets the default digits of the "Example" widgets.
287 */
288 int getDefaultDigits () {
289 return spinner1.getDigits();
290 }
291
292 /**
293 * Sets the increment of the "Example" widgets.
294 */
295 void setWidgetIncrement () {
296 spinner1.setIncrement (incrementSpinner.getSelection ());
297 }
298
299 /**
300 * Sets the minimim of the "Example" widgets.
301 */
302 void setWidgetMaximum () {
303 spinner1.setMaximum (maximumSpinner.getSelection ());
304 }
305
306 /**
307 * Sets the minimim of the "Example" widgets.
308 */
309 void setWidgetMinimum () {
310 spinner1.setMinimum (minimumSpinner.getSelection ());
311 }
312
313 /**
314 * Sets the page increment of the "Example" widgets.
315 */
316 void setWidgetPageIncrement () {
317 spinner1.setPageIncrement (pageIncrementSpinner.getSelection ());
318 }
319
320 /**
321 * Sets the digits of the "Example" widgets.
322 */
323 void setWidgetDigits () {
324 spinner1.setDigits (digitsSpinner.getSelection ());
325 }
326
327 /**
328 * Sets the selection of the "Example" widgets.
329 */
330 void setWidgetSelection () {
331 spinner1.setSelection (selectionSpinner.getSelection ());
332 }
333 }