com.sas.swing.visuals
Class TriStateCheckBoxList

com.sas.swing.visuals.TriStateCheckBoxList
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

public class TriStateCheckBoxList

A component that allows the user to select one or more objects from a list by using TriStateCheckBoxes in place of labels. A separate model, ListModel, represents the contents of the list. It's easy to display an array or vector of objects, using a TriStateCheckBoxList constructor that builds a ListModel instance for you:

 // Create a TriStateCheckBoxList that displays the strings in data[]

 String[] data = {"one", "two", "three", "four"};
 TriStateCheckBoxList dataList = new TriStateCheckBoxList(data);
 
 // The value of the TriStateCheckBoxList model property is an object that provides
 // a read-only view of the data.  It was constructed automatically.

 for(int i = 0; i < dataList.getModel().getSize(); i++) {
     System.out.println(dataList.getModel().getElementAt(i));
 }

 // Create a TriStateCheckBoxList that displays the superclass of TriStateCheckBoxList.class.
 // We store the superclasses in a java.util.Vector.

 Vector superClasses = new Vector();
 Class rootClass = javax.swing.TriStateCheckBoxList.class;
 for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) {
     superClasses.addElement(cls);
 }
 TriStateCheckBoxList classList = new TriStateCheckBoxList(superClasses);
 

TriStateCheckBoxList doesn't support scrolling directly. To create a scrolling list you make the TriStateCheckBoxList the viewport view of a JScrollPane. For example:

 JScrollPane scrollPane = new JScrollPane(dataList);
 // Or in two steps:
 JScrollPane scrollPane = new JScrollPane();
 scrollPane.getViewport().setView(dataList);
 

By default the TriStateCheckBoxList selection model allows any combination of items to be selected at a time, using the constant MULTIPLE_INTERVAL_SELECTION. The selection state is actually managed by a separate delegate object, an instance of ListSelectionModel. However TriStateCheckBoxList provides convenient properties for managing the selection.

 String[] data = {"one", "two", "three", "four"};
 TriStateCheckBoxList dataList = new TriStateCheckBoxList(data);

 dataList.setSelectedIndex(1);  // select "two" as MIXED
 dataList.getSelectedValues();   // returns "two"
 dataList.setSelectedIndex(2);  // select "three" as MIXED 
 dataList.getSelectedValues();   // returns "two","three" 
 dataList.setSelectedIndex(1);  // select "two" as ON
 dataList.getSelectedValues();   // returns "two","three" 
 dataList.setSelectedIndex(1);  // select "two" as OFF
 dataList.getSelectedValues();   // returns "three"
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.sas.swing.visuals.CheckBoxList
RB_KEY
 
Constructor Summary
TriStateCheckBoxList()
          Constructs a TriStateCheckBoxList with an empty model.
TriStateCheckBoxList(javax.swing.ListModel dataModel)
          Constructs a TriStateCheckBoxList that displays the elements in the specified, non-null model.
TriStateCheckBoxList(java.lang.Object[] listData)
          Constructs a TriStateCheckBoxList that displays the elements in the specified array.
TriStateCheckBoxList(java.util.Vector listData)
          Constructs a TriStateCheckBoxList that displays the elements in the specified Vector.
 
Method Summary
 int getSelectedIndexValue(int index)
          Returns the value at the given index.
 boolean isCycleEnabled()
          Returns whether the checkbox cycles through all three values.
 boolean isUpdateEnabled()
          Used internally to return whether values can be updated.
 void setCycleEnabled(boolean b)
          Sets whether each checkBox in the list should cycle through all three values.
 void setSelectedIndexValue(int index, int value)
          Sets the given index to the given value.
 void setUpdateEnabled(boolean b)
          Used internally to set whether values can be updated.
 
Methods inherited from class com.sas.swing.visuals.CheckBoxList
getExtendedBeanInfo, isBorderPaintedFlat, setBorderPaintedFlat, setSelectedIndices
 

Constructor Detail

TriStateCheckBoxList

public TriStateCheckBoxList(javax.swing.ListModel dataModel)
Constructs a TriStateCheckBoxList that displays the elements in the specified, non-null model. All TriStateCheckBoxList constructors delegate to this one.

Parameters:
dataModel - the data model for this list
Throws:
java.lang.IllegalArgumentException - if dataModel is null

TriStateCheckBoxList

public TriStateCheckBoxList(java.lang.Object[] listData)
Constructs a TriStateCheckBoxList that displays the elements in the specified array. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the array of Objects to be loaded into the data model

TriStateCheckBoxList

public TriStateCheckBoxList(java.util.Vector listData)
Constructs a TriStateCheckBoxList that displays the elements in the specified Vector. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the Vector to be loaded into the data model

TriStateCheckBoxList

public TriStateCheckBoxList()
Constructs a TriStateCheckBoxList with an empty model.

Method Detail

setSelectedIndexValue

public void setSelectedIndexValue(int index,
                                  int value)
Sets the given index to the given value.

Parameters:
index - The index in which to change
value - The new value to be set

getSelectedIndexValue

public int getSelectedIndexValue(int index)
Returns the value at the given index.

Parameters:
index - The index to search on
Returns:
The current value

setCycleEnabled

public void setCycleEnabled(boolean b)
Sets whether each checkBox in the list should cycle through all three values.

Parameters:
b - if true, the checkBox cycles, or else the checkBox switches between ON and OFF once those values have been reached.

isCycleEnabled

public boolean isCycleEnabled()
Returns whether the checkbox cycles through all three values.


setUpdateEnabled

public void setUpdateEnabled(boolean b)
Used internally to set whether values can be updated.


isUpdateEnabled

public boolean isUpdateEnabled()
Used internally to return whether values can be updated.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.