edu.northwestern.at.utils.swing
Class SwingUtils

java.lang.Object
  extended by edu.northwestern.at.utils.swing.SwingUtils

public class SwingUtils
extends java.lang.Object

Miscellaneous Swing utilities.

This static class provides various Swing utility methods.


Nested Class Summary
static class SwingUtils.ExitListener
          Quits application when main JFrame is closed.
protected  class SwingUtils.ExtendedEventQueue
           
 
Field Summary
static java.lang.Thread awtEventThread
          The AWT event thread.
 
Constructor Summary
protected SwingUtils()
          Can't instantiate but can override.
 
Method Summary
static javax.swing.JComponent buildLabelOrScrollingTextArea(java.lang.String str)
          Builds either a JLabel or a scrolling text area containing a string.
static javax.swing.JComponent buildScrollingStyledTextArea(StyledString str)
          Builds a scrolling styled text area containing a string.
static void closeFrame(java.awt.Frame frame)
          Close a frame.
static void flushAWTEventQueue()
          Flush the system event queue.
static java.lang.Thread getAWTEventThread()
          Get the AWT (and Swing) event thread.
static java.awt.Component getFocusedComponent(java.awt.Container parent)
          Get currently focused component given parent container.
static java.awt.Window getParentWindow(javax.swing.JComponent c)
          Get parent window for Swing component.
static javax.swing.JFrame openInJFrame(java.awt.Container content, javax.swing.JMenuBar menuBar, int width, int height, java.lang.String title, java.awt.Color backgroundColor, java.awt.event.WindowAdapter exitListener)
          Opens a container (JPanel, etc.) in a JFrame.
static java.lang.Object openInSwingFrame(javax.swing.JFrame frame, java.awt.Container content, javax.swing.JMenuBar menuBar, int width, int height, java.lang.String title, java.awt.Color backgroundColor, java.awt.event.WindowAdapter exitListener)
          Opens a container (JPanel, etc.) in an Swing frame.
static XFrame openInXFrame(java.awt.Container content, javax.swing.JMenuBar menuBar, int width, int height, java.lang.String title, java.awt.Color backgroundColor, java.awt.event.WindowAdapter exitListener)
          Opens a container (JPanel, etc.) in an XFrame.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

awtEventThread

public static java.lang.Thread awtEventThread
The AWT event thread. Set in first call to getAWTEventThread below.

Constructor Detail

SwingUtils

protected SwingUtils()
Can't instantiate but can override.

Method Detail

buildLabelOrScrollingTextArea

public static javax.swing.JComponent buildLabelOrScrollingTextArea(java.lang.String str)
Builds either a JLabel or a scrolling text area containing a string.

If the string 72 characters or less and does not contain a newline, it is wrapped in a JLabel and the JLabel is returned. Otherwise, it is wrapped in a non-editable text area with 6 rows, 72 columns, and a scroll bar and the JScrollPane is returned.

Parameters:
str - The string.

buildScrollingStyledTextArea

public static javax.swing.JComponent buildScrollingStyledTextArea(StyledString str)
Builds a scrolling styled text area containing a string.

Parameters:
str - The styled string.

closeFrame

public static void closeFrame(java.awt.Frame frame)
Close a frame.

Parameters:
frame - The frame (or JFrame) to close.

flushAWTEventQueue

public static void flushAWTEventQueue()
Flush the system event queue.


getAWTEventThread

public static java.lang.Thread getAWTEventThread()
Get the AWT (and Swing) event thread.

Returns:
The AWT event thread, or null if not available.

getFocusedComponent

public static java.awt.Component getFocusedComponent(java.awt.Container parent)
Get currently focused component given parent container.

Parameters:
parent - Parent container.
Returns:
The child component of parent with focus, or null if none has the focus.

getParentWindow

public static java.awt.Window getParentWindow(javax.swing.JComponent c)
Get parent window for Swing component.

Returns:
Parent window, or null if none.

openInSwingFrame

public static java.lang.Object openInSwingFrame(javax.swing.JFrame frame,
                                                java.awt.Container content,
                                                javax.swing.JMenuBar menuBar,
                                                int width,
                                                int height,
                                                java.lang.String title,
                                                java.awt.Color backgroundColor,
                                                java.awt.event.WindowAdapter exitListener)
Opens a container (JPanel, etc.) in an Swing frame.

Parameters:
frame - The frame to hold the content. If null, a new XFrame is allocated.
content - Content to place in JFrame.
menuBar - Menu bar for JFrame.
width - Width of JFrame.
height - Height of JFrame.
title - Title for JFrame.
backgroundColor - Background color for JFrame and content.
Returns:
The frame as an Object.

openInJFrame

public static javax.swing.JFrame openInJFrame(java.awt.Container content,
                                              javax.swing.JMenuBar menuBar,
                                              int width,
                                              int height,
                                              java.lang.String title,
                                              java.awt.Color backgroundColor,
                                              java.awt.event.WindowAdapter exitListener)
Opens a container (JPanel, etc.) in a JFrame.

Parameters:
content - Content to place in JFrame.
menuBar - Menu bar for JFrame.
width - Width of JFrame.
height - Height of JFrame.
title - Title for JFrame.
backgroundColor - Background color for JFrame and content.

openInXFrame

public static XFrame openInXFrame(java.awt.Container content,
                                  javax.swing.JMenuBar menuBar,
                                  int width,
                                  int height,
                                  java.lang.String title,
                                  java.awt.Color backgroundColor,
                                  java.awt.event.WindowAdapter exitListener)
Opens a container (JPanel, etc.) in an XFrame.

Parameters:
content - Content to place in JFrame.
menuBar - Menu bar for JFrame.
width - Width of JFrame.
height - Height of JFrame.
title - Title for JFrame.
backgroundColor - Background color for JFrame and content.
Returns:
The frame.