package textbender.o.awt; // Copyright 2001-2005, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.awt.EventQueue; //import java.lang.reflect.InvocationTargetException; /** EventQueue utilities. */ public final class EventQueueX { private EventQueueX() {} /** Invokes the runnable now, if called from the dispatch thread; * otherwise schedules it to be invoked in a later dispatch thread. */ public static void invokeNowOrLater( Runnable runnable ) { if( EventQueue.isDispatchThread() ) runnable.run(); else EventQueue.invokeLater( runnable ); } /** Invokes the runnable now, if called from the dispatch thread; * otherwise waits for a dispatch thread. * * @throws AssertionError if assertions are enabled, and an InterruptedException occurs * @throws RuntimeException if an InvocationTargetException occurs */ public static void invokeNowOrWait( Runnable runnable ) { if( EventQueue.isDispatchThread() ) runnable.run(); else tryInvokeAndWait( runnable ); } /** A version of invokeAndWait() that throws only unchecked exceptions. * * @throws RuntimeException nesting any InterruptedException * or InvocationTargetException that occurs */ public static void tryInvokeAndWait( Runnable runnable ) { try{ EventQueue.invokeAndWait( runnable ); } catch( RuntimeException xR ) { throw( xR ); } // catch( InterruptedException xI ) { assert false; } // ignore, unless debugging ///// ignore? not good catch( Exception x ) { throw new RuntimeException( x ); } // InterruptedException, InvocationTargetException // catch( InvocationTargetException xIT ) { throw new RuntimeException( xIT ); } } }