comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/BusyIndicator.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children 536e43f63c81
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.swt.custom.BusyIndicator;
14
15
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Cursor;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Shell;
21 import java.lang.Runnable;
22 import java.lang.all;
23
24 /**
25 * Support for showing a Busy Cursor during a long running process.
26 *
27 * @see <a href="http://www.eclipse.org/swt/snippets/#busyindicator">BusyIndicator snippets</a>
28 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
29 */
30 public class BusyIndicator {
31
32 static int nextBusyId = 1;
33 static const String BUSYID_NAME = "SWT BusyIndicator"; //$NON-NLS-1$
34 static const String BUSY_CURSOR = "SWT BusyIndicator Cursor"; //$NON-NLS-1$
35
36 /**
37 * Runs the given <code>Runnable</code> while providing
38 * busy feedback using this busy indicator.
39 *
40 * @param display the display on which the busy feedback should be
41 * displayed. If the display is null, the Display for the current
42 * thread will be used. If there is no Display for the current thread,
43 * the runnable code will be executed and no busy feedback will be displayed.
44 * @param runnable the runnable for which busy feedback is to be shown.
45 * Must not be null.
46 *
47 * @exception IllegalArgumentException <ul>
48 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
49 * </ul>
50 */
51
52 public static void showWhile(Display display, Runnable runnable) {
53 if (runnable is null)
54 SWT.error(SWT.ERROR_NULL_ARGUMENT);
55 if (display is null) {
56 display = Display.getCurrent();
57 if (display is null) {
58 runnable.run();
59 return;
60 }
61 }
62
63 Integer busyId = new Integer(nextBusyId);
64 nextBusyId++;
65 Cursor cursor = display.getSystemCursor(SWT.CURSOR_WAIT);
66 Shell[] shells = display.getShells();
67 for (int i = 0; i < shells.length; i++) {
68 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME);
69 if (id is null) {
70 shells[i].setCursor(cursor);
71 shells[i].setData(BUSYID_NAME, busyId);
72 }
73 }
74
75 try {
76 runnable.run();
77 } finally {
78 shells = display.getShells();
79 for (int i = 0; i < shells.length; i++) {
80 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME);
81 if ( id !is null && id == busyId) {
82 shells[i].setCursor(null);
83 shells[i].setData(BUSYID_NAME, null);
84 }
85 }
86 }
87 }
88 }