Extension SDK 10.1.2

oracle.ide.controls
Class ItemSelectableTracker

java.lang.Object
  extended byoracle.ide.controls.ItemSelectableTracker
All Implemented Interfaces:
java.util.EventListener, java.awt.event.ItemListener

public class ItemSelectableTracker
extends java.lang.Object
implements java.awt.event.ItemListener

The ItemSelectableTracker is a simple class for tracking the state of an ItemSelectable, such as a JCheckBox or JToggleButton so that a dependent group of Components can be enabled or disabled when the state of the ItemSelectable changes.

For example, this is commonly used in UI settings panels with radio buttons when there are other components associated with one or more of the buttons that should be enabled when the associated radio button is enabled, and disabled when the associated radio button is disabled.

Two optional overrides, itemSelected() and itemDeselected() are provided in case clients need to do additional work besides enabling or disabling dependent components.

Nested ItemSelectableTrackers can be used in cases where there are multiple levels of component dependencies. For example:

   [X] Some top-level option (Component 1)
       [X] First-level child dependent (Component 2)
           [X] Second-level child dependent (Component 3)
 
In these cases, it may be desirable to have an ItemSelectableTracker for the top-level option work with the ItemSelectableTracker for the second-level option. To do this, create an ItemSelectableTracker first for the relationship between component 2 and component 3. Then create an ItemSelectableTracker for component 1, and the other tracker.

Note that this class is intended only for a check box or button type of item. It is not intended for a list type of item, such as the AWT List, JComboBox, or JList.


Field Summary
protected  java.awt.Component[] components
          Stores the dependent components to enable when item is enabled.
protected  ItemSelectableTracker[] trackers
          Stores the dependent trackers to enable when item is enabled.
 
Constructor Summary
ItemSelectableTracker(java.awt.ItemSelectable selectableItem, java.awt.Component[] dependentComponents)
          Constructs a new ItemSelectableTracker to listen to the state of specified item, and enable or disable the specified dependent components based on that state.
ItemSelectableTracker(java.awt.ItemSelectable selectableItem, java.awt.Component[] dependentComponents, boolean sameEnabledState)
          Constructs a new ItemSelectableTracker to listen to the state of specified item, and enable or disable the specified dependent components based on that state.
ItemSelectableTracker(java.awt.ItemSelectable selectableItem, java.awt.Component[] dependentComponents, ItemSelectableTracker[] dependentTrackers)
          Construct a new ItemSelectableTracker to listen to the state of the specified item, and manage a component that itself has an ItemSelectableTracker registered.
 
Method Summary
protected  void itemDeselected(java.awt.ItemSelectable item)
          This method may be overrided by subclasses to take care of any additional work when the given item is deselected.
protected  void itemSelected(java.awt.ItemSelectable item)
          This method may be overrided by subclasses to take care of any additional work when the given item is selected.
 void itemStateChanged(java.awt.event.ItemEvent event)
          Invoked when an item has been selected or deselected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

protected java.awt.Component[] components
Stores the dependent components to enable when item is enabled.


trackers

protected ItemSelectableTracker[] trackers
Stores the dependent trackers to enable when item is enabled.

Constructor Detail

ItemSelectableTracker

public ItemSelectableTracker(java.awt.ItemSelectable selectableItem,
                             java.awt.Component[] dependentComponents)
Constructs a new ItemSelectableTracker to listen to the state of specified item, and enable or disable the specified dependent components based on that state. This will also update the enabled/disabled state of the dependent components to help initialize dependents correctly.

Parameters:
selectableItem - the ItemSelectable, such as a JCheckBox to track
dependentComponents - an array of Components to enable when the specified item is enabled - this array is assumed to be non-changing

ItemSelectableTracker

public ItemSelectableTracker(java.awt.ItemSelectable selectableItem,
                             java.awt.Component[] dependentComponents,
                             ItemSelectableTracker[] dependentTrackers)
Construct a new ItemSelectableTracker to listen to the state of the specified item, and manage a component that itself has an ItemSelectableTracker registered. The enabled state of the child selectable item of the subordinate tracker will match the enabled state of the main selectable item.

If a dependent component is itself an ItemSelectable, and you pass its tracker as on the the elements for dependentTrackers, you do not need to specify the component in the dependentComponents array.

Parameters:
selectableItem - the ItemSelectable, such as a JCheckBox to track
dependentComponents - an array of Components to enable when the specified item is enabled - this array is assumed to be non-changing
dependentTrackers - an array of dependent tracker relationships - this array is assumed to be non-changing.

ItemSelectableTracker

public ItemSelectableTracker(java.awt.ItemSelectable selectableItem,
                             java.awt.Component[] dependentComponents,
                             boolean sameEnabledState)
Constructs a new ItemSelectableTracker to listen to the state of specified item, and enable or disable the specified dependent components based on that state. This will also update the enabled/disabled state of the dependent components to help initialize dependents correctly.

Parameters:
selectableItem - the ItemSelectable, such as a JCheckBox to track
dependentComponents - an array of Components to enable when the specified item is enabled - this array is assumed to be non-changing
sameEnabledState - true if the dependentComponents should have the same enabled state as the selectableItem. false if the state should reflect the opposite.
Method Detail

itemStateChanged

public final void itemStateChanged(java.awt.event.ItemEvent event)
Invoked when an item has been selected or deselected. The code written for this method performs the operations that need to occur when an item is selected (or deselected).

Specified by:
itemStateChanged in interface java.awt.event.ItemListener
Parameters:
event - the ItemEvent object

itemSelected

protected void itemSelected(java.awt.ItemSelectable item)
This method may be overrided by subclasses to take care of any additional work when the given item is selected. It is called when this tracker is constructed if the item is selected, and when the state of the item changes to selected.

Parameters:
item - the ItemSelectable that was selected

itemDeselected

protected void itemDeselected(java.awt.ItemSelectable item)
This method may be overrided by subclasses to take care of any additional work when the given item is deselected. It is called when this tracker is constructed if the item is not selected, and when the state of the item changes to deselected.

Parameters:
item - the ItemSelectable that was deselected

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.