1 package net.sf.panoptes.swing.cursor; 2 3 import java.awt.*; 4 import javax.swing.SwingUtilities ; 5 6 class DispatchedEvent { 7 private final Object mutex = new Object (); 8 private final Object source; 9 private Component parent; 10 private Cursor lastCursor; 11 12 public DispatchedEvent(Object source) { 13 this.source = source; 14 } 15 public void setCursor() { 16 synchronized (mutex) { 17 parent = findVisibleParent(); 18 if (parent != null) { 19 lastCursor = (parent.isCursorSet() ? parent.getCursor() : null); 20 parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 21 } 22 } 23 } 24 public boolean resetCursor() { 25 synchronized (mutex) { 26 if (parent != null) { 27 parent.setCursor(lastCursor); 28 parent = null; 29 return true; 30 } 31 return false; 32 } 33 } 34 private Component findVisibleParent() { 35 Component result = null; 36 if (source instanceof Component) { 37 result = SwingUtilities.getRoot((Component) source); 38 } else if (source instanceof MenuComponent) { 39 MenuContainer mParent = ((MenuComponent) source).getParent(); 40 if (mParent instanceof Component) { 41 result = SwingUtilities.getRoot((Component) mParent); 42 } 43 } 44 if ((result != null) && result.isVisible()) { 45 return result; 46 } else { 47 return null; 48 } 49 } 50 } | Popular Tags |