Mercurial > projects > dwt-mac
comparison dwt/custom/BusyIndicator.d @ 41:6337764516f1
Sync dwt/custom with dwt-linux (took copy of complete folder)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:29:55 +0200 |
parents | f565d3a95c0a |
children | 07399639c0c8 |
comparison
equal
deleted
inserted
replaced
40:fbe68c33eeee | 41:6337764516f1 |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | 10 * Port to the D programming language: |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 11 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 12 *******************************************************************************/ |
14 module dwt.custom.BusyIndicator; | 13 module dwt.custom.BusyIndicator; |
14 | |
15 | |
15 | 16 |
16 import dwt.DWT; | 17 import dwt.DWT; |
17 import dwt.graphics.Cursor; | 18 import dwt.graphics.Cursor; |
18 import dwt.widgets.Display; | 19 import dwt.widgets.Display; |
19 import dwt.widgets.Shell; | 20 import dwt.widgets.Shell; |
20 | |
21 import dwt.dwthelper.Runnable; | 21 import dwt.dwthelper.Runnable; |
22 import dwt.dwthelper.string; | 22 import dwt.dwthelper.utils; |
23 import dwt.dwthelper.utils : Integer; | |
24 | 23 |
25 /** | 24 /** |
26 * Support for showing a Busy Cursor during a long running process. | 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> | |
27 */ | 29 */ |
28 public class BusyIndicator { | 30 public class BusyIndicator { |
29 | 31 |
30 static int nextBusyId = 1; | 32 static int nextBusyId = 1; |
31 static final String BUSYID_NAME = "DWT BusyIndicator"; //$NON-NLS-1$ | 33 static const String BUSYID_NAME = "DWT BusyIndicator"; //$NON-NLS-1$ |
32 static final String BUSY_CURSOR = "DWT BusyIndicator Cursor"; //$NON-NLS-1$ | 34 static const String BUSY_CURSOR = "DWT BusyIndicator Cursor"; //$NON-NLS-1$ |
33 | 35 |
34 /** | 36 /** |
35 * Runs the given <code>Runnable</code> while providing | 37 * Runs the given <code>Runnable</code> while providing |
36 * busy feedback using this busy indicator. | 38 * busy feedback using this busy indicator. |
37 * | 39 * |
38 * @param display the display on which the busy feedback should be | 40 * @param display the display on which the busy feedback should be |
39 * displayed. If the display is null, the Display for the current | 41 * displayed. If the display is null, the Display for the current |
40 * thread will be used. If there is no Display for the current thread, | 42 * thread will be used. If there is no Display for the current thread, |
41 * the runnable code will be executed and no busy feedback will be displayed. | 43 * the runnable code will be executed and no busy feedback will be displayed. |
42 * @param runnable the runnable for which busy feedback is to be shown. | 44 * @param runnable the runnable for which busy feedback is to be shown. |
43 * Must not be null. | 45 * Must not be null. |
44 * | 46 * |
45 * @exception IllegalArgumentException <ul> | 47 * @exception IllegalArgumentException <ul> |
46 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> | 48 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> |
47 * </ul> | 49 * </ul> |
48 */ | 50 */ |
49 | 51 |
50 public static void showWhile (Display display, Runnable runnable) { | 52 public static void showWhile(Display display, Runnable runnable) { |
51 if (runnable is null) | 53 if (runnable is null) |
52 DWT.error(DWT.ERROR_NULL_ARGUMENT); | 54 DWT.error(DWT.ERROR_NULL_ARGUMENT); |
55 if (display is null) { | |
56 display = Display.getCurrent(); | |
53 if (display is null) { | 57 if (display is null) { |
54 display = Display.getCurrent(); | 58 runnable.run(); |
55 if (display is null) { | 59 return; |
56 runnable.run(); | |
57 return; | |
58 } | |
59 } | 60 } |
61 } | |
60 | 62 |
61 Integer busyId = new Integer(nextBusyId); | 63 Integer busyId = new Integer(nextBusyId); |
62 nextBusyId++; | 64 nextBusyId++; |
63 Cursor cursor = display.getSystemCursor(DWT.CURSOR_WAIT); | 65 Cursor cursor = display.getSystemCursor(DWT.CURSOR_WAIT); |
64 Shell[] shells = display.getShells(); | 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(); | |
65 for (int i = 0; i < shells.length; i++) { | 79 for (int i = 0; i < shells.length; i++) { |
66 Integer id = cast(Integer) shells[i].getData(BUSYID_NAME); | 80 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME); |
67 if (id is null) { | 81 if ( id !is null && id == busyId) { |
68 shells[i].setCursor(cursor); | 82 shells[i].setCursor(null); |
69 shells[i].setData(BUSYID_NAME, busyId); | 83 shells[i].setData(BUSYID_NAME, null); |
70 } | |
71 } | |
72 | |
73 try { | |
74 runnable.run(); | |
75 } | |
76 finally { | |
77 shells = display.getShells(); | |
78 for (int i = 0; i < shells.length; i++) { | |
79 Integer id = cast(Integer) shells[i].getData(BUSYID_NAME); | |
80 if (id is busyId) { | |
81 shells[i].setCursor(null); | |
82 shells[i].setData(BUSYID_NAME, null); | |
83 } | |
84 } | 84 } |
85 } | 85 } |
86 } | 86 } |
87 } | 87 } |
88 } |