com.ccg.swing
Class Grouping

java.lang.Object
  extended by com.ccg.swing.Grouping

public class Grouping
extends Object

Easily manipulate a "grouping" of JComponent objects.

You will often find yourself in a situation where you GUI interface has a bunch of items that need you would like to treat as a "group" at times.

This class allows you to group components into a single container and then perform common operations on the entire group.

The setEnabled(boolean) method can be particularily handy when you will need to disable an entire set of options when your application enters a certain state, and then re-enable them when your application leaves the state.

This really requires an entire chapter (book) to fully understand the benefit of working with "group", but trust me in that its very handy (especially when GUI components are dynamically created from resource files).

Since:
1.0
Version:
$Revision: 1.2 $
Author:
$Author: pkb $
See Also:
Groupings

Constructor Summary
Grouping(String name)
          Create a new "grouping" of components.
 
Method Summary
 void addJComponent(JComponent c)
          Add a new component to the group of components.
 String getName()
          Get the "name" of the grouping.
 void removeJComponent(JComponent c)
          Remove a component from the group of components.
 void setBackground(Color color)
          Set the background color of the components.
 void setEnabled(boolean enable)
          Enable/Disable ALL components in the grouping.
 void setForeground(Color color)
          Set the foreground color of the components.
 void setSelected(boolean enable)
          Select/Unselect ALL "boolean" components in the grouping.
 void setText(String text)
          Set the "text" for all of the components in the group.
 int smartAdd(Object o)
          Smart add of zero or more components to the group.
 int smartRemove(Object o)
          Smart remove of zero or more components to the group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grouping

public Grouping(String name)
Create a new "grouping" of components.

Creates a "empty" group of components

Since:
1.0
See Also:
addJComponent(javax.swing.JComponent), smartAdd(java.lang.Object)
Method Detail

getName

public String getName()
Get the "name" of the grouping.

Returns:
Current String value assigned.
See Also:
Groupings

addJComponent

public void addJComponent(JComponent c)
Add a new component to the group of components.

Parameters:
c - The JComponent component to add - must not be null.
Since:
1.0
See Also:
removeJComponent(javax.swing.JComponent), smartAdd(java.lang.Object)

removeJComponent

public void removeJComponent(JComponent c)
Remove a component from the group of components.

Parameters:
c - The JComponent component to remove - must not be null.
Since:
1.0
See Also:
addJComponent(javax.swing.JComponent), smartRemove(java.lang.Object)

smartAdd

public int smartAdd(Object o)
Smart add of zero or more components to the group.

This is a very flexible way to add elements to the grouping. You can pass any object type you want (or even null) and we will handle it to the best of our ability. Here are the types we currently handle:

null
This is a easy one to handle - we don't do anything.
JComponent
This is also easy to handle, we simply use the addJComponent(JComponent) method to add it to the grouping.
Object[]
We will recursively call ourself for each object in the array.
Enumeration
We will recursively call ourself and process each element in the enumeration.
Iterator
We will recursively call ourself for each item we iterate over.
Collection
We will get a Iterator for the collection and then recursively call ourself (this handles most of the handy java.util package classes - like Vector, Hashtable, List, etc).

Parameters:
o - The Object to process as described above.
Returns:
The total number of components found that were added to the grouping.
Since:
1.0
See Also:
smartRemove(java.lang.Object)

smartRemove

public int smartRemove(Object o)
Smart remove of zero or more components to the group.

This is a very flexible way to remove elements from the grouping. You can pass any object type you want (or even null) and we will handle it to the best of our ability. Here are the types we currently handle:

null
This is a easy one to handle - we don't do anything.
JComponent
This is also easy to handle, we simply use the removeJComponent(JComponent) method to remove it from the grouping.
Object[]
We will recursively call ourself for each object in the array.
Enumeration
We will recursively call ourself and process each element in the enumeration.
Iterator
We will recursively call ourself for each item we iterate over.
Collection
We will get a Iterator for the collection and then recursively call ourself (this handles most of the handy java.util package classes - like Vector, Hashtable, List, etc).

Parameters:
o - The Object to process as described above.
Returns:
The total number of components found that were removed from the grouping.
Since:
1.0
See Also:
smartAdd(java.lang.Object)

setEnabled

public void setEnabled(boolean enable)
Enable/Disable ALL components in the grouping.

This method will invoke the JComponent.setEnabled(boolean) method for each component in the collection (lets you enable/disable the entire group of components).

Parameters:
enable - Whether the component should be enabled or not.
Since:
1.0
See Also:
setSelected(boolean)

setSelected

public void setSelected(boolean enable)
Select/Unselect ALL "boolean" components in the grouping.

This method will invoke the setSelected(boolean) or setState(boolean) method for each JComponent in the grouping that has a "boolean" state associated with it (such as AbstractButton derived objects like the javax.swing.JCheckBoxMenuItem.

Parameters:
select - Whether the component should be selected (checked) or not.
Since:
1.0
See Also:
setEnabled(boolean)

setForeground

public void setForeground(Color color)
Set the foreground color of the components.

This method will invoke the JComponent.setForeground(java.awt.Color) method for each component in the collection (lets you change the foreground color for the entire group of components).

Parameters:
color - New color to set (or null if the components should use their parent component's value)
Since:
1.0
See Also:
setBackground(java.awt.Color)

setBackground

public void setBackground(Color color)
Set the background color of the components.

This method will invoke the JComponent.setBackground(java.awt.Color) method for each component in the collection (lets you change the background color for the entire group of components).

Parameters:
color - New color to set (or null if the components should use their parent value)
Since:
1.0
See Also:
setForeground(java.awt.Color)

setText

public void setText(String text)
Set the "text" for all of the components in the group.

This method will set the text value displayed for the component(s) to the value specified. Currently, this only affects components which are descendents of JTextComponent, JLabel, or AbstractButton - this handles most of the standard Swing items.

Parameters:
text - The new text to associate with the components.
Since:
1.0
See Also:
setEnabled(boolean)


Copyright 1998-1998-2006 null. All Rights Reserved.