Mercurial > projects > dwt-linux
annotate dwt/custom/BusyIndicator.d @ 223:d0081b1505da
dwt.dwthelper restructure
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Apr 2008 08:58:40 +0200 |
parents | d5b1c263ee37 |
children | 380bad9f6852 |
rev | line source |
---|---|
113
1401263f71b0
renamed setCursor(Gtk..) to gtk_setCursor, so the public interface do not need a cast for passing null
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
98
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 * |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 * Contributors: |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
108 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
98
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 *******************************************************************************/ |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 module dwt.custom.BusyIndicator; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
15 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 import dwt.DWT; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 import dwt.graphics.Cursor; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 import dwt.widgets.Display; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
20 import dwt.widgets.Shell; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 import dwt.dwthelper.Runnable; |
217 | 22 import dwt.dwthelper.utils; |
98
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 /** |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 * Support for showing a Busy Cursor during a long running process. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 */ |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 public class BusyIndicator { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 static int nextBusyId = 1; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 static const char[] BUSYID_NAME = "DWT BusyIndicator"; //$NON-NLS-1$ |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
31 static const char[] BUSY_CURSOR = "DWT BusyIndicator Cursor"; //$NON-NLS-1$ |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 /** |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 * Runs the given <code>Runnable</code> while providing |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 * busy feedback using this busy indicator. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
36 * |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 * @param display the display on which the busy feedback should be |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 * displayed. If the display is null, the Display for the current |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 * thread will be used. If there is no Display for the current thread, |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 * the runnable code will be executed and no busy feedback will be displayed. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 * @param runnable the runnable for which busy feedback is to be shown. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 * Must not be null. |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 * |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
44 * @exception IllegalArgumentException <ul> |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 * </ul> |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 */ |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 public static void showWhile(Display display, Runnable runnable) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 if (runnable is null) |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 DWT.error(DWT.ERROR_NULL_ARGUMENT); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 if (display is null) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 display = Display.getCurrent(); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 if (display is null) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 runnable.run(); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 return; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 Integer busyId = new Integer(nextBusyId); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 nextBusyId++; |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 Cursor cursor = display.getSystemCursor(DWT.CURSOR_WAIT); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 Shell[] shells = display.getShells(); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 for (int i = 0; i < shells.length; i++) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
65 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
66 if (id is null) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 shells[i].setCursor(cursor); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 shells[i].setData(BUSYID_NAME, busyId); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
69 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
70 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
71 |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
72 try { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
73 runnable.run(); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
74 } finally { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
75 shells = display.getShells(); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
76 for (int i = 0; i < shells.length; i++) { |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
77 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
78 if ( id !is null && id == busyId) { |
113
1401263f71b0
renamed setCursor(Gtk..) to gtk_setCursor, so the public interface do not need a cast for passing null
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
79 shells[i].setCursor(null); |
98
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
80 shells[i].setData(BUSYID_NAME, null); |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
81 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
82 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
83 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
84 } |
bf44a537c2e9
BidiSegmentListener, BusyIndicator
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
85 } |