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.Tab;
|
|
14
|
|
15
|
|
16
|
|
17 import dwt.DWT;
|
|
18 import dwt.events.ArmEvent;
|
|
19 import dwt.events.ControlEvent;
|
|
20 import dwt.events.DisposeEvent;
|
|
21 import dwt.events.DisposeListener;
|
|
22 import dwt.events.FocusEvent;
|
|
23 import dwt.events.HelpEvent;
|
|
24 import dwt.events.KeyAdapter;
|
|
25 import dwt.events.KeyEvent;
|
|
26 import dwt.events.MenuEvent;
|
|
27 import dwt.events.ModifyEvent;
|
|
28 import dwt.events.MouseEvent;
|
|
29 import dwt.events.PaintEvent;
|
|
30 import dwt.events.SelectionAdapter;
|
|
31 import dwt.events.SelectionEvent;
|
|
32 import dwt.events.SelectionListener;
|
|
33 import dwt.events.ShellEvent;
|
|
34 import dwt.events.TraverseEvent;
|
|
35 import dwt.events.TreeEvent;
|
|
36 import dwt.events.TypedEvent;
|
|
37 import dwt.events.VerifyEvent;
|
|
38 import dwt.graphics.Color;
|
|
39 import dwt.graphics.Font;
|
|
40 import dwt.graphics.FontData;
|
|
41 import dwt.graphics.GC;
|
|
42 import dwt.graphics.Image;
|
|
43 import dwt.graphics.Point;
|
|
44 import dwt.graphics.RGB;
|
|
45 import dwt.graphics.Rectangle;
|
|
46 import dwt.layout.GridData;
|
|
47 import dwt.layout.GridLayout;
|
|
48 import dwt.widgets.Button;
|
|
49 import dwt.widgets.ColorDialog;
|
|
50 import dwt.widgets.Combo;
|
|
51 import dwt.widgets.Composite;
|
|
52 import dwt.widgets.Control;
|
|
53 import dwt.widgets.Display;
|
|
54 import dwt.widgets.Event;
|
|
55 import dwt.widgets.FontDialog;
|
|
56 import dwt.widgets.Group;
|
|
57 import dwt.widgets.Item;
|
|
58 import dwt.widgets.Label;
|
|
59 import dwt.widgets.Link;
|
|
60 import dwt.widgets.List;
|
|
61 import dwt.widgets.Listener;
|
|
62 import dwt.widgets.Menu;
|
|
63 import dwt.widgets.MenuItem;
|
|
64 import dwt.widgets.ProgressBar;
|
|
65 import dwt.widgets.Sash;
|
|
66 import dwt.widgets.Scale;
|
|
67 import dwt.widgets.Shell;
|
|
68 import dwt.widgets.Slider;
|
|
69 import dwt.widgets.Spinner;
|
|
70 import dwt.widgets.TabFolder;
|
|
71 import dwt.widgets.Table;
|
|
72 import dwt.widgets.TableItem;
|
|
73 import dwt.widgets.Text;
|
|
74 import dwt.widgets.Tree;
|
|
75 import dwt.widgets.TreeItem;
|
|
76 import dwt.widgets.ToolTip;
|
|
77 import dwt.widgets.Widget;
|
|
78 import dwt.widgets.Canvas;
|
|
79 import dwt.widgets.CoolBar;
|
|
80 import dwt.widgets.ExpandBar;
|
|
81
|
|
82 import dwt.dwthelper.utils;
|
|
83
|
|
84 import examples.controlexample.ControlExample;
|
|
85 import tango.text.convert.Format;
|
|
86
|
|
87 import tango.io.Stdout;
|
|
88
|
|
89 /**
|
|
90 * <code>Tab</code> is the abstract superclass of every page
|
|
91 * in the example's tab folder. Each page in the tab folder
|
|
92 * describes a control.
|
|
93 *
|
|
94 * A Tab itself is not a control but instead provides a
|
|
95 * hierarchy with which to share code that is common to
|
|
96 * every page in the folder.
|
|
97 *
|
|
98 * A typical page in a Tab contains a two column composite.
|
|
99 * The left column contains the "Example" group. The right
|
|
100 * column contains "Control" group. The "Control" group
|
|
101 * contains controls that allow the user to interact with
|
|
102 * the example control. The "Control" group typically
|
|
103 * contains a "Style", "Other" and "Size" group. Subclasses
|
|
104 * can override these defaults to augment a group or stop
|
|
105 * a group from being created.
|
|
106 */
|
|
107 struct EventName {
|
|
108 char[] name;
|
|
109 int id;
|
|
110 }
|
|
111 abstract class Tab {
|
|
112 Shell shell;
|
|
113 Display display;
|
|
114
|
|
115 /* Common control buttons */
|
|
116 Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton;
|
|
117 Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton;
|
|
118
|
|
119 /* Common groups and composites */
|
|
120 Composite tabFolderPage;
|
|
121 Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup;
|
|
122
|
|
123 /* Controlling instance */
|
|
124 const ControlExample instance;
|
|
125
|
|
126 /* Sizing constants for the "Size" group */
|
|
127 static const int TOO_SMALL_SIZE = 10;
|
|
128 static const int SMALL_SIZE = 50;
|
|
129 static const int LARGE_SIZE = 100;
|
|
130
|
|
131 /* Right-to-left support */
|
|
132 static const bool RTL_SUPPORT_ENABLE = false;
|
|
133 Group orientationGroup;
|
|
134 Button rtlButton, ltrButton, defaultOrietationButton;
|
|
135
|
|
136 /* Controls and resources for the "Colors & Fonts" group */
|
|
137 static const int IMAGE_SIZE = 12;
|
|
138 static const int FOREGROUND_COLOR = 0;
|
|
139 static const int BACKGROUND_COLOR = 1;
|
|
140 static const int FONT = 2;
|
|
141 Table colorAndFontTable;
|
|
142 ColorDialog colorDialog;
|
|
143 FontDialog fontDialog;
|
|
144 Color foregroundColor, backgroundColor;
|
|
145 Font font;
|
|
146
|
|
147 /* Controls and resources for the "Background Mode" group */
|
|
148 Combo backgroundModeCombo;
|
|
149 Button backgroundModeImageButton, backgroundModeColorButton;
|
|
150
|
|
151 /* Event logging variables and controls */
|
|
152 Text eventConsole;
|
|
153 bool logging = false;
|
|
154 bool [] eventsFilter;
|
|
155
|
|
156 /* Set/Get API controls */
|
|
157 Combo nameCombo;
|
|
158 Label returnTypeLabel;
|
|
159 Button getButton, setButton;
|
|
160 Text setText, getText;
|
|
161
|
|
162 static EventName[] EVENT_NAMES = [
|
|
163 {"Activate"[], DWT.Activate},
|
|
164 {"Arm", DWT.Arm},
|
|
165 {"Close", DWT.Close},
|
|
166 {"Collapse", DWT.Collapse},
|
|
167 {"Deactivate", DWT.Deactivate},
|
|
168 {"DefaultSelection", DWT.DefaultSelection},
|
|
169 {"Deiconify", DWT.Deiconify},
|
|
170 {"Dispose", DWT.Dispose},
|
|
171 {"DragDetect", DWT.DragDetect},
|
|
172 {"EraseItem", DWT.EraseItem},
|
|
173 {"Expand", DWT.Expand},
|
|
174 {"FocusIn", DWT.FocusIn},
|
|
175 {"FocusOut", DWT.FocusOut},
|
|
176 {"HardKeyDown", DWT.HardKeyDown},
|
|
177 {"HardKeyUp", DWT.HardKeyUp},
|
|
178 {"Help", DWT.Help},
|
|
179 {"Hide", DWT.Hide},
|
|
180 {"Iconify", DWT.Iconify},
|
|
181 {"KeyDown", DWT.KeyDown},
|
|
182 {"KeyUp", DWT.KeyUp},
|
|
183 {"MeasureItem", DWT.MeasureItem},
|
|
184 {"MenuDetect", DWT.MenuDetect},
|
|
185 {"Modify", DWT.Modify},
|
|
186 {"MouseDoubleClick", DWT.MouseDoubleClick},
|
|
187 {"MouseDown", DWT.MouseDown},
|
|
188 {"MouseEnter", DWT.MouseEnter},
|
|
189 {"MouseExit", DWT.MouseExit},
|
|
190 {"MouseHover", DWT.MouseHover},
|
|
191 {"MouseMove", DWT.MouseMove},
|
|
192 {"MouseUp", DWT.MouseUp},
|
|
193 {"MouseWheel", DWT.MouseWheel},
|
|
194 {"Move", DWT.Move},
|
|
195 {"Paint", DWT.Paint},
|
|
196 {"PaintItem", DWT.PaintItem},
|
|
197 {"Resize", DWT.Resize},
|
|
198 {"Selection", DWT.Selection},
|
|
199 {"SetData", DWT.SetData},
|
|
200 // {"Settings", DWT.Settings}, // note: this event only goes to Display
|
|
201 {"Show", DWT.Show},
|
|
202 {"Traverse", DWT.Traverse},
|
|
203 {"Verify", DWT.Verify}
|
|
204 ];
|
|
205
|
|
206 bool samplePopup = false;
|
|
207
|
|
208
|
|
209 struct ReflectTypeInfo{
|
|
210 ReflectMethodInfo[ char[] ] methods;
|
|
211 }
|
|
212 struct ReflectMethodInfo{
|
|
213 TypeInfo returnType;
|
|
214 TypeInfo[] argumentTypes;
|
|
215 }
|
|
216 static ReflectTypeInfo[ ClassInfo ] reflectTypeInfos;
|
|
217
|
|
218 static ReflectMethodInfo createMethodInfo( TypeInfo ret, TypeInfo[] args ... ){
|
|
219 ReflectMethodInfo res;
|
|
220 res.returnType = ret;
|
|
221 foreach( arg; args ){
|
|
222 res.argumentTypes ~= arg;
|
|
223 }
|
|
224 return res;
|
|
225 }
|
|
226 static void createSetterGetter( ref ReflectTypeInfo ti, char[] name, TypeInfo type ){
|
|
227 ti.methods[ "get" ~ name ] = createMethodInfo( type );
|
|
228 ti.methods[ "set" ~ name ] = createMethodInfo( typeid(void), type );
|
|
229 }
|
|
230
|
|
231 static void registerTypes(){
|
|
232 if( reflectTypeInfos.length > 0 ){
|
|
233 return;
|
|
234 }
|
|
235
|
|
236 {
|
|
237 ReflectTypeInfo ti;
|
|
238 createSetterGetter( ti, "Selection", typeid(bool) );
|
|
239 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
240 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
241 reflectTypeInfos[ Button.classinfo ] = ti;
|
|
242 }
|
|
243 {
|
|
244 ReflectTypeInfo ti;
|
|
245 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
246 reflectTypeInfos[ Canvas.classinfo ] = ti;
|
|
247 }
|
|
248 {
|
|
249 ReflectTypeInfo ti;
|
|
250 createSetterGetter( ti, "Orientation", typeid(int) );
|
|
251 createSetterGetter( ti, "Items", typeid(char[]) );
|
|
252 createSetterGetter( ti, "Selection", typeid(Point) );
|
|
253 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
254 createSetterGetter( ti, "TextLimit", typeid(int) );
|
|
255 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
256 createSetterGetter( ti, "VisibleItemCount", typeid(int) );
|
|
257 reflectTypeInfos[ Combo.classinfo ] = ti;
|
|
258 }
|
|
259 {
|
|
260 ReflectTypeInfo ti;
|
|
261 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
262 reflectTypeInfos[ CoolBar.classinfo ] = ti;
|
|
263 }
|
|
264 {
|
|
265 ReflectTypeInfo ti;
|
|
266 createSetterGetter( ti, "Spacing", typeid(int) );
|
|
267 reflectTypeInfos[ ExpandBar.classinfo ] = ti;
|
|
268 }
|
|
269 {
|
|
270 ReflectTypeInfo ti;
|
|
271 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
272 reflectTypeInfos[ Group.classinfo ] = ti;
|
|
273 }
|
|
274 {
|
|
275 ReflectTypeInfo ti;
|
|
276 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
277 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
278 reflectTypeInfos[ Label.classinfo ] = ti;
|
|
279 }
|
|
280 {
|
|
281 ReflectTypeInfo ti;
|
|
282 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
283 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
284 reflectTypeInfos[ Link.classinfo ] = ti;
|
|
285 }
|
|
286 {
|
|
287 ReflectTypeInfo ti;
|
|
288 createSetterGetter( ti, "Items", typeid(char[][]) );
|
|
289 createSetterGetter( ti, "Selection", typeid(char[]) );
|
|
290 createSetterGetter( ti, "TopIndex", typeid(int) );
|
|
291 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
292 reflectTypeInfos[ List.classinfo ] = ti;
|
|
293 }
|
|
294 {
|
|
295 ReflectTypeInfo ti;
|
|
296 createSetterGetter( ti, "Selection", typeid(char[]) );
|
|
297 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
298 reflectTypeInfos[ ProgressBar.classinfo ] = ti;
|
|
299 }
|
|
300 {
|
|
301 ReflectTypeInfo ti;
|
|
302 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
303 reflectTypeInfos[ Sash.classinfo ] = ti;
|
|
304 }
|
|
305 {
|
|
306 ReflectTypeInfo ti;
|
|
307 createSetterGetter( ti, "Selection", typeid(int) );
|
|
308 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
309 reflectTypeInfos[ Scale.classinfo ] = ti;
|
|
310 }
|
|
311 {
|
|
312 ReflectTypeInfo ti;
|
|
313 createSetterGetter( ti, "Selection", typeid(int) );
|
|
314 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
315 reflectTypeInfos[ Slider.classinfo ] = ti;
|
|
316 }
|
|
317 {
|
|
318 ReflectTypeInfo ti;
|
|
319 createSetterGetter( ti, "Selection", typeid(int) );
|
|
320 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
321 reflectTypeInfos[ Spinner.classinfo ] = ti;
|
|
322 }
|
|
323 {
|
|
324 ReflectTypeInfo ti;
|
|
325 createSetterGetter( ti, "DoubleClickEnabled", typeid(bool) );
|
|
326 createSetterGetter( ti, "EchoChar", typeid(wchar) );
|
|
327 createSetterGetter( ti, "Editable", typeid(bool) );
|
|
328 createSetterGetter( ti, "Orientation", typeid(int) );
|
|
329 createSetterGetter( ti, "Selection", typeid(Point) );
|
|
330 createSetterGetter( ti, "Tabs", typeid(int) );
|
|
331 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
332 createSetterGetter( ti, "TextLimit", typeid(int) );
|
|
333 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
334 createSetterGetter( ti, "TopIndex", typeid(int) );
|
|
335 reflectTypeInfos[ Text.classinfo ] = ti;
|
|
336 }
|
|
337 {
|
|
338 ReflectTypeInfo ti;
|
|
339 createSetterGetter( ti, "Message", typeid(int) );
|
|
340 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
341 reflectTypeInfos[ ToolTip.classinfo ] = ti;
|
|
342 }
|
|
343 {
|
|
344 ReflectTypeInfo ti;
|
|
345 createSetterGetter( ti, "ColumnOrder", typeid(int[]) );
|
|
346 createSetterGetter( ti, "Selection", typeid(TreeItem[]) );
|
|
347 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
348 createSetterGetter( ti, "TopItem", typeid(int) );
|
|
349 reflectTypeInfos[ Tree.classinfo ] = ti;
|
|
350 }
|
|
351
|
|
352 /+{
|
|
353 ReflectTypeInfo ti;
|
|
354 createSetterGetter( ti, "Editable", typeid(bool) );
|
|
355 createSetterGetter( ti, "Items", typeid(char[]) );
|
|
356 createSetterGetter( ti, "Selection", typeid(Point) );
|
|
357 createSetterGetter( ti, "Text", typeid(char[]) );
|
|
358 createSetterGetter( ti, "TextLimit", typeid(int) );
|
|
359 createSetterGetter( ti, "ToolTipText", typeid(char[]) );
|
|
360 createSetterGetter( ti, "VisibleItemCount", typeid(int) );
|
|
361 reflectTypeInfos[ CCombo.classinfo ] = ti;
|
|
362 }+/
|
|
363 }
|
|
364 /**
|
|
365 * Creates the Tab within a given instance of ControlExample.
|
|
366 */
|
|
367 this(ControlExample instance) {
|
|
368 this.instance = instance;
|
|
369 registerTypes();
|
|
370 }
|
|
371
|
|
372 /**
|
|
373 * Creates the "Control" group. The "Control" group
|
|
374 * is typically the right hand column in the tab.
|
|
375 */
|
|
376 void createControlGroup () {
|
|
377
|
|
378 /*
|
|
379 * Create the "Control" group. This is the group on the
|
|
380 * right half of each example tab. It consists of the
|
|
381 * "Style" group, the "Other" group and the "Size" group.
|
|
382 */
|
|
383 controlGroup = new Group (tabFolderPage, DWT.NONE);
|
|
384 controlGroup.setLayout (new GridLayout (2, true));
|
|
385 controlGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false));
|
|
386 controlGroup.setText (ControlExample.getResourceString("Parameters"));
|
|
387
|
|
388 /* Create individual groups inside the "Control" group */
|
|
389 createStyleGroup ();
|
|
390 createOtherGroup ();
|
|
391 createSetGetGroup();
|
|
392 createSizeGroup ();
|
|
393 createColorAndFontGroup ();
|
|
394 if (RTL_SUPPORT_ENABLE) {
|
|
395 createOrientationGroup ();
|
|
396 }
|
|
397
|
|
398 /*
|
|
399 * For each Button child in the style group, add a selection
|
|
400 * listener that will recreate the example controls. If the
|
|
401 * style group button is a RADIO button, ensure that the radio
|
|
402 * button is selected before recreating the example controls.
|
|
403 * When the user selects a RADIO button, the current RADIO
|
|
404 * button in the group is deselected and the new RADIO button
|
|
405 * is selected automatically. The listeners are notified for
|
|
406 * both these operations but typically only do work when a RADIO
|
|
407 * button is selected.
|
|
408 */
|
|
409 SelectionListener selectionListener = new class() SelectionAdapter {
|
|
410 public void widgetSelected (SelectionEvent event) {
|
|
411 if ((event.widget.getStyle () & DWT.RADIO) !is 0) {
|
|
412 if (!(cast(Button) event.widget).getSelection ()) return;
|
|
413 }
|
|
414 recreateExampleWidgets ();
|
|
415 }
|
|
416 };
|
|
417 Control [] children = styleGroup.getChildren ();
|
|
418 for (int i=0; i<children.length; i++) {
|
|
419 if ( auto button = cast(Button)children [i]) {
|
|
420 button.addSelectionListener (selectionListener);
|
|
421 } else {
|
|
422 if ( auto composite = cast(Composite)children [i]) {
|
|
423 /* Look down one more level of children in the style group. */
|
|
424 Control [] grandchildren = composite.getChildren ();
|
|
425 for (int j=0; j<grandchildren.length; j++) {
|
|
426 if ( auto button = cast(Button)grandchildren [j]) {
|
|
427 button.addSelectionListener (selectionListener);
|
|
428 }
|
|
429 }
|
|
430 }
|
|
431 }
|
|
432 }
|
|
433 if (RTL_SUPPORT_ENABLE) {
|
|
434 rtlButton.addSelectionListener (selectionListener);
|
|
435 ltrButton.addSelectionListener (selectionListener);
|
|
436 defaultOrietationButton.addSelectionListener (selectionListener);
|
|
437 }
|
|
438 }
|
|
439
|
|
440 /**
|
|
441 * Append the Set/Get API controls to the "Other" group.
|
|
442 */
|
|
443 void createSetGetGroup() {
|
|
444 /*
|
|
445 * Create the button to access set/get API functionality.
|
|
446 */
|
|
447 char[] [] methodNames = getMethodNames ();
|
|
448 if (methodNames !is null) {
|
|
449 Button setGetButton = new Button (otherGroup, DWT.PUSH);
|
|
450 setGetButton.setText (ControlExample.getResourceString ("Set_Get"));
|
|
451 setGetButton.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false));
|
|
452 setGetButton.addSelectionListener (new class(methodNames) SelectionAdapter {
|
|
453 char[][] mths;
|
|
454 this( char[][] mths ){ this.mths = mths; }
|
|
455 public void widgetSelected (SelectionEvent e) {
|
|
456 Button button = cast(Button)e.widget;
|
|
457 Point pt = button.getLocation();
|
|
458 pt = e.display.map(button, null, pt);
|
|
459 createSetGetDialog(pt.x, pt.y, mths);
|
|
460 }
|
|
461 });
|
|
462 }
|
|
463 }
|
|
464
|
|
465 /**
|
|
466 * Creates the "Control" widget children.
|
|
467 * Subclasses override this method to augment
|
|
468 * the standard controls created in the "Style",
|
|
469 * "Other" and "Size" groups.
|
|
470 */
|
|
471 void createControlWidgets () {
|
|
472 }
|
|
473
|
|
474 /**
|
|
475 * Creates the "Colors and Fonts" group. This is typically
|
|
476 * a child of the "Control" group. Subclasses override
|
|
477 * this method to customize color and font settings.
|
|
478 */
|
|
479 void createColorAndFontGroup () {
|
|
480 /* Create the group. */
|
|
481 colorGroup = new Group(controlGroup, DWT.NONE);
|
|
482 colorGroup.setLayout (new GridLayout (2, true));
|
|
483 colorGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
484 colorGroup.setText (ControlExample.getResourceString ("Colors"));
|
|
485 colorAndFontTable = new Table(colorGroup, DWT.BORDER | DWT.V_SCROLL);
|
|
486 colorAndFontTable.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, true, false, 2, 1));
|
|
487 TableItem item = new TableItem(colorAndFontTable, DWT.None);
|
|
488 item.setText(ControlExample.getResourceString ("Foreground_Color"));
|
|
489 colorAndFontTable.setSelection(0);
|
|
490 item = new TableItem(colorAndFontTable, DWT.None);
|
|
491 item.setText(ControlExample.getResourceString ("Background_Color"));
|
|
492 item = new TableItem(colorAndFontTable, DWT.None);
|
|
493 item.setText(ControlExample.getResourceString ("Font"));
|
|
494 Button changeButton = new Button (colorGroup, DWT.PUSH);
|
|
495 changeButton.setText(ControlExample.getResourceString("Change"));
|
|
496 changeButton.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false));
|
|
497 Button defaultsButton = new Button (colorGroup, DWT.PUSH);
|
|
498 defaultsButton.setText(ControlExample.getResourceString("Defaults"));
|
|
499 defaultsButton.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false));
|
|
500
|
|
501 /* Add listeners to set/reset colors and fonts. */
|
|
502 colorDialog = new ColorDialog (shell);
|
|
503 fontDialog = new FontDialog (shell);
|
|
504 colorAndFontTable.addSelectionListener(new class() SelectionAdapter {
|
|
505 public void widgetDefaultSelected(SelectionEvent event) {
|
|
506 changeFontOrColor (colorAndFontTable.getSelectionIndex());
|
|
507 }
|
|
508 });
|
|
509 changeButton.addSelectionListener(new class() SelectionAdapter {
|
|
510 public void widgetSelected(SelectionEvent event) {
|
|
511 changeFontOrColor (colorAndFontTable.getSelectionIndex());
|
|
512 }
|
|
513 });
|
|
514 defaultsButton.addSelectionListener(new class() SelectionAdapter {
|
|
515 public void widgetSelected (SelectionEvent e) {
|
|
516 resetColorsAndFonts ();
|
|
517 }
|
|
518 });
|
|
519 shell.addDisposeListener(new class() DisposeListener {
|
|
520 public void widgetDisposed(DisposeEvent event) {
|
|
521 if (foregroundColor !is null) foregroundColor.dispose();
|
|
522 if (backgroundColor !is null) backgroundColor.dispose();
|
|
523 if (font !is null) font.dispose();
|
|
524 foregroundColor = null;
|
|
525 backgroundColor = null;
|
|
526 font = null;
|
|
527 if (colorAndFontTable !is null && !colorAndFontTable.isDisposed()) {
|
|
528 TableItem [] items = colorAndFontTable.getItems();
|
|
529 for (int i = 0; i < items.length; i++) {
|
|
530 Image image = items[i].getImage();
|
|
531 if (image !is null) image.dispose();
|
|
532 }
|
|
533 }
|
|
534 }
|
|
535 });
|
|
536 }
|
|
537
|
|
538 void changeFontOrColor(int index) {
|
|
539 switch (index) {
|
|
540 case FOREGROUND_COLOR: {
|
|
541 Color oldColor = foregroundColor;
|
|
542 if (oldColor is null) {
|
|
543 Control [] controls = getExampleControls ();
|
|
544 if (controls.length > 0) oldColor = controls [0].getForeground ();
|
|
545 }
|
|
546 if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color
|
|
547 RGB rgb = colorDialog.open();
|
|
548 if (rgb is null) return;
|
|
549 oldColor = foregroundColor; // save old foreground color to dispose when done
|
|
550 foregroundColor = new Color (display, rgb);
|
|
551 setExampleWidgetForeground ();
|
|
552 if (oldColor !is null) oldColor.dispose ();
|
|
553 }
|
|
554 break;
|
|
555 case BACKGROUND_COLOR: {
|
|
556 Color oldColor = backgroundColor;
|
|
557 if (oldColor is null) {
|
|
558 Control [] controls = getExampleControls ();
|
|
559 if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color
|
|
560 }
|
|
561 if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB());
|
|
562 RGB rgb = colorDialog.open();
|
|
563 if (rgb is null) return;
|
|
564 oldColor = backgroundColor; // save old background color to dispose when done
|
|
565 backgroundColor = new Color (display, rgb);
|
|
566 setExampleWidgetBackground ();
|
|
567 if (oldColor !is null) oldColor.dispose ();
|
|
568 }
|
|
569 break;
|
|
570 case FONT: {
|
|
571 Font oldFont = font;
|
|
572 if (oldFont is null) {
|
|
573 Control [] controls = getExampleControls ();
|
|
574 if (controls.length > 0) oldFont = controls [0].getFont ();
|
|
575 }
|
|
576 if (oldFont !is null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font
|
|
577 FontData fontData = fontDialog.open ();
|
|
578 if (fontData is null) return;
|
|
579 oldFont = font; // dispose old font when done
|
|
580 font = new Font (display, fontData);
|
|
581 setExampleWidgetFont ();
|
|
582 setExampleWidgetSize ();
|
|
583 if (oldFont !is null) oldFont.dispose ();
|
|
584 }
|
|
585 break;
|
|
586 default:
|
|
587 }
|
|
588 }
|
|
589
|
|
590 /**
|
|
591 * Creates the "Other" group. This is typically
|
|
592 * a child of the "Control" group.
|
|
593 */
|
|
594 void createOtherGroup () {
|
|
595 /* Create the group */
|
|
596 otherGroup = new Group (controlGroup, DWT.NONE);
|
|
597 otherGroup.setLayout (new GridLayout ());
|
|
598 otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
599 otherGroup.setText (ControlExample.getResourceString("Other"));
|
|
600
|
|
601 /* Create the controls */
|
|
602 enabledButton = new Button(otherGroup, DWT.CHECK);
|
|
603 enabledButton.setText(ControlExample.getResourceString("Enabled"));
|
|
604 visibleButton = new Button(otherGroup, DWT.CHECK);
|
|
605 visibleButton.setText(ControlExample.getResourceString("Visible"));
|
|
606 backgroundImageButton = new Button(otherGroup, DWT.CHECK);
|
|
607 backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
|
|
608 popupMenuButton = new Button(otherGroup, DWT.CHECK);
|
|
609 popupMenuButton.setText(ControlExample.getResourceString("Popup_Menu"));
|
|
610
|
|
611 /* Add the listeners */
|
|
612 enabledButton.addSelectionListener (new class() SelectionAdapter {
|
|
613 public void widgetSelected (SelectionEvent event) {
|
|
614 setExampleWidgetEnabled ();
|
|
615 }
|
|
616 });
|
|
617 visibleButton.addSelectionListener (new class() SelectionAdapter {
|
|
618 public void widgetSelected (SelectionEvent event) {
|
|
619 setExampleWidgetVisibility ();
|
|
620 }
|
|
621 });
|
|
622 backgroundImageButton.addSelectionListener (new class() SelectionAdapter {
|
|
623 public void widgetSelected (SelectionEvent event) {
|
|
624 setExampleWidgetBackgroundImage ();
|
|
625 }
|
|
626 });
|
|
627 popupMenuButton.addSelectionListener (new class() SelectionAdapter {
|
|
628 public void widgetSelected (SelectionEvent event) {
|
|
629 setExampleWidgetPopupMenu ();
|
|
630 }
|
|
631 });
|
|
632
|
|
633 /* Set the default state */
|
|
634 enabledButton.setSelection(true);
|
|
635 visibleButton.setSelection(true);
|
|
636 backgroundImageButton.setSelection(false);
|
|
637 popupMenuButton.setSelection(false);
|
|
638 }
|
|
639
|
|
640 /**
|
|
641 * Creates the "Background Mode" group.
|
|
642 */
|
|
643 void createBackgroundModeGroup () {
|
|
644 // note that this method must be called after createExampleWidgets
|
|
645 if (getExampleControls ().length is 0) return;
|
|
646
|
|
647 /* Create the group */
|
|
648 backgroundModeGroup = new Group (controlGroup, DWT.NONE);
|
|
649 backgroundModeGroup.setLayout (new GridLayout ());
|
|
650 backgroundModeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
651 backgroundModeGroup.setText (ControlExample.getResourceString("Background_Mode"));
|
|
652
|
|
653 /* Create the controls */
|
|
654 backgroundModeCombo = new Combo(backgroundModeGroup, DWT.READ_ONLY);
|
|
655 backgroundModeCombo.setItems(["DWT.INHERIT_NONE", "DWT.INHERIT_DEFAULT", "DWT.INHERIT_FORCE"]);
|
|
656 backgroundModeImageButton = new Button(backgroundModeGroup, DWT.CHECK);
|
|
657 backgroundModeImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
|
|
658 backgroundModeColorButton = new Button(backgroundModeGroup, DWT.CHECK);
|
|
659 backgroundModeColorButton.setText(ControlExample.getResourceString("Background_Color"));
|
|
660
|
|
661 /* Add the listeners */
|
|
662 backgroundModeCombo.addSelectionListener (new class() SelectionAdapter {
|
|
663 public void widgetSelected (SelectionEvent event) {
|
|
664 setExampleGroupBackgroundMode ();
|
|
665 }
|
|
666 });
|
|
667 backgroundModeImageButton.addSelectionListener (new class() SelectionAdapter {
|
|
668 public void widgetSelected (SelectionEvent event) {
|
|
669 setExampleGroupBackgroundImage ();
|
|
670 }
|
|
671 });
|
|
672 backgroundModeColorButton.addSelectionListener (new class() SelectionAdapter {
|
|
673 public void widgetSelected (SelectionEvent event) {
|
|
674 setExampleGroupBackgroundColor ();
|
|
675 }
|
|
676 });
|
|
677
|
|
678 /* Set the default state */
|
|
679 backgroundModeCombo.setText(backgroundModeCombo.getItem(0));
|
|
680 backgroundModeImageButton.setSelection(false);
|
|
681 backgroundModeColorButton.setSelection(false);
|
|
682 }
|
|
683
|
|
684 /**
|
|
685 * Create the event console popup menu.
|
|
686 */
|
|
687 void createEventConsolePopup () {
|
|
688 Menu popup = new Menu (shell, DWT.POP_UP);
|
|
689 eventConsole.setMenu (popup);
|
|
690
|
|
691 MenuItem cut = new MenuItem (popup, DWT.PUSH);
|
|
692 cut.setText (ControlExample.getResourceString("MenuItem_Cut"));
|
|
693 cut.addListener (DWT.Selection, new class() Listener {
|
|
694 public void handleEvent (Event event) {
|
|
695 eventConsole.cut ();
|
|
696 }
|
|
697 });
|
|
698 MenuItem copy = new MenuItem (popup, DWT.PUSH);
|
|
699 copy.setText (ControlExample.getResourceString("MenuItem_Copy"));
|
|
700 copy.addListener (DWT.Selection, new class() Listener {
|
|
701 public void handleEvent (Event event) {
|
|
702 eventConsole.copy ();
|
|
703 }
|
|
704 });
|
|
705 MenuItem paste = new MenuItem (popup, DWT.PUSH);
|
|
706 paste.setText (ControlExample.getResourceString("MenuItem_Paste"));
|
|
707 paste.addListener (DWT.Selection, new class() Listener {
|
|
708 public void handleEvent (Event event) {
|
|
709 eventConsole.paste ();
|
|
710 }
|
|
711 });
|
|
712 new MenuItem (popup, DWT.SEPARATOR);
|
|
713 MenuItem selectAll = new MenuItem (popup, DWT.PUSH);
|
|
714 selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll"));
|
|
715 selectAll.addListener (DWT.Selection, new class() Listener {
|
|
716 public void handleEvent (Event event) {
|
|
717 eventConsole.selectAll ();
|
|
718 }
|
|
719 });
|
|
720 }
|
|
721
|
|
722 /**
|
|
723 * Creates the "Example" group. The "Example" group
|
|
724 * is typically the left hand column in the tab.
|
|
725 */
|
|
726 void createExampleGroup () {
|
|
727 exampleGroup = new Group (tabFolderPage, DWT.NONE);
|
|
728 exampleGroup.setLayout (new GridLayout ());
|
|
729 exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
|
|
730 }
|
|
731
|
|
732 /**
|
|
733 * Creates the "Example" widget children of the "Example" group.
|
|
734 * Subclasses override this method to create the particular
|
|
735 * example control.
|
|
736 */
|
|
737 void createExampleWidgets () {
|
|
738 /* Do nothing */
|
|
739 }
|
|
740
|
|
741 /**
|
|
742 * Creates and opens the "Listener selection" dialog.
|
|
743 */
|
|
744 void createListenerSelectionDialog () {
|
|
745 Shell dialog = new Shell (shell, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
|
|
746 dialog.setText (ControlExample.getResourceString ("Select_Listeners"));
|
|
747 dialog.setLayout (new GridLayout (2, false));
|
|
748 Table table = new Table (dialog, DWT.BORDER | DWT.V_SCROLL | DWT.CHECK);
|
|
749 GridData data = new GridData(GridData.FILL_BOTH);
|
|
750 data.verticalSpan = 2;
|
|
751 table.setLayoutData(data);
|
|
752 for (int i = 0; i < EVENT_NAMES.length; i++) {
|
|
753 TableItem item = new TableItem (table, DWT.NONE);
|
|
754 item.setText( EVENT_NAMES[i].name );
|
|
755 item.setChecked (eventsFilter[i]);
|
|
756 }
|
|
757 char[] [] customNames = getCustomEventNames ();
|
|
758 for (int i = 0; i < customNames.length; i++) {
|
|
759 TableItem item = new TableItem (table, DWT.NONE);
|
|
760 item.setText (customNames[i]);
|
|
761 item.setChecked (eventsFilter[EVENT_NAMES.length + i]);
|
|
762 }
|
|
763 Button selectAll = new Button (dialog, DWT.PUSH);
|
|
764 selectAll.setText(ControlExample.getResourceString ("Select_All"));
|
|
765 selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
|
|
766 selectAll.addSelectionListener (new class(table, customNames) SelectionAdapter {
|
|
767 Table tbl;
|
|
768 char[][] cn;
|
|
769 this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; }
|
|
770 public void widgetSelected(SelectionEvent e) {
|
|
771 TableItem [] items = tbl.getItems();
|
|
772 for (int i = 0; i < EVENT_NAMES.length; i++) {
|
|
773 items[i].setChecked(true);
|
|
774 }
|
|
775 for (int i = 0; i < cn.length; i++) {
|
|
776 items[EVENT_NAMES.length + i].setChecked(true);
|
|
777 }
|
|
778 }
|
|
779 });
|
|
780 Button deselectAll = new Button (dialog, DWT.PUSH);
|
|
781 deselectAll.setText(ControlExample.getResourceString ("Deselect_All"));
|
|
782 deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
|
|
783 deselectAll.addSelectionListener (new class(table, customNames) SelectionAdapter {
|
|
784 Table tbl;
|
|
785 char[][] cn;
|
|
786 this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; }
|
|
787 public void widgetSelected(SelectionEvent e) {
|
|
788 TableItem [] items = tbl.getItems();
|
|
789 for (int i = 0; i < EVENT_NAMES.length; i++) {
|
|
790 items[i].setChecked(false);
|
|
791 }
|
|
792 for (int i = 0; i < cn.length; i++) {
|
|
793 items[EVENT_NAMES.length + i].setChecked(false);
|
|
794 }
|
|
795 }
|
|
796 });
|
|
797 new Label(dialog, DWT.NONE); /* Filler */
|
|
798 Button ok = new Button (dialog, DWT.PUSH);
|
|
799 ok.setText(ControlExample.getResourceString ("OK"));
|
|
800 dialog.setDefaultButton(ok);
|
|
801 ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
|
|
802 ok.addSelectionListener (new class(dialog, table, customNames ) SelectionAdapter {
|
|
803 Shell dlg;
|
|
804 Table tbl;
|
|
805 char[][] cn;
|
|
806 this( Shell dlg, Table tbl, char[][] cn ){ this.tbl = tbl; this.dlg = dlg; this.cn = cn; }
|
|
807 public void widgetSelected(SelectionEvent e) {
|
|
808 TableItem [] items = tbl.getItems();
|
|
809 for (int i = 0; i < EVENT_NAMES.length; i++) {
|
|
810 eventsFilter[i] = items[i].getChecked();
|
|
811 }
|
|
812 for (int i = 0; i < cn.length; i++) {
|
|
813 eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked();
|
|
814 }
|
|
815 dlg.dispose();
|
|
816 }
|
|
817 });
|
|
818 dialog.pack ();
|
|
819 dialog.open ();
|
|
820 while (! dialog.isDisposed()) {
|
|
821 if (! display.readAndDispatch()) display.sleep();
|
|
822 }
|
|
823 }
|
|
824
|
|
825 /**
|
|
826 * Creates the "Listeners" group. The "Listeners" group
|
|
827 * goes below the "Example" and "Control" groups.
|
|
828 */
|
|
829 void createListenersGroup () {
|
|
830 listenersGroup = new Group (tabFolderPage, DWT.NONE);
|
|
831 listenersGroup.setLayout (new GridLayout (3, false));
|
|
832 listenersGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true, 2, 1));
|
|
833 listenersGroup.setText (ControlExample.getResourceString ("Listeners"));
|
|
834
|
|
835 /*
|
|
836 * Create the button to access the 'Listeners' dialog.
|
|
837 */
|
|
838 Button listenersButton = new Button (listenersGroup, DWT.PUSH);
|
|
839 listenersButton.setText (ControlExample.getResourceString ("Select_Listeners"));
|
|
840 listenersButton.addSelectionListener (new class() SelectionAdapter {
|
|
841 public void widgetSelected (SelectionEvent e) {
|
|
842 createListenerSelectionDialog ();
|
|
843 recreateExampleWidgets ();
|
|
844 }
|
|
845 });
|
|
846
|
|
847 /*
|
|
848 * Create the checkbox to add/remove listeners to/from the example widgets.
|
|
849 */
|
|
850 Button listenCheckbox = new Button (listenersGroup, DWT.CHECK);
|
|
851 listenCheckbox.setText (ControlExample.getResourceString ("Listen"));
|
|
852 listenCheckbox.addSelectionListener (new class(listenCheckbox) SelectionAdapter {
|
|
853 Button lcb;
|
|
854 this( Button lcb ){ this.lcb = lcb; }
|
|
855 public void widgetSelected(SelectionEvent e) {
|
|
856 logging = lcb.getSelection ();
|
|
857 recreateExampleWidgets ();
|
|
858 }
|
|
859 });
|
|
860
|
|
861 /*
|
|
862 * Create the button to clear the text.
|
|
863 */
|
|
864 Button clearButton = new Button (listenersGroup, DWT.PUSH);
|
|
865 clearButton.setText (ControlExample.getResourceString ("Clear"));
|
|
866 clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
|
|
867 clearButton.addSelectionListener (new class() SelectionAdapter {
|
|
868 public void widgetSelected (SelectionEvent e) {
|
|
869 eventConsole.setText ("");
|
|
870 }
|
|
871 });
|
|
872
|
|
873 /* Initialize the eventsFilter to log all events. */
|
|
874 int customEventCount = getCustomEventNames ().length;
|
|
875 eventsFilter = new bool [EVENT_NAMES.length + customEventCount];
|
|
876 for (int i = 0; i < EVENT_NAMES.length + customEventCount; i++) {
|
|
877 eventsFilter [i] = true;
|
|
878 }
|
|
879
|
|
880 /* Create the event console Text. */
|
|
881 eventConsole = new Text (listenersGroup, DWT.BORDER | DWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL);
|
|
882 GridData data = new GridData (GridData.FILL_BOTH);
|
|
883 data.horizontalSpan = 3;
|
|
884 data.heightHint = 80;
|
|
885 eventConsole.setLayoutData (data);
|
|
886 createEventConsolePopup ();
|
|
887 eventConsole.addKeyListener (new class() KeyAdapter {
|
|
888 public void keyPressed (KeyEvent e) {
|
|
889 if ((e.keyCode is 'A' || e.keyCode is 'a') && (e.stateMask & DWT.MOD1) !is 0) {
|
|
890 eventConsole.selectAll ();
|
|
891 e.doit = false;
|
|
892 }
|
|
893 }
|
|
894 });
|
|
895 }
|
|
896
|
|
897 /**
|
|
898 * Returns a list of set/get API method names (without the set/get prefix)
|
|
899 * that can be used to set/get values in the example control(s).
|
|
900 */
|
|
901 char[][] getMethodNames() {
|
|
902 return null;
|
|
903 }
|
|
904
|
|
905 void createSetGetDialog(int x, int y, char[][] methodNames) {
|
|
906 Shell dialog = new Shell(shell, DWT.DIALOG_TRIM | DWT.RESIZE | DWT.MODELESS);
|
|
907 dialog.setLayout(new GridLayout(2, false));
|
|
908 dialog.setText(getTabText() ~ " " ~ ControlExample.getResourceString ("Set_Get"));
|
|
909 nameCombo = new Combo(dialog, DWT.READ_ONLY);
|
|
910 nameCombo.setItems(methodNames);
|
|
911 nameCombo.setText(methodNames[0]);
|
|
912 nameCombo.setVisibleItemCount(methodNames.length);
|
|
913 nameCombo.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false));
|
|
914 nameCombo.addSelectionListener(new class() SelectionAdapter {
|
|
915 public void widgetSelected(SelectionEvent e) {
|
|
916 resetLabels();
|
|
917 }
|
|
918 });
|
|
919 returnTypeLabel = new Label(dialog, DWT.NONE);
|
|
920 returnTypeLabel.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false));
|
|
921 setButton = new Button(dialog, DWT.PUSH);
|
|
922 setButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false));
|
|
923 setButton.addSelectionListener(new class() SelectionAdapter {
|
|
924 public void widgetSelected(SelectionEvent e) {
|
|
925 setValue();
|
|
926 setText.selectAll();
|
|
927 setText.setFocus();
|
|
928 }
|
|
929 });
|
|
930 setText = new Text(dialog, DWT.SINGLE | DWT.BORDER);
|
|
931 setText.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false));
|
|
932 getButton = new Button(dialog, DWT.PUSH);
|
|
933 getButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false));
|
|
934 getButton.addSelectionListener(new class() SelectionAdapter {
|
|
935 public void widgetSelected(SelectionEvent e) {
|
|
936 getValue();
|
|
937 }
|
|
938 });
|
|
939 getText = new Text(dialog, DWT.MULTI | DWT.BORDER | DWT.READ_ONLY | DWT.H_SCROLL | DWT.V_SCROLL);
|
|
940 GridData data = new GridData(DWT.FILL, DWT.FILL, true, true);
|
|
941 data.widthHint = 240;
|
|
942 data.heightHint = 200;
|
|
943 getText.setLayoutData(data);
|
|
944 resetLabels();
|
|
945 dialog.setDefaultButton(setButton);
|
|
946 dialog.pack();
|
|
947 dialog.setLocation(x, y);
|
|
948 dialog.open();
|
|
949 }
|
|
950
|
|
951 void resetLabels() {
|
|
952 char[] methodRoot = nameCombo.getText();
|
|
953 returnTypeLabel.setText(parameterInfo(methodRoot));
|
|
954 setButton.setText(setMethodName(methodRoot));
|
|
955 getButton.setText("get" ~ methodRoot);
|
|
956 setText.setText("");
|
|
957 getText.setText("");
|
|
958 getValue();
|
|
959 setText.setFocus();
|
|
960 }
|
|
961
|
|
962 char[] setMethodName(char[] methodRoot) {
|
|
963 return "set" ~ methodRoot;
|
|
964 }
|
|
965
|
|
966 char[] parameterInfo(char[] methodRoot) {
|
|
967 char[] methodName = "get" ~ methodRoot;
|
|
968 auto mthi = getMethodInfo( methodName );
|
|
969 char[] typeNameString = mthi.returnType.toString;
|
|
970 //PORTING_LEFT
|
|
971
|
|
972 // char[] typeName = null;
|
|
973 // ClassInfo returnType = getReturnType(methodRoot);
|
|
974 bool isArray = false;
|
|
975 TypeInfo ti = mthi.returnType;
|
|
976
|
|
977 if ( auto tia = cast(TypeInfo_Array) mthi.returnType ) {
|
|
978 ti = tia.value;
|
|
979 isArray = true;
|
|
980 }
|
|
981 if ( auto tia = cast(TypeInfo_Class ) ti ) {
|
|
982 } else if ( auto tia = cast(TypeInfo_Interface ) ti ) {
|
|
983 } else {
|
|
984 }
|
|
985 //char[] typeNameString = typeName;
|
|
986 char[] info;
|
|
987 // int index = typeName.lastIndexOf('.');
|
|
988 // if (index !is -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1);
|
|
989 // char[] info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : ""));
|
|
990 // if (isArray) {
|
|
991 // typeNameString += "[]";
|
|
992 // }
|
|
993 // return ControlExample.getResourceString("Parameter_Info", [typeNameString, info]);
|
|
994
|
|
995 return Format( ControlExample.getResourceString("Parameter_Info"), typeNameString, info );
|
|
996 }
|
|
997
|
|
998 void getValue() {
|
|
999 //PORTING_LEFT
|
|
1000 /+
|
|
1001 char[] methodName = "get" + nameCombo.getText();
|
|
1002 getText.setText("");
|
|
1003 Widget[] widgets = getExampleWidgets();
|
|
1004 for (int i = 0; i < widgets.length; i++) {
|
|
1005 try {
|
|
1006 java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null);
|
|
1007 Object result = method.invoke(widgets[i], null);
|
|
1008 if (result is null) {
|
|
1009 getText.append("null");
|
|
1010 } else if (result.getClass().isArray()) {
|
|
1011 int length = java.lang.reflect.Array.getLength(result);
|
|
1012 if (length is 0) {
|
|
1013 getText.append(result.getClass().getComponentType() + "[0]");
|
|
1014 }
|
|
1015 for (int j = 0; j < length; j++) {
|
|
1016 getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n");
|
|
1017 }
|
|
1018 } else {
|
|
1019 getText.append(result.toString());
|
|
1020 }
|
|
1021 } catch (Exception e) {
|
|
1022 getText.append(e.toString());
|
|
1023 }
|
|
1024 if (i + 1 < widgets.length) {
|
|
1025 getText.append("\n\n");
|
|
1026 }
|
|
1027 }
|
|
1028 +/
|
|
1029 }
|
|
1030
|
|
1031 private ReflectMethodInfo getMethodInfo( char[] methodName ){
|
|
1032 Widget[] widgets = getExampleWidgets();
|
|
1033 if( widgets.length is 0 ){
|
|
1034 Stdout.formatln( "getWidgets returns null in {}", this.classinfo.name );
|
|
1035 }
|
|
1036 if( auto rti = widgets[0].classinfo in reflectTypeInfos ){
|
|
1037 if( auto mthi = methodName in rti.methods ){
|
|
1038 return *mthi;
|
|
1039 }
|
|
1040 else{
|
|
1041 Stdout.formatln( "method unknown {} in type {} in {}", methodName, widgets[0].classinfo.name, this.classinfo.name );
|
|
1042 }
|
|
1043 }
|
|
1044 else{
|
|
1045 Stdout.formatln( "type unknown {} in {}", widgets[0].classinfo.name, this.classinfo.name );
|
|
1046 }
|
|
1047 }
|
|
1048
|
|
1049 TypeInfo getReturnType(char[] methodRoot) {
|
|
1050 char[] methodName = "get" ~ methodRoot;
|
|
1051 auto mthi = getMethodInfo( methodName );
|
|
1052 return mthi.returnType;
|
|
1053 }
|
|
1054
|
|
1055 void setValue() {
|
|
1056 //PORTING_LEFT
|
|
1057 /+
|
|
1058 /* The parameter type must be the same as the get method's return type */
|
|
1059 char[] methodRoot = nameCombo.getText();
|
|
1060 Class returnType = getReturnType(methodRoot);
|
|
1061 char[] methodName = setMethodName(methodRoot);
|
|
1062 char[] value = setText.getText();
|
|
1063 Widget[] widgets = getExampleWidgets();
|
|
1064 for (int i = 0; i < widgets.length; i++) {
|
|
1065 try {
|
|
1066 java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, [returnType]);
|
|
1067 char[] typeName = returnType.getName();
|
|
1068 Object[] parameter = null;
|
|
1069 if (typeName.equals("int")) {
|
|
1070 parameter = [new Integer(value)];
|
|
1071 } else if (typeName.equals("long")) {
|
|
1072 parameter = [new Long(value)];
|
|
1073 } else if (typeName.equals("char")) {
|
|
1074 parameter = [value.length() is 1 ? new Character(value.charAt(0)) : new Character('\0')];
|
|
1075 } else if (typeName.equals("bool")) {
|
|
1076 parameter = [new bool(value)];
|
|
1077 } else if (typeName.equals("java.lang.char[]")) {
|
|
1078 parameter = [value];
|
|
1079 } else if (typeName.equals("org.eclipse.swt.graphics.Point")) {
|
|
1080 char[] xy[] = split(value, ',');
|
|
1081 parameter = [new Point((new Integer(xy[0])).intValue(),(new Integer(xy[1])).intValue())];
|
|
1082 } else if (typeName.equals("[I")) {
|
|
1083 char[] strings[] = split(value, ',');
|
|
1084 int[] ints = new int[strings.length];
|
|
1085 for (int j = 0; j < strings.length; j++) {
|
|
1086 ints[j] = (new Integer(strings[j])).intValue();
|
|
1087 }
|
|
1088 parameter = [ints];
|
|
1089 } else if (typeName.equals("[Ljava.lang.char[];")) {
|
|
1090 parameter = [split(value, ',')];
|
|
1091 } else {
|
|
1092 parameter = parameterForType(typeName, value, widgets[i]);
|
|
1093 }
|
|
1094 method.invoke(widgets[i], parameter);
|
|
1095 } catch (Exception e) {
|
|
1096 getText.setText(e.toString());
|
|
1097 }
|
|
1098 }
|
|
1099 +/
|
|
1100 return null;
|
|
1101 }
|
|
1102
|
|
1103 Object[] parameterForType(char[] typeName, char[] value, Widget widget) {
|
|
1104 //PORTING_LEFT
|
|
1105 return null;
|
|
1106 //return [value];
|
|
1107 }
|
|
1108
|
|
1109 void createOrientationGroup () {
|
|
1110 /* Create Orientation group*/
|
|
1111 orientationGroup = new Group (controlGroup, DWT.NONE);
|
|
1112 orientationGroup.setLayout (new GridLayout());
|
|
1113 orientationGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
1114 orientationGroup.setText (ControlExample.getResourceString("Orientation"));
|
|
1115 defaultOrietationButton = new Button (orientationGroup, DWT.RADIO);
|
|
1116 defaultOrietationButton.setText (ControlExample.getResourceString("Default"));
|
|
1117 defaultOrietationButton.setSelection (true);
|
|
1118 ltrButton = new Button (orientationGroup, DWT.RADIO);
|
|
1119 ltrButton.setText ("DWT.LEFT_TO_RIGHT");
|
|
1120 rtlButton = new Button (orientationGroup, DWT.RADIO);
|
|
1121 rtlButton.setText ("DWT.RIGHT_TO_LEFT");
|
|
1122 }
|
|
1123
|
|
1124 /**
|
|
1125 * Creates the "Size" group. The "Size" group contains
|
|
1126 * controls that allow the user to change the size of
|
|
1127 * the example widgets.
|
|
1128 */
|
|
1129 void createSizeGroup () {
|
|
1130 /* Create the group */
|
|
1131 sizeGroup = new Group (controlGroup, DWT.NONE);
|
|
1132 sizeGroup.setLayout (new GridLayout());
|
|
1133 sizeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
1134 sizeGroup.setText (ControlExample.getResourceString("Size"));
|
|
1135
|
|
1136 /* Create the controls */
|
|
1137
|
|
1138 /*
|
|
1139 * The preferred size of a widget is the size returned
|
|
1140 * by widget.computeSize (DWT.DEFAULT, DWT.DEFAULT).
|
|
1141 * This size is defined on a widget by widget basis.
|
|
1142 * Many widgets will attempt to display their contents.
|
|
1143 */
|
|
1144 preferredButton = new Button (sizeGroup, DWT.RADIO);
|
|
1145 preferredButton.setText (ControlExample.getResourceString("Preferred"));
|
|
1146 tooSmallButton = new Button (sizeGroup, DWT.RADIO);
|
|
1147 tooSmallButton.setText ( Format( "{} X {}", TOO_SMALL_SIZE, TOO_SMALL_SIZE));
|
|
1148 smallButton = new Button(sizeGroup, DWT.RADIO);
|
|
1149 smallButton.setText (Format( "{} X {}", SMALL_SIZE, SMALL_SIZE));
|
|
1150 largeButton = new Button (sizeGroup, DWT.RADIO);
|
|
1151 largeButton.setText (Format( "{} X {}", LARGE_SIZE, LARGE_SIZE));
|
|
1152 fillHButton = new Button (sizeGroup, DWT.CHECK);
|
|
1153 fillHButton.setText (ControlExample.getResourceString("Fill_X"));
|
|
1154 fillVButton = new Button (sizeGroup, DWT.CHECK);
|
|
1155 fillVButton.setText (ControlExample.getResourceString("Fill_Y"));
|
|
1156
|
|
1157 /* Add the listeners */
|
|
1158 SelectionAdapter selectionListener = new class() SelectionAdapter {
|
|
1159 public void widgetSelected (SelectionEvent event) {
|
|
1160 setExampleWidgetSize ();
|
|
1161 }
|
|
1162 };
|
|
1163 preferredButton.addSelectionListener(selectionListener);
|
|
1164 tooSmallButton.addSelectionListener(selectionListener);
|
|
1165 smallButton.addSelectionListener(selectionListener);
|
|
1166 largeButton.addSelectionListener(selectionListener);
|
|
1167 fillHButton.addSelectionListener(selectionListener);
|
|
1168 fillVButton.addSelectionListener(selectionListener);
|
|
1169
|
|
1170 /* Set the default state */
|
|
1171 preferredButton.setSelection (true);
|
|
1172 }
|
|
1173
|
|
1174 /**
|
|
1175 * Creates the "Style" group. The "Style" group contains
|
|
1176 * controls that allow the user to change the style of
|
|
1177 * the example widgets. Changing a widget "Style" causes
|
|
1178 * the widget to be destroyed and recreated.
|
|
1179 */
|
|
1180 void createStyleGroup () {
|
|
1181 styleGroup = new Group (controlGroup, DWT.NONE);
|
|
1182 styleGroup.setLayout (new GridLayout ());
|
|
1183 styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false));
|
|
1184 styleGroup.setText (ControlExample.getResourceString("Styles"));
|
|
1185 }
|
|
1186
|
|
1187 /**
|
|
1188 * Creates the tab folder page.
|
|
1189 *
|
|
1190 * @param tabFolder org.eclipse.swt.widgets.TabFolder
|
|
1191 * @return the new page for the tab folder
|
|
1192 */
|
|
1193 Composite createTabFolderPage (TabFolder tabFolder) {
|
|
1194 /* Cache the shell and display. */
|
|
1195 shell = tabFolder.getShell ();
|
|
1196 display = shell.getDisplay ();
|
|
1197
|
|
1198 /* Create a two column page. */
|
|
1199 tabFolderPage = new Composite (tabFolder, DWT.NONE);
|
|
1200 tabFolderPage.setLayout (new GridLayout (2, false));
|
|
1201
|
|
1202 /* Create the "Example" and "Control" groups. */
|
|
1203 createExampleGroup ();
|
|
1204 createControlGroup ();
|
|
1205
|
|
1206 /* Create the "Listeners" group under the "Control" group. */
|
|
1207 createListenersGroup ();
|
|
1208
|
|
1209 /* Create and initialize the example and control widgets. */
|
|
1210 createExampleWidgets ();
|
|
1211 hookExampleWidgetListeners ();
|
|
1212 createControlWidgets ();
|
|
1213 createBackgroundModeGroup ();
|
|
1214 setExampleWidgetState ();
|
|
1215
|
|
1216 return tabFolderPage;
|
|
1217 }
|
|
1218
|
|
1219 void setExampleWidgetPopupMenu() {
|
|
1220 Control[] controls = getExampleControls();
|
|
1221 for (int i = 0; i < controls.length; i++) {
|
|
1222 Control control = controls [i];
|
|
1223 control.addListener(DWT.MenuDetect, new class(control) Listener {
|
|
1224 Control ctrl;
|
|
1225 this( Control ctrl ){ this.ctrl = ctrl; }
|
|
1226 public void handleEvent(Event event) {
|
|
1227 Menu menu = ctrl.getMenu();
|
|
1228 if (menu !is null && samplePopup) {
|
|
1229 menu.dispose();
|
|
1230 menu = null;
|
|
1231 }
|
|
1232 if (menu is null && popupMenuButton.getSelection()) {
|
|
1233 menu = new Menu(shell, DWT.POP_UP);
|
|
1234 MenuItem item = new MenuItem(menu, DWT.PUSH);
|
|
1235 item.setText("Sample popup menu item");
|
|
1236 specialPopupMenuItems(menu, event);
|
|
1237 ctrl.setMenu(menu);
|
|
1238 samplePopup = true;
|
|
1239 }
|
|
1240 }
|
|
1241 });
|
|
1242 }
|
|
1243 }
|
|
1244
|
|
1245 protected void specialPopupMenuItems(Menu menu, Event event) {
|
|
1246 }
|
|
1247
|
|
1248 /**
|
|
1249 * Disposes the "Example" widgets.
|
|
1250 */
|
|
1251 void disposeExampleWidgets () {
|
|
1252 Widget [] widgets = getExampleWidgets ();
|
|
1253 for (int i=0; i<widgets.length; i++) {
|
|
1254 widgets [i].dispose ();
|
|
1255 }
|
|
1256 }
|
|
1257
|
|
1258 Image colorImage (Color color) {
|
|
1259 Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
|
|
1260 GC gc = new GC(image);
|
|
1261 gc.setBackground(color);
|
|
1262 Rectangle bounds = image.getBounds();
|
|
1263 gc.fillRectangle(0, 0, bounds.width, bounds.height);
|
|
1264 gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK));
|
|
1265 gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
|
|
1266 gc.dispose();
|
|
1267 return image;
|
|
1268 }
|
|
1269
|
|
1270 Image fontImage (Font font) {
|
|
1271 Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
|
|
1272 GC gc = new GC(image);
|
|
1273 Rectangle bounds = image.getBounds();
|
|
1274 gc.setBackground(display.getSystemColor(DWT.COLOR_WHITE));
|
|
1275 gc.fillRectangle(0, 0, bounds.width, bounds.height);
|
|
1276 gc.setBackground(display.getSystemColor(DWT.COLOR_BLACK));
|
|
1277 gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
|
|
1278 FontData data[] = font.getFontData();
|
|
1279 int style = data[0].getStyle();
|
|
1280 switch (style) {
|
|
1281 case DWT.NORMAL:
|
|
1282 gc.drawLine(3, 3, 3, 8);
|
|
1283 gc.drawLine(4, 3, 7, 8);
|
|
1284 gc.drawLine(8, 3, 8, 8);
|
|
1285 break;
|
|
1286 case DWT.BOLD:
|
|
1287 gc.drawLine(3, 2, 3, 9);
|
|
1288 gc.drawLine(4, 2, 4, 9);
|
|
1289 gc.drawLine(5, 2, 7, 2);
|
|
1290 gc.drawLine(5, 3, 8, 3);
|
|
1291 gc.drawLine(5, 5, 7, 5);
|
|
1292 gc.drawLine(5, 6, 7, 6);
|
|
1293 gc.drawLine(5, 8, 8, 8);
|
|
1294 gc.drawLine(5, 9, 7, 9);
|
|
1295 gc.drawLine(7, 4, 8, 4);
|
|
1296 gc.drawLine(7, 7, 8, 7);
|
|
1297 break;
|
|
1298 case DWT.ITALIC:
|
|
1299 gc.drawLine(6, 2, 8, 2);
|
|
1300 gc.drawLine(7, 3, 4, 8);
|
|
1301 gc.drawLine(3, 9, 5, 9);
|
|
1302 break;
|
|
1303 case DWT.BOLD | DWT.ITALIC:
|
|
1304 gc.drawLine(5, 2, 8, 2);
|
|
1305 gc.drawLine(5, 3, 8, 3);
|
|
1306 gc.drawLine(6, 4, 4, 7);
|
|
1307 gc.drawLine(7, 4, 5, 7);
|
|
1308 gc.drawLine(3, 8, 6, 8);
|
|
1309 gc.drawLine(3, 9, 6, 9);
|
|
1310 break;
|
|
1311 }
|
|
1312 gc.dispose();
|
|
1313 return image;
|
|
1314 }
|
|
1315
|
|
1316 /**
|
|
1317 * Gets the list of custom event names.
|
|
1318 *
|
|
1319 * @return an array containing custom event names
|
|
1320 */
|
|
1321 char[] [] getCustomEventNames () {
|
|
1322 return null;
|
|
1323 }
|
|
1324
|
|
1325 /**
|
|
1326 * Gets the default style for a widget
|
|
1327 *
|
|
1328 * @return the default style bit
|
|
1329 */
|
|
1330 int getDefaultStyle () {
|
|
1331 if (ltrButton !is null && ltrButton.getSelection()) {
|
|
1332 return DWT.LEFT_TO_RIGHT;
|
|
1333 }
|
|
1334 if (rtlButton !is null && rtlButton.getSelection()) {
|
|
1335 return DWT.RIGHT_TO_LEFT;
|
|
1336 }
|
|
1337 return DWT.NONE;
|
|
1338 }
|
|
1339
|
|
1340 /**
|
|
1341 * Gets the "Example" widgets.
|
|
1342 *
|
|
1343 * @return an array containing the example widgets
|
|
1344 */
|
|
1345 Widget [] getExampleWidgets () {
|
|
1346 return null;
|
|
1347 }
|
|
1348
|
|
1349 /**
|
|
1350 * Gets the "Example" controls.
|
|
1351 * This is the subset of "Example" widgets that are controls.
|
|
1352 *
|
|
1353 * @return an array containing the example controls
|
|
1354 */
|
|
1355 Control [] getExampleControls () {
|
|
1356 Widget [] widgets = getExampleWidgets ();
|
|
1357 Control [] controls = new Control [0];
|
|
1358 for (int i = 0; i < widgets.length; i++) {
|
|
1359 if ( auto ctrl = cast(Control)widgets[i]) {
|
|
1360 Control[] newControls = new Control[controls.length + 1];
|
|
1361 System.arraycopy(controls, 0, newControls, 0, controls.length);
|
|
1362 controls = newControls;
|
|
1363 controls[controls.length - 1] = ctrl;
|
|
1364 }
|
|
1365 }
|
|
1366 return controls;
|
|
1367 }
|
|
1368
|
|
1369 /**
|
|
1370 * Gets the "Example" widget children's items, if any.
|
|
1371 *
|
|
1372 * @return an array containing the example widget children's items
|
|
1373 */
|
|
1374 Item [] getExampleWidgetItems () {
|
|
1375 return new Item [0];
|
|
1376 }
|
|
1377
|
|
1378 /**
|
|
1379 * Gets the short text for the tab folder item.
|
|
1380 *
|
|
1381 * @return the short text for the tab item
|
|
1382 */
|
|
1383 char[] getShortTabText() {
|
|
1384 return getTabText();
|
|
1385 }
|
|
1386
|
|
1387 /**
|
|
1388 * Gets the text for the tab folder item.
|
|
1389 *
|
|
1390 * @return the text for the tab item
|
|
1391 */
|
|
1392 char[] getTabText () {
|
|
1393 return "";
|
|
1394 }
|
|
1395
|
|
1396 /**
|
|
1397 * Hooks all listeners to all example controls
|
|
1398 * and example control items.
|
|
1399 */
|
|
1400 void hookExampleWidgetListeners () {
|
|
1401 if (logging) {
|
|
1402 Widget[] widgets = getExampleWidgets ();
|
|
1403 for (int i = 0; i < widgets.length; i++) {
|
|
1404 hookListeners (widgets [i]);
|
|
1405 }
|
|
1406 Item[] exampleItems = getExampleWidgetItems ();
|
|
1407 for (int i = 0; i < exampleItems.length; i++) {
|
|
1408 hookListeners (exampleItems [i]);
|
|
1409 }
|
|
1410 char[] [] customNames = getCustomEventNames ();
|
|
1411 for (int i = 0; i < customNames.length; i++) {
|
|
1412 if (eventsFilter [EVENT_NAMES.length + i]) hookCustomListener (customNames[i]);
|
|
1413 }
|
|
1414 }
|
|
1415 }
|
|
1416
|
|
1417 /**
|
|
1418 * Hooks the custom listener specified by eventName.
|
|
1419 */
|
|
1420 void hookCustomListener (char[] eventName) {
|
|
1421 }
|
|
1422
|
|
1423 /**
|
|
1424 * Hooks all listeners to the specified widget.
|
|
1425 */
|
|
1426 void hookListeners (Widget widget) {
|
|
1427 if (logging) {
|
|
1428 Listener listener = new class() Listener {
|
|
1429 public void handleEvent (Event event) {
|
|
1430 log (event);
|
|
1431 }
|
|
1432 };
|
|
1433 for (int i = 0; i < EVENT_NAMES.length; i++) {
|
|
1434 if (eventsFilter [i]) widget.addListener ( EVENT_NAMES[i].id, listener);
|
|
1435 }
|
|
1436 }
|
|
1437 }
|
|
1438
|
|
1439 /**
|
|
1440 * Logs an untyped event to the event console.
|
|
1441 */
|
|
1442 void log(Event event) {
|
|
1443 int i = 0;
|
|
1444 while (i < EVENT_NAMES.length) {
|
|
1445 if (EVENT_NAMES[i].id is event.type) break;
|
|
1446 i++;
|
|
1447 }
|
|
1448 char[] str = Format( "{} [{}]: ", EVENT_NAMES[i].name, event.type );
|
|
1449 switch (event.type) {
|
|
1450 case DWT.KeyDown:
|
|
1451 case DWT.KeyUp: str ~= (new KeyEvent (event)).toString (); break;
|
|
1452 case DWT.MouseDown:
|
|
1453 case DWT.MouseUp:
|
|
1454 case DWT.MouseMove:
|
|
1455 case DWT.MouseEnter:
|
|
1456 case DWT.MouseExit:
|
|
1457 case DWT.MouseDoubleClick:
|
|
1458 case DWT.MouseWheel:
|
|
1459 case DWT.MouseHover: str ~= (new MouseEvent (event)).toString (); break;
|
|
1460 case DWT.Paint: str ~= (new PaintEvent (event)).toString (); break;
|
|
1461 case DWT.Move:
|
|
1462 case DWT.Resize: str ~= (new ControlEvent (event)).toString (); break;
|
|
1463 case DWT.Dispose: str ~= (new DisposeEvent (event)).toString (); break;
|
|
1464 case DWT.Selection:
|
|
1465 case DWT.DefaultSelection: str ~= (new SelectionEvent (event)).toString (); break;
|
|
1466 case DWT.FocusIn:
|
|
1467 case DWT.FocusOut: str ~= (new FocusEvent (event)).toString (); break;
|
|
1468 case DWT.Expand:
|
|
1469 case DWT.Collapse: str ~= (new TreeEvent (event)).toString (); break;
|
|
1470 case DWT.Iconify:
|
|
1471 case DWT.Deiconify:
|
|
1472 case DWT.Close:
|
|
1473 case DWT.Activate:
|
|
1474 case DWT.Deactivate: str ~=( new ShellEvent (event)).toString (); break;
|
|
1475 case DWT.Show:
|
|
1476 case DWT.Hide: str ~= ( null !is cast(Menu)event.widget) ? (new MenuEvent (event)).toString () : event.toString(); break;
|
|
1477 case DWT.Modify: str ~= (new ModifyEvent (event)).toString (); break;
|
|
1478 case DWT.Verify: str ~= (new VerifyEvent (event)).toString (); break;
|
|
1479 case DWT.Help: str ~= (new HelpEvent (event)).toString (); break;
|
|
1480 case DWT.Arm: str ~= (new ArmEvent (event)).toString (); break;
|
|
1481 case DWT.Traverse: str ~= (new TraverseEvent (event)).toString (); break;
|
|
1482 case DWT.HardKeyDown:
|
|
1483 case DWT.HardKeyUp:
|
|
1484 case DWT.DragDetect:
|
|
1485 case DWT.MenuDetect:
|
|
1486 case DWT.SetData:
|
|
1487 default: str ~= event.toString ();
|
|
1488 }
|
|
1489 eventConsole.append (str);
|
|
1490 eventConsole.append ("\n");
|
|
1491 }
|
|
1492
|
|
1493 /**
|
|
1494 * Logs a string to the event console.
|
|
1495 */
|
|
1496 void log (char[] string) {
|
|
1497 eventConsole.append (string);
|
|
1498 eventConsole.append ("\n");
|
|
1499 }
|
|
1500
|
|
1501 /**
|
|
1502 * Logs a typed event to the event console.
|
|
1503 */
|
|
1504 void log (char[] eventName, TypedEvent event) {
|
|
1505 eventConsole.append (eventName ~ ": ");
|
|
1506 eventConsole.append (event.toString ());
|
|
1507 eventConsole.append ("\n");
|
|
1508 }
|
|
1509
|
|
1510 /**
|
|
1511 * Recreates the "Example" widgets.
|
|
1512 */
|
|
1513 void recreateExampleWidgets () {
|
|
1514 disposeExampleWidgets ();
|
|
1515 createExampleWidgets ();
|
|
1516 hookExampleWidgetListeners ();
|
|
1517 setExampleWidgetState ();
|
|
1518 }
|
|
1519
|
|
1520 /**
|
|
1521 * Sets the foreground color, background color, and font
|
|
1522 * of the "Example" widgets to their default settings.
|
|
1523 * Subclasses may extend in order to reset other colors
|
|
1524 * and fonts to default settings as well.
|
|
1525 */
|
|
1526 void resetColorsAndFonts () {
|
|
1527 Color oldColor = foregroundColor;
|
|
1528 foregroundColor = null;
|
|
1529 setExampleWidgetForeground ();
|
|
1530 if (oldColor !is null) oldColor.dispose();
|
|
1531 oldColor = backgroundColor;
|
|
1532 backgroundColor = null;
|
|
1533 setExampleWidgetBackground ();
|
|
1534 if (oldColor !is null) oldColor.dispose();
|
|
1535 Font oldFont = font;
|
|
1536 font = null;
|
|
1537 setExampleWidgetFont ();
|
|
1538 setExampleWidgetSize ();
|
|
1539 if (oldFont !is null) oldFont.dispose();
|
|
1540 }
|
|
1541
|
|
1542 /**
|
|
1543 * Sets the background color of the "Example" widgets' parent.
|
|
1544 */
|
|
1545 void setExampleGroupBackgroundColor () {
|
|
1546 if (backgroundModeGroup is null) return;
|
|
1547 exampleGroup.setBackground (backgroundModeColorButton.getSelection () ? display.getSystemColor(DWT.COLOR_BLUE) : null);
|
|
1548 }
|
|
1549 /**
|
|
1550 * Sets the background image of the "Example" widgets' parent.
|
|
1551 */
|
|
1552 void setExampleGroupBackgroundImage () {
|
|
1553 if (backgroundModeGroup is null) return;
|
|
1554 exampleGroup.setBackgroundImage (backgroundModeImageButton.getSelection () ? instance.images[ControlExample.ciParentBackground] : null);
|
|
1555 }
|
|
1556
|
|
1557 /**
|
|
1558 * Sets the background mode of the "Example" widgets' parent.
|
|
1559 */
|
|
1560 void setExampleGroupBackgroundMode () {
|
|
1561 if (backgroundModeGroup is null) return;
|
|
1562 char[] modeString = backgroundModeCombo.getText ();
|
|
1563 int mode = DWT.INHERIT_NONE;
|
|
1564 if (modeString=="DWT.INHERIT_DEFAULT") mode = DWT.INHERIT_DEFAULT;
|
|
1565 if (modeString=="DWT.INHERIT_FORCE") mode = DWT.INHERIT_FORCE;
|
|
1566 exampleGroup.setBackgroundMode (mode);
|
|
1567 }
|
|
1568
|
|
1569 /**
|
|
1570 * Sets the background color of the "Example" widgets.
|
|
1571 */
|
|
1572 void setExampleWidgetBackground () {
|
|
1573 if (colorAndFontTable is null) return; // user cannot change color/font on this tab
|
|
1574 Control [] controls = getExampleControls ();
|
|
1575 if (!instance.startup) {
|
|
1576 for (int i = 0; i < controls.length; i++) {
|
|
1577 controls[i].setBackground (backgroundColor);
|
|
1578 }
|
|
1579 }
|
|
1580 // Set the background color item's image to match the background color of the example widget(s).
|
|
1581 Color color = backgroundColor;
|
|
1582 if (controls.length is 0) return;
|
|
1583 if (color is null) color = controls [0].getBackground ();
|
|
1584 TableItem item = colorAndFontTable.getItem(BACKGROUND_COLOR);
|
|
1585 Image oldImage = item.getImage();
|
|
1586 if (oldImage !is null) oldImage.dispose();
|
|
1587 item.setImage (colorImage (color));
|
|
1588 }
|
|
1589
|
|
1590 /**
|
|
1591 * Sets the enabled state of the "Example" widgets.
|
|
1592 */
|
|
1593 void setExampleWidgetEnabled () {
|
|
1594 Control [] controls = getExampleControls ();
|
|
1595 for (int i=0; i<controls.length; i++) {
|
|
1596 controls [i].setEnabled (enabledButton.getSelection ());
|
|
1597 }
|
|
1598 }
|
|
1599
|
|
1600 /**
|
|
1601 * Sets the font of the "Example" widgets.
|
|
1602 */
|
|
1603 void setExampleWidgetFont () {
|
|
1604 if (colorAndFontTable is null) return; // user cannot change color/font on this tab
|
|
1605 Control [] controls = getExampleControls ();
|
|
1606 if (!instance.startup) {
|
|
1607 for (int i = 0; i < controls.length; i++) {
|
|
1608 controls[i].setFont(font);
|
|
1609 }
|
|
1610 }
|
|
1611 /* Set the font item's image and font to match the font of the example widget(s). */
|
|
1612 Font ft = font;
|
|
1613 if (controls.length is 0) return;
|
|
1614 if (ft is null) ft = controls [0].getFont ();
|
|
1615 TableItem item = colorAndFontTable.getItem(FONT);
|
|
1616 Image oldImage = item.getImage();
|
|
1617 if (oldImage !is null) oldImage.dispose();
|
|
1618 item.setImage (fontImage (ft));
|
|
1619 item.setFont(ft);
|
|
1620 colorAndFontTable.layout ();
|
|
1621 }
|
|
1622
|
|
1623 /**
|
|
1624 * Sets the foreground color of the "Example" widgets.
|
|
1625 */
|
|
1626 void setExampleWidgetForeground () {
|
|
1627 if (colorAndFontTable is null) return; // user cannot change color/font on this tab
|
|
1628 Control [] controls = getExampleControls ();
|
|
1629 if (!instance.startup) {
|
|
1630 for (int i = 0; i < controls.length; i++) {
|
|
1631 controls[i].setForeground (foregroundColor);
|
|
1632 }
|
|
1633 }
|
|
1634 /* Set the foreground color item's image to match the foreground color of the example widget(s). */
|
|
1635 Color color = foregroundColor;
|
|
1636 if (controls.length is 0) return;
|
|
1637 if (color is null) color = controls [0].getForeground ();
|
|
1638 TableItem item = colorAndFontTable.getItem(FOREGROUND_COLOR);
|
|
1639 Image oldImage = item.getImage();
|
|
1640 if (oldImage !is null) oldImage.dispose();
|
|
1641 item.setImage (colorImage(color));
|
|
1642 }
|
|
1643
|
|
1644 /**
|
|
1645 * Sets the size of the "Example" widgets.
|
|
1646 */
|
|
1647 void setExampleWidgetSize () {
|
|
1648 int size = DWT.DEFAULT;
|
|
1649 if (preferredButton is null) return;
|
|
1650 if (preferredButton.getSelection()) size = DWT.DEFAULT;
|
|
1651 if (tooSmallButton.getSelection()) size = TOO_SMALL_SIZE;
|
|
1652 if (smallButton.getSelection()) size = SMALL_SIZE;
|
|
1653 if (largeButton.getSelection()) size = LARGE_SIZE;
|
|
1654 Control [] controls = getExampleControls ();
|
|
1655 for (int i=0; i<controls.length; i++) {
|
|
1656 GridData gridData = new GridData(size, size);
|
|
1657 gridData.grabExcessHorizontalSpace = fillHButton.getSelection();
|
|
1658 gridData.grabExcessVerticalSpace = fillVButton.getSelection();
|
|
1659 gridData.horizontalAlignment = fillHButton.getSelection() ? DWT.FILL : DWT.LEFT;
|
|
1660 gridData.verticalAlignment = fillVButton.getSelection() ? DWT.FILL : DWT.TOP;
|
|
1661 controls [i].setLayoutData (gridData);
|
|
1662 }
|
|
1663 tabFolderPage.layout (controls);
|
|
1664 }
|
|
1665
|
|
1666 /**
|
|
1667 * Sets the state of the "Example" widgets. Subclasses
|
|
1668 * reimplement this method to set "Example" widget state
|
|
1669 * that is specific to the widget.
|
|
1670 */
|
|
1671 void setExampleWidgetState () {
|
|
1672 setExampleWidgetBackground ();
|
|
1673 setExampleWidgetForeground ();
|
|
1674 setExampleWidgetFont ();
|
|
1675 if (!instance.startup) {
|
|
1676 setExampleWidgetEnabled ();
|
|
1677 setExampleWidgetVisibility ();
|
|
1678 setExampleGroupBackgroundMode ();
|
|
1679 setExampleGroupBackgroundColor ();
|
|
1680 setExampleGroupBackgroundImage ();
|
|
1681 setExampleWidgetBackgroundImage ();
|
|
1682 setExampleWidgetPopupMenu ();
|
|
1683 setExampleWidgetSize ();
|
|
1684 }
|
|
1685 //TEMPORARY CODE
|
|
1686 // Control [] controls = getExampleControls ();
|
|
1687 // for (int i=0; i<controls.length; i++) {
|
|
1688 // log ("Control=" + controls [i] + ", border width=" + controls [i].getBorderWidth ());
|
|
1689 // }
|
|
1690 }
|
|
1691
|
|
1692 /**
|
|
1693 * Sets the visibility of the "Example" widgets.
|
|
1694 */
|
|
1695 void setExampleWidgetVisibility () {
|
|
1696 Control [] controls = getExampleControls ();
|
|
1697 for (int i=0; i<controls.length; i++) {
|
|
1698 controls [i].setVisible (visibleButton.getSelection ());
|
|
1699 }
|
|
1700 }
|
|
1701
|
|
1702 /**
|
|
1703 * Sets the background image of the "Example" widgets.
|
|
1704 */
|
|
1705 void setExampleWidgetBackgroundImage () {
|
|
1706 Control [] controls = getExampleControls ();
|
|
1707 for (int i=0; i<controls.length; i++) {
|
|
1708 controls [i].setBackgroundImage (backgroundImageButton.getSelection () ? instance.images[ControlExample.ciBackground] : null);
|
|
1709 }
|
|
1710 }
|
|
1711
|
|
1712 /**
|
|
1713 * Splits the given string around matches of the given character.
|
|
1714 *
|
|
1715 * This subset of java.lang.String.split(String regex)
|
|
1716 * uses only code that can be run on CLDC platforms.
|
|
1717 */
|
|
1718 char[] [] split (char[] string, char ch) {
|
|
1719 char[] [] result = new char[][0];
|
|
1720 int start = 0;
|
|
1721 int length = string.length;
|
|
1722 while (start < length) {
|
|
1723 int end = tango.text.Util.locate( string, ch, start);
|
|
1724 if (end is string.length ) end = length;
|
|
1725 char[] substr = string[start .. end];
|
|
1726 char[] [] newResult = new char[][result.length + 1];
|
|
1727 System.arraycopy(result, 0, newResult, 0, result.length);
|
|
1728 newResult [result.length] = substr;
|
|
1729 result = newResult;
|
|
1730 start = end + 1;
|
|
1731 }
|
|
1732 return result;
|
|
1733 }
|
|
1734 }
|