Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 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 * D Port: | |
11 * Bill Baxter <wbaxter> at gmail com | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet21; | |
14 | |
15 /* | |
16 * Canvas example snippet: implement tab traversal (behave like a tab group) | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import org.eclipse.swt.SWT; | |
22 import org.eclipse.swt.graphics.Color; | |
23 import org.eclipse.swt.widgets.Display; | |
24 import org.eclipse.swt.widgets.Shell; | |
25 import org.eclipse.swt.widgets.Listener; | |
26 import org.eclipse.swt.widgets.Event; | |
27 import org.eclipse.swt.widgets.Button; | |
28 import org.eclipse.swt.widgets.Text; | |
29 import org.eclipse.swt.widgets.Canvas; | |
30 | |
112 | 31 version(Tango){ |
32 import tango.io.Stdout; | |
33 } else { // Phobos | |
34 import std.stdio; | |
35 } | |
28 | 36 |
37 import java.lang.all; | |
38 | |
39 void main () { | |
40 Display display = new Display (); | |
112 | 41 Color red = display.getSystemColor (SWT.COLOR_RED); |
42 Color blue = display.getSystemColor (SWT.COLOR_BLUE); | |
28 | 43 Shell shell = new Shell (display); |
44 Button b = new Button (shell, SWT.PUSH); | |
45 b.setBounds (10, 10, 100, 32); | |
46 b.setText ("Button"); | |
47 shell.setDefaultButton (b); | |
112 | 48 Canvas c = new Canvas (shell, SWT.BORDER); |
28 | 49 c.setBounds (10, 50, 100, 32); |
50 | |
51 void onTraverse(Event e, Canvas c) { | |
52 switch (e.detail) { | |
53 /* Do tab group traversal */ | |
54 case SWT.TRAVERSE_ESCAPE: | |
55 case SWT.TRAVERSE_RETURN: | |
56 case SWT.TRAVERSE_TAB_NEXT: | |
57 case SWT.TRAVERSE_TAB_PREVIOUS: | |
58 case SWT.TRAVERSE_PAGE_NEXT: | |
59 case SWT.TRAVERSE_PAGE_PREVIOUS: | |
60 e.doit = true; | |
61 break; | |
62 } | |
63 } | |
64 | |
65 void onFocusIn(Event e, Canvas c) { | |
66 c.setBackground (red); | |
67 } | |
68 | |
69 void onFocusOut(Event e, Canvas c) { | |
70 c.setBackground (blue); | |
71 } | |
72 | |
73 void onKeyDown (Event e, Canvas c) { | |
112 | 74 version(Tango){ |
75 Stdout("KEY").newline; | |
76 } else { // Phobos | |
77 writeln("KEY"); | |
78 } | |
28 | 79 for (int i=0; i<64; i++) { |
80 Color c1 = red, c2 = blue; | |
81 if (c.isFocusControl ()) { | |
82 c1 = blue; c2 = red; | |
83 } | |
84 c.setBackground (c1); | |
85 c.update (); | |
86 c.setBackground (c2); | |
87 } | |
88 } | |
89 | |
90 c.addListener (SWT.Traverse, dgListener(&onTraverse, c)); | |
91 c.addListener (SWT.FocusIn, dgListener(&onFocusIn, c)); | |
92 c.addListener (SWT.FocusOut, dgListener(&onFocusOut, c)); | |
93 c.addListener (SWT.KeyDown, dgListener(&onKeyDown, c)); | |
94 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
95 Text t = new Text (shell, SWT.SINGLE | SWT.BORDER); |
28 | 96 t.setBounds (10, 85, 100, 32); |
97 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
98 Text r = new Text (shell, SWT.MULTI | SWT.BORDER); |
28 | 99 r.setBounds (10, 120, 100, 32); |
100 | |
101 c.setFocus (); | |
102 shell.setSize (200, 200); | |
103 shell.open (); | |
104 while (!shell.isDisposed()) { | |
105 if (!display.readAndDispatch ()) display.sleep (); | |
106 } | |
107 display.dispose (); | |
108 } |