1 package snow.utils.gui; 2 3 import javax.swing.SwingUtilities ; 4 5 6 16 public class SwingSafeRunnable implements Runnable { 17 18 Runnable runnable; 19 boolean wait; 20 21 24 public SwingSafeRunnable(Runnable theRunnable, boolean doWait) { 25 runnable = theRunnable; 26 wait = doWait; 27 } 28 29 public void run() 30 { 31 try 32 { 33 if(SwingUtilities.isEventDispatchThread()) { 34 runnable.run(); 35 } 36 else 37 { 38 if(wait) 39 { 40 try { 41 SwingUtilities.invokeAndWait(runnable); 42 } 43 catch (InterruptedException iE) 44 { 45 iE.printStackTrace(); 46 } 47 catch (java.lang.reflect.InvocationTargetException iTE) 48 { 49 iTE.printStackTrace(); 50 } 51 } 52 else 53 SwingUtilities.invokeLater(runnable); 54 } 55 } 56 catch(Exception e) 57 { 58 e.printStackTrace(); 60 throw new RuntimeException (e.getMessage()); 61 } 62 } 63 64 65 } 66 | Popular Tags |