78
|
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.RangeTab;
|
|
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.Button;
|
|
23 import dwt.widgets.Group;
|
|
24 import dwt.widgets.Spinner;
|
|
25 import dwt.widgets.Widget;
|
|
26
|
|
27 import examples.controlexample.Tab;
|
|
28 import examples.controlexample.ControlExample;
|
|
29
|
|
30 abstract class RangeTab : Tab {
|
|
31 /* Style widgets added to the "Style" group */
|
|
32 Button horizontalButton, verticalButton;
|
|
33 bool orientationButtons = true;
|
|
34
|
|
35 /* Scale widgets added to the "Control" group */
|
|
36 Spinner minimumSpinner, selectionSpinner, maximumSpinner;
|
|
37
|
|
38 /**
|
|
39 * Creates the Tab within a given instance of ControlExample.
|
|
40 */
|
|
41 this(ControlExample instance) {
|
|
42 super(instance);
|
|
43 }
|
|
44
|
|
45 /**
|
|
46 * Creates the "Control" widget children.
|
|
47 */
|
|
48 void createControlWidgets () {
|
|
49 /* Create controls specific to this example */
|
|
50 createMinimumGroup ();
|
|
51 createMaximumGroup ();
|
|
52 createSelectionGroup ();
|
|
53 }
|
|
54
|
|
55 /**
|
|
56 * Create a group of widgets to control the maximum
|
|
57 * attribute of the example widget.
|
|
58 */
|
|
59 void createMaximumGroup() {
|
|
60
|
|
61 /* Create the group */
|
|
62 Group maximumGroup = new Group (controlGroup, DWT.NONE);
|
|
63 maximumGroup.setLayout (new GridLayout ());
|
|
64 maximumGroup.setText (ControlExample.getResourceString("Maximum"));
|
|
65 maximumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
|
|
66
|
|
67 /* Create a Spinner widget */
|
|
68 maximumSpinner = new Spinner (maximumGroup, DWT.BORDER);
|
|
69 maximumSpinner.setMaximum (100000);
|
|
70 maximumSpinner.setSelection (getDefaultMaximum());
|
|
71 maximumSpinner.setPageIncrement (100);
|
|
72 maximumSpinner.setIncrement (1);
|
|
73 maximumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
|
|
74
|
|
75 /* Add the listeners */
|
|
76 maximumSpinner.addSelectionListener(new class() SelectionAdapter {
|
|
77 public void widgetSelected (SelectionEvent event) {
|
|
78 setWidgetMaximum ();
|
|
79 }
|
|
80 });
|
|
81 }
|
|
82
|
|
83 /**
|
|
84 * Create a group of widgets to control the minimum
|
|
85 * attribute of the example widget.
|
|
86 */
|
|
87 void createMinimumGroup() {
|
|
88
|
|
89 /* Create the group */
|
|
90 Group minimumGroup = new Group (controlGroup, DWT.NONE);
|
|
91 minimumGroup.setLayout (new GridLayout ());
|
|
92 minimumGroup.setText (ControlExample.getResourceString("Minimum"));
|
|
93 minimumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
|
|
94
|
|
95 /* Create a Spinner widget */
|
|
96 minimumSpinner = new Spinner (minimumGroup, DWT.BORDER);
|
|
97 minimumSpinner.setMaximum (100000);
|
|
98 minimumSpinner.setSelection(getDefaultMinimum());
|
|
99 minimumSpinner.setPageIncrement (100);
|
|
100 minimumSpinner.setIncrement (1);
|
|
101 minimumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
|
|
102
|
|
103 /* Add the listeners */
|
|
104 minimumSpinner.addSelectionListener (new class() SelectionAdapter {
|
|
105 public void widgetSelected (SelectionEvent event) {
|
|
106 setWidgetMinimum ();
|
|
107 }
|
|
108 });
|
|
109
|
|
110 }
|
|
111
|
|
112 /**
|
|
113 * Create a group of widgets to control the selection
|
|
114 * attribute of the example widget.
|
|
115 */
|
|
116 void createSelectionGroup() {
|
|
117
|
|
118 /* Create the group */
|
|
119 Group selectionGroup = new Group(controlGroup, DWT.NONE);
|
|
120 selectionGroup.setLayout(new GridLayout());
|
|
121 GridData gridData = new GridData(DWT.FILL, DWT.BEGINNING, false, false);
|
|
122 selectionGroup.setLayoutData(gridData);
|
|
123 selectionGroup.setText(ControlExample.getResourceString("Selection"));
|
|
124
|
|
125 /* Create a Spinner widget */
|
|
126 selectionSpinner = new Spinner (selectionGroup, DWT.BORDER);
|
|
127 selectionSpinner.setMaximum (100000);
|
|
128 selectionSpinner.setSelection (getDefaultSelection());
|
|
129 selectionSpinner.setPageIncrement (100);
|
|
130 selectionSpinner.setIncrement (1);
|
|
131 selectionSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false));
|
|
132
|
|
133 /* Add the listeners */
|
|
134 selectionSpinner.addSelectionListener(new class() SelectionAdapter {
|
|
135 public void widgetSelected(SelectionEvent event) {
|
|
136 setWidgetSelection ();
|
|
137 }
|
|
138 });
|
|
139
|
|
140 }
|
|
141
|
|
142 /**
|
|
143 * Creates the "Style" group.
|
|
144 */
|
|
145 void createStyleGroup () {
|
|
146 super.createStyleGroup ();
|
|
147
|
|
148 /* Create the extra widgets */
|
|
149 if (orientationButtons) {
|
|
150 horizontalButton = new Button (styleGroup, DWT.RADIO);
|
|
151 horizontalButton.setText ("DWT.HORIZONTAL");
|
|
152 verticalButton = new Button (styleGroup, DWT.RADIO);
|
|
153 verticalButton.setText ("DWT.VERTICAL");
|
|
154 }
|
|
155 borderButton = new Button (styleGroup, DWT.CHECK);
|
|
156 borderButton.setText ("DWT.BORDER");
|
|
157 }
|
|
158
|
|
159 /**
|
|
160 * Sets the state of the "Example" widgets.
|
|
161 */
|
|
162 void setExampleWidgetState () {
|
|
163 super.setExampleWidgetState ();
|
|
164 if (!instance.startup) {
|
|
165 setWidgetMinimum ();
|
|
166 setWidgetMaximum ();
|
|
167 setWidgetSelection ();
|
|
168 }
|
|
169 Widget [] widgets = getExampleWidgets ();
|
|
170 if (widgets.length !is 0) {
|
|
171 if (orientationButtons) {
|
|
172 horizontalButton.setSelection ((widgets [0].getStyle () & DWT.HORIZONTAL) !is 0);
|
|
173 verticalButton.setSelection ((widgets [0].getStyle () & DWT.VERTICAL) !is 0);
|
|
174 }
|
|
175 borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0);
|
|
176 }
|
|
177 }
|
|
178
|
|
179 /**
|
|
180 * Gets the default maximum of the "Example" widgets.
|
|
181 */
|
|
182 abstract int getDefaultMaximum ();
|
|
183
|
|
184 /**
|
|
185 * Gets the default minimim of the "Example" widgets.
|
|
186 */
|
|
187 abstract int getDefaultMinimum ();
|
|
188
|
|
189 /**
|
|
190 * Gets the default selection of the "Example" widgets.
|
|
191 */
|
|
192 abstract int getDefaultSelection ();
|
|
193
|
|
194 /**
|
|
195 * Sets the maximum of the "Example" widgets.
|
|
196 */
|
|
197 abstract void setWidgetMaximum ();
|
|
198
|
|
199 /**
|
|
200 * Sets the minimim of the "Example" widgets.
|
|
201 */
|
|
202 abstract void setWidgetMinimum ();
|
|
203
|
|
204 /**
|
|
205 * Sets the selection of the "Example" widgets.
|
|
206 */
|
|
207 abstract void setWidgetSelection ();
|
|
208 }
|