net.wotonomy.ui.swing.util
Class WindowUtilities

java.lang.Object
  extended by net.wotonomy.ui.swing.util.WindowUtilities

public class WindowUtilities
extends java.lang.Object

A collection of window-related utilities.

Version:
$Revision: 904 $ $Date: 2006-02-18 23:19:05 +0000 (Sat, 18 Feb 2006) $
Author:
michael@mpowers.net, $Author: cgruber $

Field Summary
static int CASCADE
          Place lower and to the right of the last window placed in this manner.
static int CENTER
          Place frame at center (vertically and horizontally) of screen.
static int CENTER_PARENT
          Center dialog on frame area of parent, if any.
 
Constructor Summary
WindowUtilities()
           
 
Method Summary
protected static void addAllChildComponents(java.awt.Container aContainer, java.util.Collection aCollection)
          Adds all children of the specified container to the specified collection.
static void cascade(java.awt.Window aWindow)
          Place lower and to the right of the last window placed in this manner.
static void center(java.awt.Window aWindow)
          Place the window in the center of the screen.
static void dumpComponents(java.awt.Container aContainer)
          Prints out a list of all components to System.out.
protected static void dumpComponents(java.awt.Container aContainer, java.lang.String padding)
           
static void dumpNamedChildComponents(java.awt.Container aContainer)
           
static void dumpSortedChildComponents(java.awt.Container aContainer)
           
static void enableComponents(java.awt.Container aContainer, boolean isEnabled)
          Sets the enabled state of a container and all of its components.
static java.util.Collection getAllChildComponents(java.awt.Container aContainer)
          Gets all children of the specified container.
static java.util.Map getComponentToNameMap(java.awt.Container aContainer)
          Generates a deterministically unique name for each component in a container.
static java.util.Map getNameToComponentMap(java.awt.Container aContainer)
          Maps a deterministically unique name to a component in a container.
static java.util.List getSortedChildComponents(java.awt.Container aContainer)
          Gets a list of all children of a specified container, sorted by position.
static java.util.Map getUniqueNameMap(java.util.List anObjectList)
          Generates a unique name for each object in a list and returns a map that maps the objects to the names.
static java.awt.Window getWindowForComponent(java.awt.Component c)
          Returns the first parent Window of the specified component.
static java.lang.String incrementString(java.lang.String aString)
          Numerically increments a string.
static void labelComponents(java.awt.Container aContainer)
          Sets each child component's tooltip to show the name generated from getComponentNameMap().
static void labelComponents(java.awt.Container aContainer, java.util.Map aNameMap)
          Sets each child component's tooltip to show a given string retrieved from a map using the component's generated name as a key.
static void nameComponents(java.awt.Container aContainer)
          Sets the tooltips of all components in a container to the respective names of those components.
protected static void nameComponents(java.awt.Container aContainer, java.lang.String path)
           
static void place(java.awt.Window aWindow, int location)
          Place the window in the specified location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER
Place frame at center (vertically and horizontally) of screen.

See Also:
Constant Field Values

CENTER_PARENT

public static final int CENTER_PARENT
Center dialog on frame area of parent, if any.

See Also:
Constant Field Values

CASCADE

public static final int CASCADE
Place lower and to the right of the last window placed in this manner. Will wrap to top and left of screen as necessary.

See Also:
Constant Field Values
Constructor Detail

WindowUtilities

public WindowUtilities()
Method Detail

center

public static void center(java.awt.Window aWindow)
Place the window in the center of the screen. Note: don't forget to first set the size of your window. This is a convenience method and simply calls place() with the CENTER parameter.

Parameters:
aWindow - The window to be centered.
See Also:
place(java.awt.Window, int)

cascade

public static void cascade(java.awt.Window aWindow)
Place lower and to the right of the last window placed in this manner. Will wrap to top and left of screen as necessary. This is a convenience method and simply calls place() with the CASCADE parameter.

Parameters:
aWindow - The window to be cascaded.
See Also:
place(java.awt.Window, int)

place

public static void place(java.awt.Window aWindow,
                         int location)
Place the window in the specified location. Note: don't forget to first set the size of your window.

Parameters:
aWindow - The window to be placed.
location - Where on screen to place the frame.

getWindowForComponent

public static java.awt.Window getWindowForComponent(java.awt.Component c)
Returns the first parent Window of the specified component.

Parameters:
c - the Component whose parent will be found.
Returns:
the Window that contains the component, or null if the component does not have a valid Frame parent.

dumpComponents

public static void dumpComponents(java.awt.Container aContainer)
Prints out a list of all components to System.out.

Parameters:
aContainer - the Container whose components will be listed.

dumpComponents

protected static void dumpComponents(java.awt.Container aContainer,
                                     java.lang.String padding)

getSortedChildComponents

public static java.util.List getSortedChildComponents(java.awt.Container aContainer)
Gets a list of all children of a specified container, sorted by position. Components are sorted from top to bottom and then left to right.

Parameters:
aContainer - The container whose children are to be returned.

dumpSortedChildComponents

public static void dumpSortedChildComponents(java.awt.Container aContainer)

dumpNamedChildComponents

public static void dumpNamedChildComponents(java.awt.Container aContainer)

getUniqueNameMap

public static java.util.Map getUniqueNameMap(java.util.List anObjectList)
Generates a unique name for each object in a list and returns a map that maps the objects to the names. The name is based on the class of the object in the object list.

Parameters:
anObjectList - A List of objects.
Returns:
A Map that maps the objects in the list to the generated names.

incrementString

public static java.lang.String incrementString(java.lang.String aString)
Numerically increments a string. For example, "hello" becomes "hello1" and "hello1" becomes "hello2" while "hello999" becomes "hello1000".

Parameters:
aString - a String to be incremented.
Returns:
The incremented String.

getAllChildComponents

public static java.util.Collection getAllChildComponents(java.awt.Container aContainer)
Gets all children of the specified container.

Parameters:
aContainer - the Container to be searched.
Returns:
A Collection containing all of the child components of the container.

addAllChildComponents

protected static void addAllChildComponents(java.awt.Container aContainer,
                                            java.util.Collection aCollection)
Adds all children of the specified container to the specified collection.

Parameters:
aContainer - the Container to be searched.
aCollection - the Collection to which the child components will be added.

labelComponents

public static void labelComponents(java.awt.Container aContainer)
Sets each child component's tooltip to show the name generated from getComponentNameMap(). (We're doing this so the tooltip authors can know how to reference the components.)

Parameters:
aContainer - the Container whose components will be labeled.

labelComponents

public static void labelComponents(java.awt.Container aContainer,
                                   java.util.Map aNameMap)
Sets each child component's tooltip to show a given string retrieved from a map using the component's generated name as a key.

Parameters:
aContainer - the Container whose components will be labeled.
aNameMap - a Map of generated names to string values.

getComponentToNameMap

public static java.util.Map getComponentToNameMap(java.awt.Container aContainer)
Generates a deterministically unique name for each component in a container. The name is based on the name of the class of the component followed by a number. Each class of component is numbered based on it's position in the container, sorted from top to bottom and left to right.

Parameters:
aContainer - the Container whose components will named.
Returns:
a Map that maps each component to its name.

getNameToComponentMap

public static java.util.Map getNameToComponentMap(java.awt.Container aContainer)
Maps a deterministically unique name to a component in a container. The name is based on the name of the class of the component followed by a number. Each class of component is numbered based on it's position in the container, sorted from top to bottom and left to right.

Parameters:
aContainer - the Container whose components will named.
Returns:
a Map that maps each component to its name.

nameComponents

public static void nameComponents(java.awt.Container aContainer)
Sets the tooltips of all components in a container to the respective names of those components. (We're using this so the tooltip authors can know how to reference the components.)

Parameters:
aContainer - the Container whose components will be labeled.

nameComponents

protected static void nameComponents(java.awt.Container aContainer,
                                     java.lang.String path)

enableComponents

public static void enableComponents(java.awt.Container aContainer,
                                    boolean isEnabled)
Sets the enabled state of a container and all of its components.

Parameters:
aContainer - the Container whose components will be enabled.
isEnabled - True if enabled, false id disabled.


Copyright © 2006 null. All Rights Reserved.