Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130a.d @ 29:4e5843b771cc
First snippets buildable on windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 19:55:00 +0100 |
parents | 69b1fa94a4a8 |
children | 8ae65ae167f5 |
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 | |
36 import tango.core.Thread; | |
37 import tango.io.Stdout; | |
38 import tango.util.Convert; | |
39 import tango.util.log.Trace; | |
40 | |
41 | |
42 void main(String[] args){ | |
43 Snippet130.main(args); | |
44 } | |
45 | |
46 public class Snippet130 { | |
47 | |
48 public static void main(String[] args) { | |
49 Display display = new Display(); | |
50 Shell shell = new Shell(display); | |
51 shell.setLayout(new GridLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
52 Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); |
28 | 53 text.setLayoutData(new GridData(GridData.FILL_BOTH)); |
54 int[] nextId = new int[1]; | |
55 Button b = new Button(shell, SWT.PUSH); | |
56 b.setText("invoke long running job"); | |
57 | |
58 b.addSelectionListener(new class() SelectionAdapter { | |
59 public void widgetSelected(SelectionEvent e) { | |
60 Runnable longJob = new class() Runnable { | |
61 bool done = false; | |
62 int id; | |
63 public void run() { | |
64 Thread thread = new Thread({ | |
65 id = nextId[0]++; | |
66 display.syncExec( dgRunnable( &printStart, text, id )); | |
67 for (int i = 0; i < 6; i++) { | |
68 if (display.isDisposed()) return; | |
69 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i); | |
70 Thread.sleep(0.500); | |
71 } | |
72 /* | |
73 for (int i = 0; i < 100000; i++) { | |
74 if (display.isDisposed()) return; | |
75 Stdout.formatln("do task that takes a long time in a separate thread {}", id); | |
76 } | |
77 */ | |
78 if (display.isDisposed()) return; | |
79 display.syncExec( dgRunnable( &printEnd, text, id )); | |
80 done = true; | |
81 display.wake(); | |
82 }); // thread = ... | |
83 thread.start(); | |
84 | |
85 while (!done && !shell.isDisposed()) { | |
86 if (!display.readAndDispatch()) | |
87 display.sleep(); | |
88 } | |
89 } | |
90 }; // Runnable longJob = ... | |
91 BusyIndicator.showWhile(display, longJob); | |
92 } // widgetSelected(); | |
93 }); // addSelectionListener | |
94 | |
95 | |
96 shell.setSize(250, 150); | |
97 shell.open(); | |
98 while (!shell.isDisposed()) { | |
99 if (!display.readAndDispatch()) | |
100 display.sleep(); | |
101 } | |
102 display.dispose(); | |
103 } | |
104 private void printStart(Text text, int id ) { | |
105 if (text.isDisposed()) return; | |
106 Trace.formatln( "Start long running task {}", id ); | |
107 text.append("\nStart long running task "~to!(char[])(id)); | |
108 } | |
109 private void printEnd(Text text, int id ) { | |
110 if (text.isDisposed()) return; | |
111 Trace.formatln( "Completed long running task {}", id ); | |
112 text.append("\nCompleted long running task "~to!(char[])(id)); | |
113 } | |
114 } |