1 11 package org.eclipse.swt.custom; 12 13 14 import org.eclipse.swt.*; 15 import org.eclipse.swt.graphics.*; 16 import org.eclipse.swt.widgets.*; 17 18 21 public class BusyIndicator { 22 23 static int nextBusyId = 1; 24 static final String BUSYID_NAME = "SWT BusyIndicator"; static final String BUSY_CURSOR = "SWT BusyIndicator Cursor"; 27 42 43 public static void showWhile(Display display, Runnable runnable) { 44 if (runnable == null) 45 SWT.error(SWT.ERROR_NULL_ARGUMENT); 46 if (display == null) { 47 display = Display.getCurrent(); 48 if (display == null) { 49 runnable.run(); 50 return; 51 } 52 } 53 54 Integer busyId = new Integer (nextBusyId); 55 nextBusyId++; 56 Cursor cursor = display.getSystemCursor(SWT.CURSOR_WAIT); 57 Shell[] shells = display.getShells(); 58 for (int i = 0; i < shells.length; i++) { 59 Integer id = (Integer )shells[i].getData(BUSYID_NAME); 60 if (id == null) { 61 shells[i].setCursor(cursor); 62 shells[i].setData(BUSYID_NAME, busyId); 63 } 64 } 65 66 try { 67 runnable.run(); 68 } finally { 69 shells = display.getShells(); 70 for (int i = 0; i < shells.length; i++) { 71 Integer id = (Integer )shells[i].getData(BUSYID_NAME); 72 if (id == busyId) { 73 shells[i].setCursor(null); 74 shells[i].setData(BUSYID_NAME, null); 75 } 76 } 77 } 78 } 79 } 80 | Popular Tags |