comparison snippets/display/Snippet268.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.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 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.Listener;
27 import dwt.widgets.Shell;
28
29 import dwt.dwthelper.utils;
30
31 import dwt.custom.StyledText;
32 import dwt.graphics.Point;
33 import dwt.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, DWT.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(DWT.DEFAULT, 400));
51 shell.open();
52 styledText.addListener(DWT.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 = DWT.MouseWheel;
62 event.detail = DWT.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 }