Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet146.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 8ae65ae167f5 |
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 * Thomas Demmer <t_demmer AT web DOT de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet146; | |
14 | |
15 /* | |
16 * UI Automation (for testing tools) snippet: post key events | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.widgets.Display; | |
25 import org.eclipse.swt.widgets.Event; | |
26 import org.eclipse.swt.widgets.Shell; | |
27 import org.eclipse.swt.widgets.Text; | |
28 | |
29 import java.lang.all; | |
30 | |
112 | 31 version(Tango){ |
32 //import tango.core.Thread; | |
33 import tango.text.Unicode; | |
34 } else { | |
35 import std.string; | |
36 import std.uni; | |
37 alias isUniUpper isUpper; | |
38 } | |
28 | 39 |
40 void main(String[] args) { | |
41 Display display = new Display(); | |
42 Shell shell = new Shell(display); | |
43 Text text = new Text(shell, SWT.BORDER); | |
44 text.setSize(text.computeSize(150, SWT.DEFAULT)); | |
45 shell.pack(); | |
46 shell.open(); | |
47 Thread thread = new Thread({ | |
48 String string = "Love the method."; | |
49 String lstring; | |
112 | 50 version(Tango){ |
51 lstring. length = string.length; | |
52 toLower(string, lstring); | |
53 } else { | |
54 lstring = tolower(string); | |
55 } | |
28 | 56 for (int i = 0; i < string.length; i++) { |
57 char ch = string.charAt(i); | |
112 | 58 bool shift = cast(bool) isUpper(ch); |
28 | 59 ch = lstring.charAt(i); |
60 if (shift) { | |
61 Event event = new Event(); | |
62 event.type = SWT.KeyDown; | |
63 event.keyCode = SWT.SHIFT; | |
64 display.post(event); | |
65 } | |
66 Event event = new Event(); | |
67 event.type = SWT.KeyDown; | |
68 event.character = ch; | |
69 display.post(event); | |
70 try { | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
71 Thread.sleep(10); |
28 | 72 } catch (InterruptedException e) {} |
73 event.type = SWT.KeyUp; | |
74 display.post(event); | |
75 try { | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
76 Thread.sleep(100); |
28 | 77 } catch (InterruptedException e) {} |
78 if (shift) { | |
79 event = new Event(); | |
80 event.type = SWT.KeyUp; | |
81 event.keyCode = SWT.SHIFT; | |
82 display.post(event); | |
83 } | |
84 } | |
85 }); | |
86 thread.start(); | |
87 while (!shell.isDisposed()) { | |
88 if (!display.readAndDispatch()) display.sleep(); | |
89 } | |
90 display.dispose(); | |
91 } | |
92 |