Mercurial > projects > dwt-samples
comparison snippets/display/Snippet146.d @ 132:104f5ed240fc
More snippets from TomD, thanks!
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 29 Jul 2008 01:50:10 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
130:5c1906bfc206 | 132:104f5ed240fc |
---|---|
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 display.Snippet146; | |
14 | |
15 /* | |
16 * UI Automation (for testing tools) snippet: post key events | |
17 * | |
18 * For a list of all DWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import dwt.DWT; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Event; | |
26 import dwt.widgets.Shell; | |
27 import dwt.widgets.Text; | |
28 | |
29 import dwt.dwthelper.utils; | |
30 | |
31 import tango.core.Thread; | |
32 import tango.text.Unicode; | |
33 | |
34 void main(String[] args) { | |
35 Display display = new Display(); | |
36 Shell shell = new Shell(display); | |
37 Text text = new Text(shell, DWT.BORDER); | |
38 text.setSize(text.computeSize(150, DWT.DEFAULT)); | |
39 shell.pack(); | |
40 shell.open(); | |
41 Thread thread = new Thread({ | |
42 String string = "Love the method."; | |
43 String lstring; | |
44 lstring. length = string.length; | |
45 toLower(string, lstring); | |
46 for (int i = 0; i < string.length; i++) { | |
47 char ch = string.charAt(i); | |
48 bool shift = isUpper(ch); | |
49 ch = lstring.charAt(i); | |
50 if (shift) { | |
51 Event event = new Event(); | |
52 event.type = DWT.KeyDown; | |
53 event.keyCode = DWT.SHIFT; | |
54 display.post(event); | |
55 } | |
56 Event event = new Event(); | |
57 event.type = DWT.KeyDown; | |
58 event.character = ch; | |
59 display.post(event); | |
60 try { | |
61 Thread.sleep(10/1000.); | |
62 } catch (InterruptedException e) {} | |
63 event.type = DWT.KeyUp; | |
64 display.post(event); | |
65 try { | |
66 Thread.sleep(100/1000.0); | |
67 } catch (InterruptedException e) {} | |
68 if (shift) { | |
69 event = new Event(); | |
70 event.type = DWT.KeyUp; | |
71 event.keyCode = DWT.SHIFT; | |
72 display.post(event); | |
73 } | |
74 } | |
75 }); | |
76 thread.start(); | |
77 while (!shell.isDisposed()) { | |
78 if (!display.readAndDispatch()) display.sleep(); | |
79 } | |
80 display.dispose(); | |
81 } | |
82 |