Mercurial > projects > dwt-samples
annotate examples/controlexample/ShellTab.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 | 4a04b6759f98 |
children |
rev | line source |
---|---|
78 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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:
78
diff
changeset
|
13 module controlexample.ShellTab; |
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.Event; | |
25 import dwt.widgets.Group; | |
26 import dwt.widgets.Listener; | |
27 import dwt.widgets.Shell; | |
28 | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
29 import controlexample.Tab; |
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
30 import controlexample.ControlExample; |
78 | 31 |
32 import dwt.dwthelper.utils; | |
33 | |
34 import tango.util.Convert; | |
35 | |
36 class ShellTab : Tab { | |
37 /* Style widgets added to the "Style" groups, and "Other" group */ | |
38 Button noParentButton, parentButton; | |
39 Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton, onTopButton, toolButton; | |
40 Button createButton, closeAllButton; | |
41 Button modelessButton, primaryModalButton, applicationModalButton, systemModalButton; | |
42 Button imageButton; | |
43 Group parentStyleGroup, modalStyleGroup; | |
44 | |
45 /* Variables used to track the open shells */ | |
46 int shellCount = 0; | |
47 Shell [] shells; | |
48 | |
49 /** | |
50 * Creates the Tab within a given instance of ControlExample. | |
51 */ | |
52 this(ControlExample instance) { | |
53 super(instance); | |
54 } | |
55 | |
56 /** | |
57 * Close all the example shells. | |
58 */ | |
59 void closeAllShells() { | |
60 for (int i = 0; i<shellCount; i++) { | |
61 if (shells[i] !is null & !shells [i].isDisposed ()) { | |
62 shells [i].dispose(); | |
63 } | |
64 } | |
65 shellCount = 0; | |
66 } | |
67 | |
68 /** | |
69 * Handle the Create button selection event. | |
70 * | |
71 * @param event org.eclipse.swt.events.SelectionEvent | |
72 */ | |
73 public void createButtonSelected(SelectionEvent event) { | |
74 | |
75 /* | |
76 * Remember the example shells so they | |
77 * can be disposed by the user. | |
78 */ | |
79 if (shellCount >= shells.length) { | |
80 Shell [] newShells = new Shell [shells.length + 4]; | |
81 System.arraycopy (shells, 0, newShells, 0, shells.length); | |
82 shells = newShells; | |
83 } | |
84 | |
85 /* Compute the shell style */ | |
86 int style = DWT.NONE; | |
87 if (noTrimButton.getSelection()) style |= DWT.NO_TRIM; | |
88 if (closeButton.getSelection()) style |= DWT.CLOSE; | |
89 if (titleButton.getSelection()) style |= DWT.TITLE; | |
90 if (minButton.getSelection()) style |= DWT.MIN; | |
91 if (maxButton.getSelection()) style |= DWT.MAX; | |
92 if (borderButton.getSelection()) style |= DWT.BORDER; | |
93 if (resizeButton.getSelection()) style |= DWT.RESIZE; | |
94 if (onTopButton.getSelection()) style |= DWT.ON_TOP; | |
95 if (toolButton.getSelection()) style |= DWT.TOOL; | |
96 if (modelessButton.getSelection()) style |= DWT.MODELESS; | |
97 if (primaryModalButton.getSelection()) style |= DWT.PRIMARY_MODAL; | |
98 if (applicationModalButton.getSelection()) style |= DWT.APPLICATION_MODAL; | |
99 if (systemModalButton.getSelection()) style |= DWT.SYSTEM_MODAL; | |
100 | |
101 /* Create the shell with or without a parent */ | |
102 if (noParentButton.getSelection ()) { | |
103 shells [shellCount] = new Shell (style); | |
104 } else { | |
105 shells [shellCount] = new Shell (shell, style); | |
106 } | |
107 Shell currentShell = shells [shellCount]; | |
108 Button button = new Button(currentShell, DWT.PUSH); | |
109 button.setBounds(20, 20, 120, 30); | |
110 Button closeButton = new Button(currentShell, DWT.PUSH); | |
111 closeButton.setBounds(160, 20, 120, 30); | |
112 closeButton.setText(ControlExample.getResourceString("Close")); | |
113 closeButton.addListener(DWT.Selection, new class(currentShell) Listener { | |
114 Shell s; | |
115 this( Shell s ){ this.s = s; } | |
116 public void handleEvent(Event event) { | |
117 s.dispose(); | |
118 } | |
119 }); | |
120 | |
121 /* Set the size, title, and image, and open the shell */ | |
122 currentShell.setSize (300, 100); | |
123 currentShell.setText (ControlExample.getResourceString("Title") ~ to!(char[])(shellCount)); | |
124 if (imageButton.getSelection()) currentShell.setImage(instance.images[ControlExample.ciTarget]); | |
125 if (backgroundImageButton.getSelection()) currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]); | |
126 hookListeners (currentShell); | |
127 currentShell.open (); | |
128 shellCount++; | |
129 } | |
130 | |
131 /** | |
132 * Creates the "Control" group. | |
133 */ | |
134 void createControlGroup () { | |
135 /* | |
136 * Create the "Control" group. This is the group on the | |
137 * right half of each example tab. It consists of the | |
138 * style group, the 'other' group and the size group. | |
139 */ | |
140 controlGroup = new Group (tabFolderPage, DWT.NONE); | |
141 controlGroup.setLayout (new GridLayout (2, true)); | |
142 controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); | |
143 controlGroup.setText (ControlExample.getResourceString("Parameters")); | |
144 | |
145 /* Create a group for the decoration style controls */ | |
146 styleGroup = new Group (controlGroup, DWT.NONE); | |
147 styleGroup.setLayout (new GridLayout ()); | |
148 styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false, 1, 3)); | |
149 styleGroup.setText (ControlExample.getResourceString("Decoration_Styles")); | |
150 | |
151 /* Create a group for the modal style controls */ | |
152 modalStyleGroup = new Group (controlGroup, DWT.NONE); | |
153 modalStyleGroup.setLayout (new GridLayout ()); | |
154 modalStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); | |
155 modalStyleGroup.setText (ControlExample.getResourceString("Modal_Styles")); | |
156 | |
157 /* Create a group for the 'other' controls */ | |
158 otherGroup = new Group (controlGroup, DWT.NONE); | |
159 otherGroup.setLayout (new GridLayout ()); | |
160 otherGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false)); | |
161 otherGroup.setText (ControlExample.getResourceString("Other")); | |
162 | |
163 /* Create a group for the parent style controls */ | |
164 parentStyleGroup = new Group (controlGroup, DWT.NONE); | |
165 parentStyleGroup.setLayout (new GridLayout ()); | |
166 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
167 parentStyleGroup.setLayoutData (gridData); | |
168 parentStyleGroup.setText (ControlExample.getResourceString("Parent")); | |
169 } | |
170 | |
171 /** | |
172 * Creates the "Control" widget children. | |
173 */ | |
174 void createControlWidgets () { | |
175 | |
176 /* Create the parent style buttons */ | |
177 noParentButton = new Button (parentStyleGroup, DWT.RADIO); | |
178 noParentButton.setText (ControlExample.getResourceString("No_Parent")); | |
179 parentButton = new Button (parentStyleGroup, DWT.RADIO); | |
180 parentButton.setText (ControlExample.getResourceString("Parent")); | |
181 | |
182 /* Create the decoration style buttons */ | |
183 noTrimButton = new Button (styleGroup, DWT.CHECK); | |
184 noTrimButton.setText ("DWT.NO_TRIM"); | |
185 closeButton = new Button (styleGroup, DWT.CHECK); | |
186 closeButton.setText ("DWT.CLOSE"); | |
187 titleButton = new Button (styleGroup, DWT.CHECK); | |
188 titleButton.setText ("DWT.TITLE"); | |
189 minButton = new Button (styleGroup, DWT.CHECK); | |
190 minButton.setText ("DWT.MIN"); | |
191 maxButton = new Button (styleGroup, DWT.CHECK); | |
192 maxButton.setText ("DWT.MAX"); | |
193 borderButton = new Button (styleGroup, DWT.CHECK); | |
194 borderButton.setText ("DWT.BORDER"); | |
195 resizeButton = new Button (styleGroup, DWT.CHECK); | |
196 resizeButton.setText ("DWT.RESIZE"); | |
197 onTopButton = new Button (styleGroup, DWT.CHECK); | |
198 onTopButton.setText ("DWT.ON_TOP"); | |
199 toolButton = new Button (styleGroup, DWT.CHECK); | |
200 toolButton.setText ("DWT.TOOL"); | |
201 | |
202 /* Create the modal style buttons */ | |
203 modelessButton = new Button (modalStyleGroup, DWT.RADIO); | |
204 modelessButton.setText ("DWT.MODELESS"); | |
205 primaryModalButton = new Button (modalStyleGroup, DWT.RADIO); | |
206 primaryModalButton.setText ("DWT.PRIMARY_MODAL"); | |
207 applicationModalButton = new Button (modalStyleGroup, DWT.RADIO); | |
208 applicationModalButton.setText ("DWT.APPLICATION_MODAL"); | |
209 systemModalButton = new Button (modalStyleGroup, DWT.RADIO); | |
210 systemModalButton.setText ("DWT.SYSTEM_MODAL"); | |
211 | |
212 /* Create the 'other' buttons */ | |
213 imageButton = new Button (otherGroup, DWT.CHECK); | |
214 imageButton.setText (ControlExample.getResourceString("Image")); | |
215 backgroundImageButton = new Button(otherGroup, DWT.CHECK); | |
216 backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); | |
217 | |
218 /* Create the "create" and "closeAll" buttons */ | |
219 createButton = new Button (controlGroup, DWT.NONE); | |
220 GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_END); | |
221 createButton.setLayoutData (gridData); | |
222 createButton.setText (ControlExample.getResourceString("Create_Shell")); | |
223 closeAllButton = new Button (controlGroup, DWT.NONE); | |
224 gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); | |
225 closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells")); | |
226 closeAllButton.setLayoutData (gridData); | |
227 | |
228 /* Add the listeners */ | |
229 createButton.addSelectionListener(new class() SelectionAdapter { | |
230 public void widgetSelected(SelectionEvent e) { | |
231 createButtonSelected(e); | |
232 } | |
233 }); | |
234 closeAllButton.addSelectionListener(new class() SelectionAdapter { | |
235 public void widgetSelected(SelectionEvent e) { | |
236 closeAllShells (); | |
237 } | |
238 }); | |
239 SelectionListener decorationButtonListener = new class() SelectionAdapter { | |
240 public void widgetSelected(SelectionEvent event) { | |
241 decorationButtonSelected(event); | |
242 } | |
243 }; | |
244 noTrimButton.addSelectionListener (decorationButtonListener); | |
245 closeButton.addSelectionListener (decorationButtonListener); | |
246 titleButton.addSelectionListener (decorationButtonListener); | |
247 minButton.addSelectionListener (decorationButtonListener); | |
248 maxButton.addSelectionListener (decorationButtonListener); | |
249 borderButton.addSelectionListener (decorationButtonListener); | |
250 resizeButton.addSelectionListener (decorationButtonListener); | |
251 applicationModalButton.addSelectionListener (decorationButtonListener); | |
252 systemModalButton.addSelectionListener (decorationButtonListener); | |
253 | |
254 /* Set the default state */ | |
255 noParentButton.setSelection (true); | |
256 modelessButton.setSelection (true); | |
257 backgroundImageButton.setSelection(false); | |
258 } | |
259 | |
260 /** | |
261 * Handle a decoration button selection event. | |
262 * | |
263 * @param event org.eclipse.swt.events.SelectionEvent | |
264 */ | |
265 public void decorationButtonSelected(SelectionEvent event) { | |
266 | |
267 /* Make sure if the modal style is DWT.APPLICATION_MODAL or | |
268 * DWT.SYSTEM_MODAL the style DWT.CLOSE is also selected. | |
269 * This is to make sure the user can close the shell. | |
270 */ | |
271 Button widget = cast(Button) event.widget; | |
272 if (widget is applicationModalButton || widget is systemModalButton) { | |
273 if (widget.getSelection()) { | |
274 closeButton.setSelection (true); | |
275 noTrimButton.setSelection (false); | |
276 } | |
277 return; | |
278 } | |
279 if (widget is closeButton) { | |
280 if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { | |
281 closeButton.setSelection (true); | |
282 } | |
283 } | |
284 /* | |
285 * Make sure if the No Trim button is selected then | |
286 * all other decoration buttons are deselected. | |
287 */ | |
288 if (widget.getSelection() && widget !is noTrimButton) { | |
289 noTrimButton.setSelection (false); | |
290 return; | |
291 } | |
292 if (widget.getSelection() && widget is noTrimButton) { | |
293 if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { | |
294 noTrimButton.setSelection (false); | |
295 return; | |
296 } | |
297 closeButton.setSelection (false); | |
298 titleButton.setSelection (false); | |
299 minButton.setSelection (false); | |
300 maxButton.setSelection (false); | |
301 borderButton.setSelection (false); | |
302 resizeButton.setSelection (false); | |
303 return; | |
304 } | |
305 } | |
306 | |
307 /** | |
308 * Gets the text for the tab folder item. | |
309 */ | |
310 char[] getTabText () { | |
311 return "Shell"; | |
312 } | |
313 } |