Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.d @ 125:c43718956f21 default tip
Updated the snippets status.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 11 Aug 2011 19:55:14 +0200 |
parents | 536e43f63c81 |
children |
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; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
33 void writeln(in char[] line) { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
34 Stdout(line)("\n").flush(); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
35 } |
112 | 36 } else { // Phobos |
37 import std.stdio; | |
38 } | |
28 | 39 |
40 import java.lang.all; | |
41 | |
42 void main () { | |
43 Display display = new Display (); | |
112 | 44 Color red = display.getSystemColor (SWT.COLOR_RED); |
45 Color blue = display.getSystemColor (SWT.COLOR_BLUE); | |
28 | 46 Shell shell = new Shell (display); |
47 Button b = new Button (shell, SWT.PUSH); | |
48 b.setBounds (10, 10, 100, 32); | |
49 b.setText ("Button"); | |
50 shell.setDefaultButton (b); | |
112 | 51 Canvas c = new Canvas (shell, SWT.BORDER); |
28 | 52 c.setBounds (10, 50, 100, 32); |
53 | |
54 void onTraverse(Event e, Canvas c) { | |
55 switch (e.detail) { | |
56 /* Do tab group traversal */ | |
57 case SWT.TRAVERSE_ESCAPE: | |
58 case SWT.TRAVERSE_RETURN: | |
59 case SWT.TRAVERSE_TAB_NEXT: | |
60 case SWT.TRAVERSE_TAB_PREVIOUS: | |
61 case SWT.TRAVERSE_PAGE_NEXT: | |
62 case SWT.TRAVERSE_PAGE_PREVIOUS: | |
63 e.doit = true; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
64 default: |
28 | 65 } |
66 } | |
67 | |
68 void onFocusIn(Event e, Canvas c) { | |
69 c.setBackground (red); | |
70 } | |
71 | |
72 void onFocusOut(Event e, Canvas c) { | |
73 c.setBackground (blue); | |
74 } | |
75 | |
76 void onKeyDown (Event e, Canvas c) { | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
77 writeln("KEY"); |
28 | 78 for (int i=0; i<64; i++) { |
79 Color c1 = red, c2 = blue; | |
80 if (c.isFocusControl ()) { | |
81 c1 = blue; c2 = red; | |
82 } | |
83 c.setBackground (c1); | |
84 c.update (); | |
85 c.setBackground (c2); | |
86 } | |
87 } | |
88 | |
89 c.addListener (SWT.Traverse, dgListener(&onTraverse, c)); | |
90 c.addListener (SWT.FocusIn, dgListener(&onFocusIn, c)); | |
91 c.addListener (SWT.FocusOut, dgListener(&onFocusOut, c)); | |
92 c.addListener (SWT.KeyDown, dgListener(&onKeyDown, c)); | |
93 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
94 Text t = new Text (shell, SWT.SINGLE | SWT.BORDER); |
28 | 95 t.setBounds (10, 85, 100, 32); |
96 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
97 Text r = new Text (shell, SWT.MULTI | SWT.BORDER); |
28 | 98 r.setBounds (10, 120, 100, 32); |
99 | |
100 c.setFocus (); | |
101 shell.setSize (200, 200); | |
102 shell.open (); | |
103 while (!shell.isDisposed()) { | |
104 if (!display.readAndDispatch ()) display.sleep (); | |
105 } | |
106 display.dispose (); | |
107 } |