Mercurial > projects > dwt-samples
comparison examples/controlexample/ScaleTab.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.ScaleTab; | |
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.Scale; | |
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 | |
32 class ScaleTab : RangeTab { | |
33 /* Example widgets and groups that contain them */ | |
34 Scale scale1; | |
35 Group scaleGroup; | |
36 | |
37 /* Spinner widgets added to the "Control" group */ | |
38 Spinner incrementSpinner, pageIncrementSpinner; | |
39 | |
40 /** | |
41 * Creates the Tab within a given instance of ControlExample. | |
42 */ | |
43 this(ControlExample instance) { | |
44 super(instance); | |
45 } | |
46 | |
47 /** | |
48 * Creates the "Control" widget children. | |
49 */ | |
50 void createControlWidgets () { | |
51 super.createControlWidgets (); | |
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 scale */ | |
63 scaleGroup = new Group (exampleGroup, DWT.NONE); | |
64 scaleGroup.setLayout (new GridLayout ()); | |
65 scaleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
66 scaleGroup.setText ("Scale"); | |
67 | |
68 } | |
69 | |
70 /** | |
71 * Creates the "Example" widgets. | |
72 */ | |
73 void createExampleWidgets () { | |
74 | |
75 /* Compute the widget style */ | |
76 int style = getDefaultStyle(); | |
77 if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; | |
78 if (verticalButton.getSelection ()) style |= DWT.VERTICAL; | |
79 if (borderButton.getSelection ()) style |= DWT.BORDER; | |
80 | |
81 /* Create the example widgets */ | |
82 scale1 = new Scale (scaleGroup, style); | |
83 } | |
84 | |
85 /** | |
86 * Create a group of widgets to control the increment | |
87 * attribute of the example widget. | |
88 */ | |
89 void createIncrementGroup() { | |
90 | |
91 /* Create the group */ | |
92 Group incrementGroup = new Group (controlGroup, DWT.NONE); | |
93 incrementGroup.setLayout (new GridLayout ()); | |
94 incrementGroup.setText (ControlExample.getResourceString("Increment")); | |
95 incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); | |
96 | |
97 /* Create the Spinner widget */ | |
98 incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); | |
99 incrementSpinner.setMaximum (100000); | |
100 incrementSpinner.setSelection (getDefaultIncrement()); | |
101 incrementSpinner.setPageIncrement (100); | |
102 incrementSpinner.setIncrement (1); | |
103 incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); | |
104 | |
105 /* Add the listeners */ | |
106 incrementSpinner.addSelectionListener (new class() SelectionAdapter { | |
107 public void widgetSelected (SelectionEvent e) { | |
108 setWidgetIncrement (); | |
109 } | |
110 }); | |
111 } | |
112 | |
113 /** | |
114 * Create a group of widgets to control the page increment | |
115 * attribute of the example widget. | |
116 */ | |
117 void createPageIncrementGroup() { | |
118 | |
119 /* Create the group */ | |
120 Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); | |
121 pageIncrementGroup.setLayout (new GridLayout ()); | |
122 pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); | |
123 pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); | |
124 | |
125 /* Create the Spinner widget */ | |
126 pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); | |
127 pageIncrementSpinner.setMaximum (100000); | |
128 pageIncrementSpinner.setSelection (getDefaultPageIncrement()); | |
129 pageIncrementSpinner.setPageIncrement (100); | |
130 pageIncrementSpinner.setIncrement (1); | |
131 pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); | |
132 | |
133 /* Add the listeners */ | |
134 pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { | |
135 public void widgetSelected (SelectionEvent event) { | |
136 setWidgetPageIncrement (); | |
137 } | |
138 }); | |
139 } | |
140 | |
141 /** | |
142 * Gets the "Example" widget children. | |
143 */ | |
144 Widget [] getExampleWidgets () { | |
145 return [ cast(Widget) scale1]; | |
146 } | |
147 | |
148 /** | |
149 * Returns a list of set/get API method names (without the set/get prefix) | |
150 * that can be used to set/get values in the example control(s). | |
151 */ | |
152 char[][] getMethodNames() { | |
153 return ["Selection", "ToolTipText"]; | |
154 } | |
155 | |
156 /** | |
157 * Gets the text for the tab folder item. | |
158 */ | |
159 char[] getTabText () { | |
160 return "Scale"; | |
161 } | |
162 | |
163 /** | |
164 * Sets the state of the "Example" widgets. | |
165 */ | |
166 void setExampleWidgetState () { | |
167 super.setExampleWidgetState (); | |
168 if (!instance.startup) { | |
169 setWidgetIncrement (); | |
170 setWidgetPageIncrement (); | |
171 } | |
172 } | |
173 | |
174 /** | |
175 * Gets the default maximum of the "Example" widgets. | |
176 */ | |
177 int getDefaultMaximum () { | |
178 return scale1.getMaximum(); | |
179 } | |
180 | |
181 /** | |
182 * Gets the default minimim of the "Example" widgets. | |
183 */ | |
184 int getDefaultMinimum () { | |
185 return scale1.getMinimum(); | |
186 } | |
187 | |
188 /** | |
189 * Gets the default selection of the "Example" widgets. | |
190 */ | |
191 int getDefaultSelection () { | |
192 return scale1.getSelection(); | |
193 } | |
194 | |
195 /** | |
196 * Gets the default increment of the "Example" widgets. | |
197 */ | |
198 int getDefaultIncrement () { | |
199 return scale1.getIncrement(); | |
200 } | |
201 | |
202 /** | |
203 * Gets the default page increment of the "Example" widgets. | |
204 */ | |
205 int getDefaultPageIncrement () { | |
206 return scale1.getPageIncrement(); | |
207 } | |
208 | |
209 /** | |
210 * Sets the increment of the "Example" widgets. | |
211 */ | |
212 void setWidgetIncrement () { | |
213 scale1.setIncrement (incrementSpinner.getSelection ()); | |
214 } | |
215 | |
216 /** | |
217 * Sets the minimim of the "Example" widgets. | |
218 */ | |
219 void setWidgetMaximum () { | |
220 scale1.setMaximum (maximumSpinner.getSelection ()); | |
221 } | |
222 | |
223 /** | |
224 * Sets the minimim of the "Example" widgets. | |
225 */ | |
226 void setWidgetMinimum () { | |
227 scale1.setMinimum (minimumSpinner.getSelection ()); | |
228 } | |
229 | |
230 /** | |
231 * Sets the page increment of the "Example" widgets. | |
232 */ | |
233 void setWidgetPageIncrement () { | |
234 scale1.setPageIncrement (pageIncrementSpinner.getSelection ()); | |
235 } | |
236 | |
237 /** | |
238 * Sets the selection of the "Example" widgets. | |
239 */ | |
240 void setWidgetSelection () { | |
241 scale1.setSelection (selectionSpinner.getSelection ()); | |
242 } | |
243 } |