121
|
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.Snippet142;
|
|
14
|
|
15 /*
|
|
16 * UI Automation (for testing tools) snippet: post mouse 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.graphics.Point;
|
|
25 import dwt.widgets.Button;
|
|
26 import dwt.widgets.Display;
|
|
27 import dwt.widgets.Event;
|
|
28 import dwt.widgets.Listener;
|
|
29 import dwt.widgets.Shell;
|
|
30
|
|
31 import dwt.dwthelper.utils;
|
|
32
|
|
33 import tango.core.Thread;
|
|
34 import tango.io.Stdout;
|
|
35
|
|
36 void main(String[] args) {
|
|
37 Display display = new Display();
|
|
38 Shell shell = new Shell(display);
|
|
39 Button button = new Button(shell,DWT.NONE);
|
|
40 button.setSize(100,100);
|
|
41 button.setText("Click");
|
|
42 shell.pack();
|
|
43 shell.open();
|
|
44 button.addListener(DWT.MouseDown, dgListener( (Event e){
|
|
45 Stdout.formatln("Mouse Down (Button: {} x: {} y: {})",e.button,e.x,e.y);
|
|
46 }));
|
|
47 Point pt = display.map(shell, null, 50, 50);
|
|
48 Thread thread = new Thread({
|
|
49 Event event;
|
|
50 try {
|
|
51 Thread.sleep(300/1000.);
|
|
52 } catch (InterruptedException e) {}
|
|
53 event = new Event();
|
|
54 event.type = DWT.MouseMove;
|
|
55 event.x = pt.x;
|
|
56 event.y = pt.y;
|
|
57 display.post(event);
|
|
58 try {
|
|
59 Thread.sleep(300/1000.0);
|
|
60 } catch (InterruptedException e) {}
|
|
61 event.type = DWT.MouseDown;
|
|
62 event.button = 1;
|
|
63 display.post(event);
|
|
64 try {
|
|
65 Thread.sleep(300/1000.0);
|
|
66 } catch (InterruptedException e) {}
|
|
67 event.type = DWT.MouseUp;
|
|
68 display.post(event);
|
|
69 });
|
|
70 thread.start();
|
|
71 while (!shell.isDisposed()) {
|
|
72 if (!display.readAndDispatch()) display.sleep();
|
|
73 }
|
|
74 display.dispose();
|
|
75 }
|
|
76
|