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.Snippet268;
|
|
14
|
|
15 /*
|
|
16 * UI Automation (for testing tools) snippet: post mouse wheel events to a styled text
|
|
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.Listener;
|
|
27 import org.eclipse.swt.widgets.Shell;
|
|
28
|
|
29 import java.lang.all;
|
|
30
|
|
31 import org.eclipse.swt.custom.StyledText;
|
|
32 import org.eclipse.swt.graphics.Point;
|
|
33 import org.eclipse.swt.layout.FillLayout;
|
|
34
|
|
35 import tango.io.Stdout;
|
|
36 import tango.util.Convert;
|
|
37 import tango.core.Thread;
|
|
38
|
|
39 void main(String[] args) {
|
|
40 Display display = new Display();
|
|
41 Shell shell = new Shell(display);
|
|
42 shell.setLayout(new FillLayout());
|
|
43 StyledText styledText = new StyledText(shell, SWT.V_SCROLL);
|
|
44 String multiLineString = "";
|
|
45 for (int i = 0; i < 200; i++) {
|
|
46 multiLineString ~= "This is line number " ~ to!(String)(i) ~
|
|
47 " in the multi-line string.\n";
|
|
48 }
|
|
49 styledText.setText(multiLineString);
|
|
50 shell.setSize(styledText.computeSize(SWT.DEFAULT, 400));
|
|
51 shell.open();
|
|
52 styledText.addListener(SWT.MouseWheel, dgListener( (Event e){
|
|
53 Stdout.formatln("Mouse Wheel event \n"); //" + e);
|
|
54 Stdout.flush();
|
|
55 }));
|
|
56 final Point pt = display.map(shell, null, 50, 50);
|
|
57 Thread thread = new Thread({
|
|
58 Event event;
|
|
59 for (int i = 0; i < 50; i++) {
|
|
60 event = new Event();
|
|
61 event.type = SWT.MouseWheel;
|
|
62 event.detail = SWT.SCROLL_LINE;
|
|
63 event.x = pt.x;
|
|
64 event.y = pt.y;
|
|
65 event.count = -2;
|
|
66 display.post(event);
|
|
67 try {
|
|
68 Thread.sleep(400/1000);
|
|
69 } catch (InterruptedException e) {}
|
|
70 }
|
|
71 Stdout("Thread done\n").flush();
|
|
72 });
|
|
73
|
|
74 thread.start();
|
|
75 while (!shell.isDisposed()) {
|
|
76 if (!display.readAndDispatch()) display.sleep();
|
|
77 }
|
|
78 display.dispose();
|
|
79 }
|