Mercurial > projects > dwt-samples
annotate examples/controlexample/ButtonTab.d @ 161:eb84f9418bbf
Change module names to this not have examples in the FQN.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 01 Sep 2008 22:24:27 +0200 |
parents | 8a1930f94cbb |
children |
rev | line source |
---|---|
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 *******************************************************************************/ | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
80
diff
changeset
|
13 module controlexample.ButtonTab; |
78 | 14 |
15 | |
16 | |
17 import dwt.DWT; | |
18 import dwt.events.SelectionAdapter; | |
19 import dwt.events.SelectionEvent; | |
20 import dwt.events.SelectionListener; | |
21 import dwt.layout.GridData; | |
22 import dwt.layout.GridLayout; | |
23 import dwt.widgets.Button; | |
24 import dwt.widgets.Group; | |
25 import dwt.widgets.Widget; | |
26 | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
80
diff
changeset
|
27 import controlexample.AlignableTab; |
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
80
diff
changeset
|
28 import controlexample.ControlExample; |
78 | 29 |
30 /** | |
31 * <code>ButtonTab</code> is the class that | |
32 * demonstrates DWT buttons. | |
33 */ | |
34 class ButtonTab : AlignableTab { | |
35 | |
36 /* Example widgets and groups that contain them */ | |
37 Button button1, button2, button3, button4, button5, button6, button7, button8, button9; | |
38 Group textButtonGroup, imageButtonGroup, imagetextButtonGroup; | |
39 | |
40 /* Alignment widgets added to the "Control" group */ | |
41 Button upButton, downButton; | |
42 | |
43 /* Style widgets added to the "Style" group */ | |
44 Button pushButton, checkButton, radioButton, toggleButton, arrowButton, flatButton; | |
45 | |
46 /** | |
47 * Creates the Tab within a given instance of ControlExample. | |
48 */ | |
49 this(ControlExample instance) { | |
50 super(instance); | |
51 } | |
52 | |
53 /** | |
54 * Creates the "Control" group. | |
55 */ | |
56 void createControlGroup () { | |
57 super.createControlGroup (); | |
58 | |
59 /* Create the controls */ | |
60 upButton = new Button (alignmentGroup, DWT.RADIO); | |
61 upButton.setText (ControlExample.getResourceString("Up")); | |
62 downButton = new Button (alignmentGroup, DWT.RADIO); | |
63 downButton.setText (ControlExample.getResourceString("Down")); | |
64 | |
65 /* Add the listeners */ | |
66 SelectionListener selectionListener = new class() SelectionAdapter { | |
67 public void widgetSelected(SelectionEvent event) { | |
68 if (!(cast(Button) event.widget).getSelection()) return; | |
69 setExampleWidgetAlignment (); | |
70 } | |
71 }; | |
72 upButton.addSelectionListener(selectionListener); | |
73 downButton.addSelectionListener(selectionListener); | |
74 } | |
75 | |
76 /** | |
77 * Creates the "Example" group. | |
78 */ | |
79 void createExampleGroup () { | |
80 super.createExampleGroup (); | |
81 | |
82 /* Create a group for text buttons */ | |
83 textButtonGroup = new Group(exampleGroup, DWT.NONE); | |
84 GridLayout gridLayout = new GridLayout (); | |
85 textButtonGroup.setLayout(gridLayout); | |
86 gridLayout.numColumns = 3; | |
87 textButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
88 textButtonGroup.setText (ControlExample.getResourceString("Text_Buttons")); | |
89 | |
90 /* Create a group for the image buttons */ | |
91 imageButtonGroup = new Group(exampleGroup, DWT.NONE); | |
92 gridLayout = new GridLayout(); | |
93 imageButtonGroup.setLayout(gridLayout); | |
94 gridLayout.numColumns = 3; | |
95 imageButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
96 imageButtonGroup.setText (ControlExample.getResourceString("Image_Buttons")); | |
97 | |
98 /* Create a group for the image and text buttons */ | |
99 imagetextButtonGroup = new Group(exampleGroup, DWT.NONE); | |
100 gridLayout = new GridLayout(); | |
101 imagetextButtonGroup.setLayout(gridLayout); | |
102 gridLayout.numColumns = 3; | |
103 imagetextButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
104 imagetextButtonGroup.setText (ControlExample.getResourceString("Image_Text_Buttons")); | |
105 } | |
106 | |
107 /** | |
108 * Creates the "Example" widgets. | |
109 */ | |
110 void createExampleWidgets () { | |
111 | |
112 /* Compute the widget style */ | |
113 int style = getDefaultStyle(); | |
114 if (pushButton.getSelection()) style |= DWT.PUSH; | |
115 if (checkButton.getSelection()) style |= DWT.CHECK; | |
116 if (radioButton.getSelection()) style |= DWT.RADIO; | |
117 if (toggleButton.getSelection()) style |= DWT.TOGGLE; | |
118 if (flatButton.getSelection()) style |= DWT.FLAT; | |
119 if (borderButton.getSelection()) style |= DWT.BORDER; | |
120 if (leftButton.getSelection()) style |= DWT.LEFT; | |
121 if (rightButton.getSelection()) style |= DWT.RIGHT; | |
122 if (arrowButton.getSelection()) { | |
123 style |= DWT.ARROW; | |
124 if (upButton.getSelection()) style |= DWT.UP; | |
125 if (downButton.getSelection()) style |= DWT.DOWN; | |
126 } else { | |
127 if (centerButton.getSelection()) style |= DWT.CENTER; | |
128 } | |
129 | |
130 /* Create the example widgets */ | |
131 button1 = new Button(textButtonGroup, style); | |
132 button1.setText(ControlExample.getResourceString("One")); | |
133 button2 = new Button(textButtonGroup, style); | |
134 button2.setText(ControlExample.getResourceString("Two")); | |
135 button3 = new Button(textButtonGroup, style); | |
136 button3.setText(ControlExample.getResourceString("Three")); | |
137 button4 = new Button(imageButtonGroup, style); | |
138 button4.setImage(instance.images[ControlExample.ciClosedFolder]); | |
139 button5 = new Button(imageButtonGroup, style); | |
140 button5.setImage(instance.images[ControlExample.ciOpenFolder]); | |
141 button6 = new Button(imageButtonGroup, style); | |
142 button6.setImage(instance.images[ControlExample.ciTarget]); | |
143 button7 = new Button(imagetextButtonGroup, style); | |
144 button7.setText(ControlExample.getResourceString("One")); | |
145 button7.setImage(instance.images[ControlExample.ciClosedFolder]); | |
146 button8 = new Button(imagetextButtonGroup, style); | |
147 button8.setText(ControlExample.getResourceString("Two")); | |
148 button8.setImage(instance.images[ControlExample.ciOpenFolder]); | |
149 button9 = new Button(imagetextButtonGroup, style); | |
150 button9.setText(ControlExample.getResourceString("Three")); | |
151 button9.setImage(instance.images[ControlExample.ciTarget]); | |
152 } | |
153 | |
154 /** | |
155 * Creates the "Style" group. | |
156 */ | |
157 void createStyleGroup() { | |
158 super.createStyleGroup (); | |
159 | |
160 /* Create the extra widgets */ | |
161 pushButton = new Button (styleGroup, DWT.RADIO); | |
162 pushButton.setText("DWT.PUSH"); | |
163 checkButton = new Button (styleGroup, DWT.RADIO); | |
164 checkButton.setText ("DWT.CHECK"); | |
165 radioButton = new Button (styleGroup, DWT.RADIO); | |
166 radioButton.setText ("DWT.RADIO"); | |
167 toggleButton = new Button (styleGroup, DWT.RADIO); | |
168 toggleButton.setText ("DWT.TOGGLE"); | |
169 arrowButton = new Button (styleGroup, DWT.RADIO); | |
170 arrowButton.setText ("DWT.ARROW"); | |
171 flatButton = new Button (styleGroup, DWT.CHECK); | |
172 flatButton.setText ("DWT.FLAT"); | |
173 borderButton = new Button (styleGroup, DWT.CHECK); | |
174 borderButton.setText ("DWT.BORDER"); | |
175 } | |
176 | |
177 /** | |
178 * Gets the "Example" widget children. | |
179 */ | |
180 Widget [] getExampleWidgets () { | |
181 return [ cast(Widget) button1, button2, button3, button4, button5, button6, button7, button8, button9 ]; | |
182 } | |
183 | |
184 /** | |
185 * Returns a list of set/get API method names (without the set/get prefix) | |
186 * that can be used to set/get values in the example control(s). | |
187 */ | |
188 char[][] getMethodNames() { | |
189 return [ cast(char[])"Selection", "Text", "ToolTipText" ]; | |
190 } | |
191 | |
192 /** | |
193 * Gets the text for the tab folder item. | |
194 */ | |
195 char[] getTabText () { | |
196 return "Button"; | |
197 } | |
198 | |
199 /** | |
200 * Sets the alignment of the "Example" widgets. | |
201 */ | |
202 void setExampleWidgetAlignment () { | |
203 int alignment = 0; | |
204 if (leftButton.getSelection ()) alignment = DWT.LEFT; | |
205 if (centerButton.getSelection ()) alignment = DWT.CENTER; | |
206 if (rightButton.getSelection ()) alignment = DWT.RIGHT; | |
207 if (upButton.getSelection ()) alignment = DWT.UP; | |
208 if (downButton.getSelection ()) alignment = DWT.DOWN; | |
209 button1.setAlignment (alignment); | |
210 button2.setAlignment (alignment); | |
211 button3.setAlignment (alignment); | |
212 button4.setAlignment (alignment); | |
213 button5.setAlignment (alignment); | |
214 button6.setAlignment (alignment); | |
215 button7.setAlignment (alignment); | |
216 button8.setAlignment (alignment); | |
217 button9.setAlignment (alignment); | |
218 } | |
219 | |
220 /** | |
221 * Sets the state of the "Example" widgets. | |
222 */ | |
223 void setExampleWidgetState () { | |
224 super.setExampleWidgetState (); | |
225 if (arrowButton.getSelection ()) { | |
226 upButton.setEnabled (true); | |
227 centerButton.setEnabled (false); | |
228 downButton.setEnabled (true); | |
229 } else { | |
230 upButton.setEnabled (false); | |
231 centerButton.setEnabled (true); | |
232 downButton.setEnabled (false); | |
233 } | |
234 upButton.setSelection ((button1.getStyle () & DWT.UP) !is 0); | |
235 downButton.setSelection ((button1.getStyle () & DWT.DOWN) !is 0); | |
236 pushButton.setSelection ((button1.getStyle () & DWT.PUSH) !is 0); | |
237 checkButton.setSelection ((button1.getStyle () & DWT.CHECK) !is 0); | |
238 radioButton.setSelection ((button1.getStyle () & DWT.RADIO) !is 0); | |
239 toggleButton.setSelection ((button1.getStyle () & DWT.TOGGLE) !is 0); | |
240 arrowButton.setSelection ((button1.getStyle () & DWT.ARROW) !is 0); | |
241 flatButton.setSelection ((button1.getStyle () & DWT.FLAT) !is 0); | |
242 borderButton.setSelection ((button1.getStyle () & DWT.BORDER) !is 0); | |
243 } | |
244 } |