com.objectwave.viewUtility
Class VectorToButtons

java.lang.Object
  |
  +--com.objectwave.viewUtility.VectorToButtons

public class VectorToButtons
extends java.lang.Object

Provides the ability to create a vector of buttons from a vector of data. The method getButtons() will return the buttons generated, and getPanel() will return the buttons contained in a JPanel using a vertically-oriented GridLayout. Note that the buttons and the panel will automatically update with calls to the various setXxx() methods. The same panel will always be returned for a given instance of this class, while the buttons array will change if and only if the data vector is changed. Displaying Labels:

The labels for the buttons can be specified if three different ways. A vector of strings can be provided via the setLabels() method, a StringifyIF instance can be provided, or the toString() value of each data element can be used. If a vector of strings is provided, then that will be used over all other methods. Otherwise, if a stringifier is defined, then it will be used. If all else failed the toString() values are used.

Customizing the Buttons' Appearance
The font of all of the buttons can be specified simply by calling setFont(). Additionally, the layout can be modified by calling getPanel().setLayout(someLayoutManager). This should be followed by getPanel().revalidate() if the panel may currently be visible.

Specifying Button Behavior
A common behavior can be associated with all of the buttons by calling setAction() with some ActionIF object. This interface's single method, public void performAction(Object), is passed the data element associated with the button that was clicked. This single ActionIF object is applied to all buttons. If this is not desired for a given button, then simply call removeListener(int), passing the index of the given button.


Constructor Summary
VectorToButtons()
          Constructors:
VectorToButtons(java.util.Vector data)
           
VectorToButtons(java.util.Vector data, java.util.Vector strings)
           
 
Method Summary
protected  void action(java.lang.Object source)
           
 javax.swing.JButton[] getButtons()
           
 java.util.Vector getData()
           
 java.awt.Font getFont()
           
 StringifyIF getLabelifier()
           
 java.util.Vector getLabels()
           
 javax.swing.JPanel getPanel()
           
static void main(java.lang.String[] args)
          The rest of this class definition is for testing:
 void removeListener(int index)
          Remove the index'th button's action listener.
 void setAction(ActionIF act)
           
 void setData(java.util.Vector data)
           
 void setFont(java.awt.Font f)
           
 void setLabels(java.util.Vector strings)
           
 void setStringifier(StringifyIF s)
           
protected  void updateAll()
          Remake the button vector.
protected  void updateFont()
           
protected  void updateLabels()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VectorToButtons

public VectorToButtons()
Constructors:


VectorToButtons

public VectorToButtons(java.util.Vector data)

VectorToButtons

public VectorToButtons(java.util.Vector data,
                       java.util.Vector strings)
Method Detail

action

protected void action(java.lang.Object source)

getButtons

public javax.swing.JButton[] getButtons()

getData

public java.util.Vector getData()

getFont

public java.awt.Font getFont()

getLabelifier

public StringifyIF getLabelifier()

getLabels

public java.util.Vector getLabels()

getPanel

public javax.swing.JPanel getPanel()

main

public static void main(java.lang.String[] args)
The rest of this class definition is for testing:


removeListener

public void removeListener(int index)
Remove the index'th button's action listener.


setAction

public void setAction(ActionIF act)

setData

public void setData(java.util.Vector data)

setFont

public void setFont(java.awt.Font f)

setLabels

public void setLabels(java.util.Vector strings)

setStringifier

public void setStringifier(StringifyIF s)

updateAll

protected void updateAll()
Remake the button vector.


updateFont

protected void updateFont()

updateLabels

protected void updateLabels()