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