Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class SwingUtils

java.lang.Object
  com.wordpress.tipsforjava.swing.SwingUtils

public final class SwingUtils
extends Object

A collection of utility methods for Swing.

Authors:
Rob Camick
Darryl Burke


Field Summary
static Set setExclude

Exclude methods that return values that are meaningless to the user

 
Constructor Summary
private SwingUtils()

 
Method Summary
static boolean equals(Object obj1, Object obj2)

Convenience method for determining whether two objects are either equal or both null.

private static Object getComponentFromList(Class clazz, List list, String property, Object value)

static Map getComponentMap(JComponent container, boolean nested)

Convenience method for mapping a container in the hierarchy to its contained components.

static Object getDescendantOfClass(Class clazz, Container container, String property, Object value)

Convenience method that searches below container in the component hierarchy in a depth first manner and returns the first found component of class clazz having the bound property value.

static Object getDescendantOfClass(Class clazz, Container container, String property, Object value, boolean nested)

Convenience method that searches below container in the component hierarchy in a depth first manner and returns the first found component of class clazz having the bound property value.

static Object getDescendantOfType(Class clazz, Container container, String property, Object value)

Convenience method that searches below container in the component hierarchy and returns the first found component that is an instance of class clazz having the bound property value.

static Object getDescendantOfType(Class clazz, Container container, String property, Object value, boolean nested)

Convenience method that searches below container in the component hierarchy and returns the first found component that is an instance of class clazz and has the bound property value.

static List getDescendantsOfClass(Class clazz, Container container)

Convenience method for searching below container in the component hierarchy and return nested components of class clazz it finds.

static List getDescendantsOfClass(Class clazz, Container container, boolean nested)

Convenience method for searching below container in the component hierarchy and return nested components of class clazz it finds.

static List getDescendantsOfType(Class clazz, Container container)

Convenience method for searching below container in the component hierarchy and return nested components that are instances of class clazz it finds.

static List getDescendantsOfType(Class clazz, Container container, boolean nested)

Convenience method for searching below container in the component hierarchy and return nested components that are instances of class clazz it finds.

static Class getJClass(Object component)

Convenience method to obtain the Swing class from which this component was directly or indirectly derived.

static Map getProperties(JComponent component)

Convenience method for obtaining most non-null human readable properties of a JComponent.

static Object getUIDefaultOfClass(Class clazz, String property)

Convenience method for retrieving the UIDefault for a single property of a particular class.

static UIDefaults getUIDefaultsOfClass(Class clazz)

Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class.

static UIDefaults getUIDefaultsOfClass(String className)

Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

setExclude

static Set setExclude
Exclude methods that return values that are meaningless to the user


 
Constructor Detail

SwingUtils

private SwingUtils()


 
Method Detail

equals

public static boolean equals(Object obj1, Object obj2)
Convenience method for determining whether two objects are either equal or both null.
Parameters:
obj1 - the first reference object to compare.
obj2 - the second reference object to compare.
Returns:
true if obj1 and obj2 are equal or if both are null, false otherwise


getComponentFromList

private static Object getComponentFromList(Class clazz, List list, String property, Object value)


getComponentMap

public static Map getComponentMap(JComponent container, boolean nested)
Convenience method for mapping a container in the hierarchy to its contained components. The keys are the containers, and the values are lists of contained components.

Implementation note: The returned value is a HashMap and the values are of type ArrayList. This is subject to change, so callers should code against the interfaces Map and List.

Parameters:
container - The JComponent to be mapped
nested - true to drill down to nested containers, false otherwise
Returns:
the Map of the UI


getDescendantOfClass

public static Object getDescendantOfClass(Class clazz, Container container, String property, Object value)
Convenience method that searches below container in the component hierarchy in a depth first manner and returns the first found component of class clazz having the bound property value.

Returns null if such component cannot be found.

This method invokes getDescendantOfClass(clazz, container, property, value, true)

throws:
java.lang.IllegalArgumentException if the bound property does not exist for the class or cannot be accessed
Parameters:
clazz - the class of component to be found.
container - the container at which to begin the search
property - the className of the bound property, exactly as expressed in the accessor e.g. "Text" for getText(), "Value" for getValue(). This parameter is case sensitive.
value - the value of the bound property
Returns:
the component, or null if no such component exists in the container's hierarchy.


getDescendantOfClass

public static Object getDescendantOfClass(Class clazz, Container container, String property, Object value, boolean nested)
Convenience method that searches below container in the component hierarchy in a depth first manner and returns the first found component of class clazz having the bound property value.

Returns null if such component cannot be found.

throws:
java.lang.IllegalArgumentException if the bound property does not exist for the class or cannot be accessed
Parameters:
clazz - the class of component to be found.
container - the container at which to begin the search
property - the className of the bound property, exactly as expressed in the accessor e.g. "Text" for getText(), "Value" for getValue(). This parameter is case sensitive.
value - the value of the bound property
nested - true to include components nested within another listed component, false otherwise
Returns:
the component, or null if no such component exists in the container's hierarchy


getDescendantOfType

public static Object getDescendantOfType(Class clazz, Container container, String property, Object value)
Convenience method that searches below container in the component hierarchy and returns the first found component that is an instance of class clazz having the bound property value. Returns null if such component cannot be found.

This method invokes getDescendantOfType(clazz, container, property, value, true)

throws:
java.lang.IllegalArgumentException if the bound property does not exist for the class or cannot be accessed
Parameters:
clazz - the class of component whose instance is to be found.
container - the container at which to begin the search
property - the className of the bound property, exactly as expressed in the accessor e.g. "Text" for getText(), "Value" for getValue().
value - the value of the bound property
Returns:
the component, or null if no such component exists in the container


getDescendantOfType

public static Object getDescendantOfType(Class clazz, Container container, String property, Object value, boolean nested)
Convenience method that searches below container in the component hierarchy and returns the first found component that is an instance of class clazz and has the bound property value. Returns null if such component cannot be found.
throws:
java.lang.IllegalArgumentException if the bound property does not exist for the class or cannot be accessed
Parameters:
clazz - the class of component whose instance to be found.
container - the container at which to begin the search
property - the className of the bound property, exactly as expressed in the accessor e.g. "Text" for getText(), "Value" for getValue().
value - the value of the bound property
nested - true to list components nested within another component which is also an instance of clazz, false otherwise
Returns:
the component, or null if no such component exists in the container


getDescendantsOfClass

public static List getDescendantsOfClass(Class clazz, Container container)
Convenience method for searching below container in the component hierarchy and return nested components of class clazz it finds. Returns an empty list if no such components exist in the container.

This method invokes getDescendantsOfClass(clazz, container, true)

Parameters:
clazz - the class of components to be found.
container - the container at which to begin the search
Returns:
the List of components


getDescendantsOfClass

public static List getDescendantsOfClass(Class clazz, Container container, boolean nested)
Convenience method for searching below container in the component hierarchy and return nested components of class clazz it finds. Returns an empty list if no such components exist in the container.
Parameters:
clazz - the class of components to be found.
container - the container at which to begin the search
nested - true to list components nested within another listed component, false otherwise
Returns:
the List of components


getDescendantsOfType

public static List getDescendantsOfType(Class clazz, Container container)
Convenience method for searching below container in the component hierarchy and return nested components that are instances of class clazz it finds. Returns an empty list if no such components exist in the container.

Invoking this method with a class parameter of JComponent.class will return all nested components.

This method invokes getDescendantsOfType(clazz, container, true)

Parameters:
clazz - the class of components whose instances are to be found.
container - the container at which to begin the search
Returns:
the List of components


getDescendantsOfType

public static List getDescendantsOfType(Class clazz, Container container, boolean nested)
Convenience method for searching below container in the component hierarchy and return nested components that are instances of class clazz it finds. Returns an empty list if no such components exist in the container.

Invoking this method with a class parameter of JComponent.class will return all nested components.

Parameters:
clazz - the class of components whose instances are to be found.
container - the container at which to begin the search
nested - true to list components nested within another listed component, false otherwise
Returns:
the List of components


getJClass

public static Class getJClass(Object component)
Convenience method to obtain the Swing class from which this component was directly or indirectly derived.
Parameters:
component - The component whose Swing superclass is to be determined
Returns:
The nearest Swing class in the inheritance tree


getProperties

public static Map getProperties(JComponent component)
Convenience method for obtaining most non-null human readable properties of a JComponent. Array properties are not included.

Implementation note: The returned value is a HashMap. This is subject to change, so callers should code against the interface Map.

Parameters:
component - the component whose proerties are to be determined
Returns:
the class and value of the properties


getUIDefaultOfClass

public static Object getUIDefaultOfClass(Class clazz, String property)
Convenience method for retrieving the UIDefault for a single property of a particular class.
Parameters:
clazz - the class of interest
property - the property to query
Returns:
the UIDefault property, or null if not found


getUIDefaultsOfClass

public static UIDefaults getUIDefaultsOfClass(Class clazz)
Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class.
Parameters:
clazz - the class of interest
Returns:
the UIDefaults of the class


getUIDefaultsOfClass

public static UIDefaults getUIDefaultsOfClass(String className)
Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class.
Parameters:
className - fully qualified name of the class of interest
Returns:
the UIDefaults of the class named


 

Groovy Documentation