comparison examples/controlexample/SliderTab.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.SliderTab;
14
15
16
17 import dwt.DWT;
18 import dwt.events.SelectionAdapter;
19 import dwt.events.SelectionEvent;
20 import dwt.layout.GridData;
21 import dwt.layout.GridLayout;
22 import dwt.widgets.Group;
23 import dwt.widgets.Slider;
24 import dwt.widgets.Spinner;
25 import dwt.widgets.Widget;
26
27 import examples.controlexample.Tab;
28 import examples.controlexample.ControlExample;
29 import examples.controlexample.RangeTab;
30
31 class SliderTab : RangeTab {
32 /* Example widgets and groups that contain them */
33 Slider slider1;
34 Group sliderGroup;
35
36 /* Spinner widgets added to the "Control" group */
37 Spinner incrementSpinner, pageIncrementSpinner, thumbSpinner;
38
39 /**
40 * Creates the Tab within a given instance of ControlExample.
41 */
42 this(ControlExample instance) {
43 super(instance);
44 }
45
46 /**
47 * Creates the "Control" widget children.
48 */
49 void createControlWidgets () {
50 super.createControlWidgets ();
51 createThumbGroup ();
52 createIncrementGroup ();
53 createPageIncrementGroup ();
54 }
55
56 /**
57 * Creates the "Example" group.
58 */
59 void createExampleGroup () {
60 super.createExampleGroup ();
61
62 /* Create a group for the slider */
63 sliderGroup = new Group (exampleGroup, DWT.NONE);
64 sliderGroup.setLayout (new GridLayout ());
65 sliderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
66 sliderGroup.setText ("Slider");
67 }
68
69 /**
70 * Creates the "Example" widgets.
71 */
72 void createExampleWidgets () {
73
74 /* Compute the widget style */
75 int style = getDefaultStyle();
76 if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL;
77 if (verticalButton.getSelection ()) style |= DWT.VERTICAL;
78 if (borderButton.getSelection ()) style |= DWT.BORDER;
79
80 /* Create the example widgets */
81 slider1 = new Slider(sliderGroup, style);
82 }
83
84 /**
85 * Create a group of widgets to control the increment
86 * attribute of the example widget.
87 */
88 void createIncrementGroup() {
89
90 /* Create the group */
91 Group incrementGroup = new Group (controlGroup, DWT.NONE);
92 incrementGroup.setLayout (new GridLayout ());
93 incrementGroup.setText (ControlExample.getResourceString("Increment"));
94 incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
95
96 /* Create the Spinner widget */
97 incrementSpinner = new Spinner (incrementGroup, DWT.BORDER);
98 incrementSpinner.setMaximum (100000);
99 incrementSpinner.setSelection (getDefaultIncrement());
100 incrementSpinner.setPageIncrement (100);
101 incrementSpinner.setIncrement (1);
102 incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
103
104 /* Add the listeners */
105 incrementSpinner.addSelectionListener (new class() SelectionAdapter {
106 public void widgetSelected (SelectionEvent e) {
107 setWidgetIncrement ();
108 }
109 });
110 }
111
112 /**
113 * Create a group of widgets to control the page increment
114 * attribute of the example widget.
115 */
116 void createPageIncrementGroup() {
117
118 /* Create the group */
119 Group pageIncrementGroup = new Group (controlGroup, DWT.NONE);
120 pageIncrementGroup.setLayout (new GridLayout ());
121 pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment"));
122 pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
123
124 /* Create the Spinner widget */
125 pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER);
126 pageIncrementSpinner.setMaximum (100000);
127 pageIncrementSpinner.setSelection (getDefaultPageIncrement());
128 pageIncrementSpinner.setPageIncrement (100);
129 pageIncrementSpinner.setIncrement (1);
130 pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
131
132 /* Add the listeners */
133 pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter {
134 public void widgetSelected (SelectionEvent event) {
135 setWidgetPageIncrement ();
136 }
137 });
138 }
139
140 /**
141 * Create a group of widgets to control the thumb
142 * attribute of the example widget.
143 */
144 void createThumbGroup() {
145
146 /* Create the group */
147 Group thumbGroup = new Group (controlGroup, DWT.NONE);
148 thumbGroup.setLayout (new GridLayout ());
149 thumbGroup.setText (ControlExample.getResourceString("Thumb"));
150 thumbGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
151
152 /* Create the Spinner widget */
153 thumbSpinner = new Spinner (thumbGroup, DWT.BORDER);
154 thumbSpinner.setMaximum (100000);
155 thumbSpinner.setSelection (getDefaultThumb());
156 thumbSpinner.setPageIncrement (100);
157 thumbSpinner.setIncrement (1);
158 thumbSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
159
160 /* Add the listeners */
161 thumbSpinner.addSelectionListener (new class() SelectionAdapter {
162 public void widgetSelected (SelectionEvent event) {
163 setWidgetThumb ();
164 }
165 });
166 }
167
168 /**
169 * Gets the "Example" widget children.
170 */
171 Widget [] getExampleWidgets () {
172 return [ cast(Widget) slider1 ];
173 }
174
175 /**
176 * Returns a list of set/get API method names (without the set/get prefix)
177 * that can be used to set/get values in the example control(s).
178 */
179 char[][] getMethodNames() {
180 return ["Selection", "ToolTipText"];
181 }
182
183 /**
184 * Gets the text for the tab folder item.
185 */
186 char[] getTabText () {
187 return "Slider";
188 }
189
190 /**
191 * Sets the state of the "Example" widgets.
192 */
193 void setExampleWidgetState () {
194 super.setExampleWidgetState ();
195 if (!instance.startup) {
196 setWidgetIncrement ();
197 setWidgetPageIncrement ();
198 setWidgetThumb ();
199 }
200 }
201
202 /**
203 * Gets the default maximum of the "Example" widgets.
204 */
205 int getDefaultMaximum () {
206 return slider1.getMaximum();
207 }
208
209 /**
210 * Gets the default minimim of the "Example" widgets.
211 */
212 int getDefaultMinimum () {
213 return slider1.getMinimum();
214 }
215
216 /**
217 * Gets the default selection of the "Example" widgets.
218 */
219 int getDefaultSelection () {
220 return slider1.getSelection();
221 }
222
223 /**
224 * Gets the default increment of the "Example" widgets.
225 */
226 int getDefaultIncrement () {
227 return slider1.getIncrement();
228 }
229
230 /**
231 * Gets the default page increment of the "Example" widgets.
232 */
233 int getDefaultPageIncrement () {
234 return slider1.getPageIncrement();
235 }
236
237 /**
238 * Gets the default thumb of the "Example" widgets.
239 */
240 int getDefaultThumb () {
241 return slider1.getThumb();
242 }
243
244 /**
245 * Sets the increment of the "Example" widgets.
246 */
247 void setWidgetIncrement () {
248 slider1.setIncrement (incrementSpinner.getSelection ());
249 }
250
251 /**
252 * Sets the minimim of the "Example" widgets.
253 */
254 void setWidgetMaximum () {
255 slider1.setMaximum (maximumSpinner.getSelection ());
256 }
257
258 /**
259 * Sets the minimim of the "Example" widgets.
260 */
261 void setWidgetMinimum () {
262 slider1.setMinimum (minimumSpinner.getSelection ());
263 }
264
265 /**
266 * Sets the page increment of the "Example" widgets.
267 */
268 void setWidgetPageIncrement () {
269 slider1.setPageIncrement (pageIncrementSpinner.getSelection ());
270 }
271
272 /**
273 * Sets the selection of the "Example" widgets.
274 */
275 void setWidgetSelection () {
276 slider1.setSelection (selectionSpinner.getSelection ());
277 }
278
279 /**
280 * Sets the thumb of the "Example" widgets.
281 */
282 void setWidgetThumb () {
283 slider1.setThumb (thumbSpinner.getSelection ());
284 }
285 }