Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130a.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.Snippet130; | |
14 /* | |
15 * BusyIndicator example snippet: display busy cursor during long running task | |
16 * | |
17 * For a list of all SWT example snippets see | |
18 * http://www.eclipse.org/swt/snippets/ | |
19 */ | |
20 import org.eclipse.swt.SWT; | |
21 import org.eclipse.swt.events.SelectionAdapter; | |
22 import org.eclipse.swt.events.SelectionEvent; | |
23 import org.eclipse.swt.layout.GridLayout; | |
24 import org.eclipse.swt.layout.GridData; | |
25 import org.eclipse.swt.widgets.Shell; | |
26 import org.eclipse.swt.widgets.Button; | |
27 import org.eclipse.swt.widgets.Display; | |
28 import org.eclipse.swt.widgets.Shell; | |
29 import org.eclipse.swt.widgets.Text; | |
30 | |
31 | |
32 import org.eclipse.swt.custom.BusyIndicator; | |
33 | |
34 import java.lang.all; | |
35 | |
112 | 36 version(Tango){ |
37 //import tango.core.Thread; | |
38 import tango.io.Stdout; | |
39 import tango.util.Convert; | |
40 import tango.util.log.Trace; | |
41 } else { // Phobos | |
42 import std.conv; | |
43 import std.stdio; | |
44 } | |
28 | 45 |
46 | |
47 void main(String[] args){ | |
48 Snippet130.main(args); | |
49 } | |
50 | |
51 public class Snippet130 { | |
52 | |
53 public static void main(String[] args) { | |
54 Display display = new Display(); | |
55 Shell shell = new Shell(display); | |
56 shell.setLayout(new GridLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
57 Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); |
28 | 58 text.setLayoutData(new GridData(GridData.FILL_BOTH)); |
59 int[] nextId = new int[1]; | |
60 Button b = new Button(shell, SWT.PUSH); | |
61 b.setText("invoke long running job"); | |
62 | |
63 b.addSelectionListener(new class() SelectionAdapter { | |
64 public void widgetSelected(SelectionEvent e) { | |
65 Runnable longJob = new class() Runnable { | |
66 bool done = false; | |
67 int id; | |
68 public void run() { | |
69 Thread thread = new Thread({ | |
70 id = nextId[0]++; | |
71 display.syncExec( dgRunnable( &printStart, text, id )); | |
72 for (int i = 0; i < 6; i++) { | |
73 if (display.isDisposed()) return; | |
112 | 74 version(Tango){ |
75 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i); | |
76 } else { // Phobos | |
77 writefln("do task that takes a long time in a separate thread %s %s/6", id, i); | |
78 } | |
109
8ae65ae167f5
Updated swt win32 for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
79 Thread.sleep(500); |
28 | 80 } |
81 /* | |
82 for (int i = 0; i < 100000; i++) { | |
83 if (display.isDisposed()) return; | |
84 Stdout.formatln("do task that takes a long time in a separate thread {}", id); | |
85 } | |
86 */ | |
87 if (display.isDisposed()) return; | |
88 display.syncExec( dgRunnable( &printEnd, text, id )); | |
89 done = true; | |
90 display.wake(); | |
91 }); // thread = ... | |
92 thread.start(); | |
93 | |
94 while (!done && !shell.isDisposed()) { | |
95 if (!display.readAndDispatch()) | |
96 display.sleep(); | |
97 } | |
98 } | |
99 }; // Runnable longJob = ... | |
100 BusyIndicator.showWhile(display, longJob); | |
101 } // widgetSelected(); | |
102 }); // addSelectionListener | |
103 | |
104 | |
105 shell.setSize(250, 150); | |
106 shell.open(); | |
107 while (!shell.isDisposed()) { | |
108 if (!display.readAndDispatch()) | |
109 display.sleep(); | |
110 } | |
111 display.dispose(); | |
112 } | |
112 | 113 private static void printStart(Text text, int id ) { |
28 | 114 if (text.isDisposed()) return; |
112 | 115 version(Tango){ |
116 Trace.formatln( "Start long running task {}", id ); | |
117 } else { // Phobos | |
118 writefln( "Start long running task %s", id ); | |
119 } | |
120 text.append("\nStart long running task "~to!(String)(id)); | |
28 | 121 } |
112 | 122 private static void printEnd(Text text, int id ) { |
28 | 123 if (text.isDisposed()) return; |
112 | 124 version(Tango){ |
125 Trace.formatln( "Completed long running task {}", id ); | |
126 } else { // Phobos | |
127 writefln( "Completed long running task %s", id ); | |
128 } | |
129 text.append("\nCompleted long running task "~to!(String)(id)); | |
28 | 130 } |
131 } |