edu.iastate.utils.gui
Class GUIUtils

java.lang.Object
  extended byedu.iastate.utils.gui.GUIUtils

public class GUIUtils
extends java.lang.Object

Common GUI utilities accessed via static methods.

Author:
Colin Bell

Nested Class Summary
static class GUIUtils.ColumnSorter
          This comparator is used to sort vectors of data
 
Constructor Summary
GUIUtils()
           
 
Method Summary
private static void center(java.awt.Component wind, java.awt.Rectangle rect)
          Centers wind within the passed rectangle.
static void centerWithinDesktop(javax.swing.JInternalFrame frame)
          Centers passed internal frame within its desktop area.
static void centerWithinParent(java.awt.Window wind)
          Centers wind within its parent.
static void centerWithinScreen(java.awt.Window wind)
          Centers wind within the screen.
static void deiconify(java.awt.Frame frame)
           
static javax.swing.JInternalFrame[] getNonMinimizedNonToolWindows(javax.swing.JInternalFrame[] frames)
          Return an array containing all JInternalFrame objects that were passed in frames that are not tool windows.
static javax.swing.JInternalFrame[] getOpenNonToolWindows(javax.swing.JInternalFrame[] frames)
          Return an array containing all JInternalFrame objects that were passed in frames that are not tool windows.
static javax.swing.JInternalFrame[] getOpenToolWindows(javax.swing.JInternalFrame[] frames)
          Return an array containing all JInternalFrame objects that were passed in frames that are tool windows.
static java.awt.Frame getOwningFrame(java.awt.Component comp)
          Return the owning Frame for the passed component of null if it doesn't have one.
static javax.swing.JFrame getRootFrame(java.awt.Component control)
          Get the root JFrame
static void iconify(java.awt.Frame frame)
           
static boolean isToolWindow(javax.swing.JInternalFrame frame)
          Return true if frame is a tool window.
static boolean isWithinParent(java.awt.Component wind)
           
static javax.swing.Icon loadIcon(java.lang.String filename)
          Load an icon from a image file eg: GUIUtils.loadIcon("images/semanticwww.gif"); the image file should be in the same jar file or under relative folder
static java.awt.Image loadImage(java.lang.String filename)
          Load an image
static void makeToolWindow(javax.swing.JInternalFrame frame, boolean isToolWindow)
          Make the passed internal frame a Tool Window.
static void maximize(java.awt.Frame frame)
           
static void minimize(java.awt.Frame frame)
           
static void setJButtonSizesTheSame(javax.swing.JButton[] btns)
          Change the sizes of all the passed buttons to be the size of the largest one.
static void showModally(javax.swing.JInternalFrame frame)
           
static void sortAllRowsBy(javax.swing.table.DefaultTableModel model, int colIndex, boolean ascending)
          Regardless of sort order (ascending or descending), null values always appear last.
static void updateComboBox(javax.swing.JComboBox theBox, java.lang.Object[] newdata)
          Update the content of a combo box, keep the old selection if possible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GUIUtils

public GUIUtils()
Method Detail

centerWithinParent

public static void centerWithinParent(java.awt.Window wind)
Centers wind within its parent. If it has no parent then center within the screen. If centering would cause the title bar to go above the parent (I.E. cannot see the titlebar and so cannot move the window) then move the window down.

Parameters:
wind - The Window to be centered.
Throws:
java.lang.IllegalArgumentException - If wind is null.

centerWithinDesktop

public static void centerWithinDesktop(javax.swing.JInternalFrame frame)
Centers passed internal frame within its desktop area. If centering would cause the title bar to go off the top of the screen then move the window down.

Parameters:
frame - The internal frame to be centered.
Throws:
java.lang.IllegalArgumentException - If frame is null.

centerWithinScreen

public static void centerWithinScreen(java.awt.Window wind)
Centers wind within the screen. If centering would cause the title bar to go off the top of the screen then move the window down.

Parameters:
wind - The Window to be centered.
Throws:
java.lang.IllegalArgumentException - If wind is null.

getOwningFrame

public static java.awt.Frame getOwningFrame(java.awt.Component comp)
Return the owning Frame for the passed component of null if it doesn't have one.

Throws:
java.lang.IllegalArgumentException - If wind is null.

isToolWindow

public static boolean isToolWindow(javax.swing.JInternalFrame frame)
Return true if frame is a tool window. I.E. is the JInternalFrame.isPalette set to Boolean.TRUE?

Parameters:
frame - The JInternalFrame to be checked.
Throws:
java.lang.IllegalArgumentException - If frame is null.

makeToolWindow

public static void makeToolWindow(javax.swing.JInternalFrame frame,
                                  boolean isToolWindow)
Make the passed internal frame a Tool Window.


setJButtonSizesTheSame

public static void setJButtonSizesTheSame(javax.swing.JButton[] btns)
Change the sizes of all the passed buttons to be the size of the largest one.

Parameters:
btns - Array of buttons to eb resized.
Throws:
java.lang.IllegalArgumentException - If btns is null.

getOpenToolWindows

public static javax.swing.JInternalFrame[] getOpenToolWindows(javax.swing.JInternalFrame[] frames)
Return an array containing all JInternalFrame objects that were passed in frames that are tool windows.

Parameters:
frames - JInternalFrame objects to be checked.

getOpenNonToolWindows

public static javax.swing.JInternalFrame[] getOpenNonToolWindows(javax.swing.JInternalFrame[] frames)
Return an array containing all JInternalFrame objects that were passed in frames that are not tool windows.

Parameters:
frames - JInternalFrame objects to be checked.

getNonMinimizedNonToolWindows

public static javax.swing.JInternalFrame[] getNonMinimizedNonToolWindows(javax.swing.JInternalFrame[] frames)
Return an array containing all JInternalFrame objects that were passed in frames that are not tool windows. and are not minimized.

Parameters:
frames - JInternalFrame objects to be checked.

isWithinParent

public static boolean isWithinParent(java.awt.Component wind)

showModally

public static void showModally(javax.swing.JInternalFrame frame)

center

private static void center(java.awt.Component wind,
                           java.awt.Rectangle rect)
Centers wind within the passed rectangle.

Parameters:
wind - The Window to be centered.
rect - The rectangle (in screen coords) to center wind within.
Throws:
java.lang.IllegalArgumentException - If Window or Rectangle is null.

sortAllRowsBy

public static void sortAllRowsBy(javax.swing.table.DefaultTableModel model,
                                 int colIndex,
                                 boolean ascending)
Regardless of sort order (ascending or descending), null values always appear last. colIndex specifies a column in model.


updateComboBox

public static void updateComboBox(javax.swing.JComboBox theBox,
                                  java.lang.Object[] newdata)
Update the content of a combo box, keep the old selection if possible

Parameters:
newdata - Object[]

loadIcon

public static javax.swing.Icon loadIcon(java.lang.String filename)
Load an icon from a image file eg: GUIUtils.loadIcon("images/semanticwww.gif"); the image file should be in the same jar file or under relative folder

Parameters:
filename - String
Returns:
Icon

loadImage

public static java.awt.Image loadImage(java.lang.String filename)
Load an image

Parameters:
filename - String
Returns:
Image

iconify

public static void iconify(java.awt.Frame frame)

deiconify

public static void deiconify(java.awt.Frame frame)

minimize

public static void minimize(java.awt.Frame frame)

maximize

public static void maximize(java.awt.Frame frame)

getRootFrame

public static javax.swing.JFrame getRootFrame(java.awt.Component control)
Get the root JFrame

Parameters:
control - Component
Returns:
JFrame
Since:
2005-03-27