com.virtuosotechnologies.lib.swing
Class SwingUtils

java.lang.Object
  extended bycom.virtuosotechnologies.lib.swing.SwingUtils

public final class SwingUtils
extends Object

Various utilities for swing.


Method Summary
static KeyStroke buildAcceleratorKeyStroke(String spec)
          Build an accelerator keystroke.
static JDialog createJDialog(JComponent parent, String title, boolean modal)
          Create a new JDialog.
static int getIndexOfComponent(Container container, Component component)
          Get the index of the given component in the given container.
static boolean invokeOnSwingThread(Runnable job)
          Invoke a job on the awt/swing event thread.
static void invokeOnSwingThreadAsync(Runnable job)
          Invoke a job on the awt/swing event thread.
static boolean invokeOnSwingThreadSync(Runnable job)
          Invoke a job on the awt/swing event thread and wait until it is complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

invokeOnSwingThread

public static boolean invokeOnSwingThread(Runnable job)
Invoke a job on the awt/swing event thread. This is different from SwingUtilities.invokeLater() in that if the current thread is the AWT/Swing thread, it runs the job immediately rather than queuing another event.

Parameters:
job - Runnable job
Returns:
true if the job completed on the current thread, or false if it was queued for later

invokeOnSwingThreadAsync

public static void invokeOnSwingThreadAsync(Runnable job)
Invoke a job on the awt/swing event thread. This is identical to SwingUtilities.invokeLater() in that the job is queued for later execution even if the current thread is the AWT/Swing thread.

Parameters:
job - Runnable job

invokeOnSwingThreadSync

public static boolean invokeOnSwingThreadSync(Runnable job)
Invoke a job on the awt/swing event thread and wait until it is complete. This is different from SwingUtilities.invokeAndWait() in that it is okay to call this from the AWT/Swing thread: it will run the job in the current thread rather than attempting to queue an event.

Parameters:
job - Runnable job
Returns:
true if the job completed, or false if it was interrupted

getIndexOfComponent

public static int getIndexOfComponent(Container container,
                                      Component component)
Get the index of the given component in the given container. Returns -1 if the component is not in the container.

Parameters:
container - container to search
component - component to look for
Returns:
index of the component, or -1 if not found

createJDialog

public static JDialog createJDialog(JComponent parent,
                                    String title,
                                    boolean modal)
Create a new JDialog. Simulates a constructor Swing should have provided.


buildAcceleratorKeyStroke

public static KeyStroke buildAcceleratorKeyStroke(String spec)
Build an accelerator keystroke. The input string should be of the format: "[shift] ", similar to the KeyStroke parse format except that the only allowed modifier is "shift". This method will automatically add the platform- dependent modifier (ctrl for Windows/Linux, meta for Mac OS X).