magi.toolkit.fields
Class MagiComboBoxModel

java.lang.Object
  |
  +--magi.toolkit.fields.MagiComboBoxModel
All Implemented Interfaces:
javax.swing.ComboBoxModel, javax.swing.ListModel

public class MagiComboBoxModel
extends java.lang.Object
implements javax.swing.ComboBoxModel

A Combo Box Model that allows easy data setting and retrieval.

Author:
Paul Atkinson, Magi Systems Pty Ltd.
See Also:
MagiComboBox, ComboList

Constructor Summary
MagiComboBoxModel()
          Default constructor.
MagiComboBoxModel(java.util.Collection collection)
          Create a model with any Collection of Objects, for example a List, Set, Vector, etc.
MagiComboBoxModel(java.util.Collection collection, int index)
          Create a model with any Collection of Objects, for example a List, Set, Vector, etc.
MagiComboBoxModel(java.lang.Object[] objectArray)
          Create a model with the specified array of Objects.
MagiComboBoxModel(java.lang.Object[] objectArray, int index)
          Create a model with the specified array of Objects.
 
Method Summary
 void addItem(java.lang.Object item)
          Adds an item Object to the end of the combo data.
 void addListDataListener(javax.swing.event.ListDataListener l)
          Add a list data listener, to be notified whenever the model's data changes.
 ComboList getData()
          Retrieve the list of data stored in this model.
 java.lang.Object getElementAt(int index)
          Returns the item in the data set identified by index.
 int getSelectedIndex()
          Returns the selected index for this combo box.
 java.lang.Object getSelectedItem()
          Returns the selected item for this combo box.
 int getSize()
          Returns the size of data stored in this model.
 void removeItem(java.lang.Object item)
          Removes an item Object from the combo data.
 void removeListDataListener(javax.swing.event.ListDataListener l)
          Remove a list data listener from this model.
 void setData(ComboList comboList)
          Sets the list of data stored in this model.
 void setSelectedIndex(int index)
          Sets the selected index for this combo box.
 void setSelectedItem(java.lang.Object item)
          Sets the selected item for this combo box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagiComboBoxModel

public MagiComboBoxModel()
Default constructor.


MagiComboBoxModel

public MagiComboBoxModel(java.lang.Object[] objectArray)
Create a model with the specified array of Objects.

Parameters:
objectArray - an array of Objects to populate with.

MagiComboBoxModel

public MagiComboBoxModel(java.util.Collection collection)
Create a model with any Collection of Objects, for example a List, Set, Vector, etc.

Parameters:
collection - any Collection of Objects.

MagiComboBoxModel

public MagiComboBoxModel(java.lang.Object[] objectArray,
                         int index)
Create a model with the specified array of Objects. Allows the selected item index.

Parameters:
objectArray - an array of Objects to populate with.
index - the index of the selected item.

MagiComboBoxModel

public MagiComboBoxModel(java.util.Collection collection,
                         int index)
Create a model with any Collection of Objects, for example a List, Set, Vector, etc. Allows the selected item index.

Parameters:
collection - any Collection of Objects.
index - the index of the selected item.
Method Detail

setSelectedItem

public void setSelectedItem(java.lang.Object item)
Sets the selected item for this combo box.

Specified by:
setSelectedItem in interface javax.swing.ComboBoxModel
Parameters:
item - the item Object to select.

getSelectedItem

public java.lang.Object getSelectedItem()
Returns the selected item for this combo box.

Specified by:
getSelectedItem in interface javax.swing.ComboBoxModel
Returns:
the selected item Object.

setSelectedIndex

public void setSelectedIndex(int index)
Sets the selected index for this combo box.

Parameters:
index - the int index to select.

getSelectedIndex

public int getSelectedIndex()
Returns the selected index for this combo box.

Returns:
the int index selected.

getSize

public int getSize()
Returns the size of data stored in this model.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
int number of data elements.

getElementAt

public java.lang.Object getElementAt(int index)
Returns the item in the data set identified by index.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - the index of the item to retrieve.
Returns:
the Object at the index.

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener l)
Add a list data listener, to be notified whenever the model's data changes.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to attach.

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener l)
Remove a list data listener from this model.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to remove.

getData

public ComboList getData()
Retrieve the list of data stored in this model.

Returns:
a ComboList of data elements.

setData

public void setData(ComboList comboList)
Sets the list of data stored in this model.

Parameters:
comboList - a ComboList of data elements.

addItem

public void addItem(java.lang.Object item)
Adds an item Object to the end of the combo data.

Parameters:
item - an item Object to add to the end.
See Also:
removeItem(Object)

removeItem

public void removeItem(java.lang.Object item)
Removes an item Object from the combo data. If this item is the selected item, the combo selection is lost.

Parameters:
item - an item Object to remove.
See Also:
addItem(Object)