Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.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.Snippet142; | |
14 | |
15 /* | |
16 * UI Automation (for testing tools) snippet: post mouse 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.graphics.Point; | |
25 import org.eclipse.swt.widgets.Button; | |
26 import org.eclipse.swt.widgets.Display; | |
27 import org.eclipse.swt.widgets.Event; | |
28 import org.eclipse.swt.widgets.Listener; | |
29 import org.eclipse.swt.widgets.Shell; | |
30 | |
31 import java.lang.all; | |
32 | |
112 | 33 version(Tango){ |
34 //import tango.core.Thread; | |
35 import tango.io.Stdout; | |
36 } else { // Phobos | |
37 import std.stdio; | |
38 } | |
28 | 39 |
40 void main(String[] args) { | |
41 Display display = new Display(); | |
42 Shell shell = new Shell(display); | |
43 Button button = new Button(shell,SWT.NONE); | |
44 button.setSize(100,100); | |
45 button.setText("Click"); | |
46 shell.pack(); | |
47 shell.open(); | |
48 button.addListener(SWT.MouseDown, dgListener( (Event e){ | |
112 | 49 version(Tango){ |
50 Stdout.formatln("Mouse Down (Button: {} x: {} y: {})",e.button,e.x,e.y); | |
51 } else { // Phobos | |
52 writefln("Mouse Down (Button: %s x: %s y: %s)",e.button,e.x,e.y); | |
53 } | |
28 | 54 })); |
55 Point pt = display.map(shell, null, 50, 50); | |
56 Thread thread = new Thread({ | |
57 Event event; | |
58 try { | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
59 Thread.sleep(300); |
28 | 60 } catch (InterruptedException e) {} |
61 event = new Event(); | |
62 event.type = SWT.MouseMove; | |
63 event.x = pt.x; | |
64 event.y = pt.y; | |
65 display.post(event); | |
66 try { | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
67 Thread.sleep(300); |
28 | 68 } catch (InterruptedException e) {} |
69 event.type = SWT.MouseDown; | |
70 event.button = 1; | |
71 display.post(event); | |
72 try { | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
73 Thread.sleep(300); |
28 | 74 } catch (InterruptedException e) {} |
75 event.type = SWT.MouseUp; | |
76 display.post(event); | |
77 }); | |
78 thread.start(); | |
79 while (!shell.isDisposed()) { | |
80 if (!display.readAndDispatch()) display.sleep(); | |
81 } | |
82 display.dispose(); | |
83 } | |
84 |