[Schmitzm-commits] r2373 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 26 17:12:46 CEST 2013
Author: mojays
Date: 2013-07-26 17:12:46 +0200 (Fri, 26 Jul 2013)
New Revision: 2373
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
SwingUtil.setWaitCursor()/.resetCursor(.): ensure that method is performed on EDT
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2013-07-26 14:53:45 UTC (rev 2372)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2013-07-26 15:12:46 UTC (rev 2373)
@@ -2785,7 +2785,9 @@
}
/**
- * Sets the cursor of the parent frame to {@link Cursor#WAIT_CURSOR}, to lock the frame.
+ * Sets the cursor of the parent frame to {@link Cursor#WAIT_CURSOR}, to lock the frame.<br>
+ * This method automatically ensures that it is called on EDT, so it can be called riskless
+ * from other treads.
* @param comp component to set the wait cursor for
*/
public static void setWaitCursor(Component comp) {
@@ -2793,12 +2795,14 @@
}
/**
- * Sets the cursor of the parent frame to {@link Cursor#WAIT_CURSOR}, to lock the frame.
+ * Sets the cursor of the parent frame to {@link Cursor#WAIT_CURSOR}, to lock the frame.<br>
+ * This method automatically ensures that it is called on EDT, so it can be called riskless
+ * from other treads.
* @param comp component to set the wait cursor for
* @param keyListener {@link KeyListener} to react on during wait cursor state (will
* be added to glass pane)
*/
- public static void setWaitCursor(Component comp, KeyListener keyListener) {
+ public static void setWaitCursor(final Component comp, final KeyListener keyListener) {
// // Original code taken from http://www.javaspecialists.eu/archive/Issue065.html
// // applicable for JComponent
// RootPaneContainer root = (RootPaneContainer)((JComponent)getContentPane()).getTopLevelAncestor();
@@ -2806,42 +2810,54 @@
// root.getGlassPane().addMouseListener(DUMMY_MOUSEADAPTER);
// root.getGlassPane().setVisible(true);
- RootPaneContainer rootPane = getParentRootPaneContainer(comp);
- if ( rootPane != null && rootPane.getContentPane() != null ) {
- rootPane.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- rootPane.getGlassPane().addMouseListener(DUMMY_MOUSEADAPTER);
- rootPane.getGlassPane().addFocusListener(DUMMY_FOCUSLISTENER);
- if ( keyListener != null ) {
- rootPane.getGlassPane().addKeyListener(keyListener);
- waitCursorKeyListenerCache.put(comp,keyListener);
+ invokeLater( new Runnable() {
+ @Override
+ public void run() {
+ RootPaneContainer rootPane = getParentRootPaneContainer(comp);
+ if ( rootPane != null && rootPane.getContentPane() != null ) {
+ rootPane.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ rootPane.getGlassPane().addMouseListener(DUMMY_MOUSEADAPTER);
+ rootPane.getGlassPane().addFocusListener(DUMMY_FOCUSLISTENER);
+ if ( keyListener != null ) {
+ rootPane.getGlassPane().addKeyListener(keyListener);
+ waitCursorKeyListenerCache.put(comp,keyListener);
+ }
+ rootPane.getGlassPane().setVisible(true);
+ rootPane.getGlassPane().requestFocusInWindow();
+ }
}
- rootPane.getGlassPane().setVisible(true);
- rootPane.getGlassPane().requestFocusInWindow();
- }
+ });
}
/**
* Sets the cursor of the parent frame to the default cursor. A possible
* {@link KeyListener} which was added to the glass pane during
- * {@link #setWaitCursor(Component, KeyListener)} is automatically removed.
+ * {@link #setWaitCursor(Component, KeyListener)} is automatically removed.<br>
+ * This method automatically ensures that it is called on EDT, so it can be called riskless
+ * from other treads.
* @param comp component to reset the wait cursor for
*/
- public static void resetCursor(Component comp) {
+ public static void resetCursor(final Component comp) {
// // Original code taken from http://www.javaspecialists.eu/archive/Issue065.html
// // applicable for JComponent
// RootPaneContainer root = (RootPaneContainer)((JComponent)getContentPane()).getTopLevelAncestor();
// root.getGlassPane().setCursor(Cursor.getDefaultCursor());
// root.getGlassPane().removeMouseListener(DUMMY_MOUSEADAPTER);
// root.getGlassPane().setVisible(false);
- RootPaneContainer rootPane = getParentRootPaneContainer(comp);
- if ( rootPane != null && rootPane.getContentPane() != null ) {
- rootPane.getGlassPane().setCursor(Cursor.getDefaultCursor());
- rootPane.getGlassPane().removeMouseListener(DUMMY_MOUSEADAPTER);
- rootPane.getGlassPane().removeFocusListener(DUMMY_FOCUSLISTENER);
- KeyListener keyListener = waitCursorKeyListenerCache.remove(comp);
- rootPane.getGlassPane().removeKeyListener(keyListener); // no problem if listener is NULL!
- rootPane.getGlassPane().setVisible(false);
- }
+ invokeLater( new Runnable() {
+ @Override
+ public void run() {
+ RootPaneContainer rootPane = getParentRootPaneContainer(comp);
+ if ( rootPane != null && rootPane.getContentPane() != null ) {
+ rootPane.getGlassPane().setCursor(Cursor.getDefaultCursor());
+ rootPane.getGlassPane().removeMouseListener(DUMMY_MOUSEADAPTER);
+ rootPane.getGlassPane().removeFocusListener(DUMMY_FOCUSLISTENER);
+ KeyListener keyListener = waitCursorKeyListenerCache.remove(comp);
+ rootPane.getGlassPane().removeKeyListener(keyListener); // no problem if listener is NULL!
+ rootPane.getGlassPane().setVisible(false);
+ }
+ }
+ });
}
/**
More information about the Schmitzm-commits
mailing list