com.ccg.values
Class ValuesConfigModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by com.ccg.values.ValuesConfigModel
All Implemented Interfaces:
Serializable, ComboBoxModel, ListModel

public class ValuesConfigModel
extends AbstractListModel
implements ComboBoxModel

A standard ComboBoxModel which is associated with a set of configurations for a particular ValuesConfig class.

This method makes it easy to create and maintain Swing list and combobox models which reflect a set of available configurations. It works in the following manner:

Since:
1.0
Version:
$Revision: 1.1 $
Author:
$Author: pkb $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
ValuesConfigModel()
           
 
Method Summary
 ValuesConfig createValuesConfig()
          Create a new ValuesConfig object of the appropriate type.
 Object getElementAt(int i)
          Get the name of a particular configuration.
 Object getSelectedItem()
          Get the selected item.
 int getSize()
          Get number of configurations which are available.
 Class getValuesConfigClass()
          Get the ValuesConfig class which this list model will support.
 void reload()
          Reloads set of available configurations.
 void setSelectedItem(Object val)
          Set the selected item.
 void setValuesConfigClass(Class val)
          Set the ValuesConfig class which this list model will support.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Constructor Detail

ValuesConfigModel

public ValuesConfigModel()
Method Detail

setValuesConfigClass

public void setValuesConfigClass(Class val)
Set the ValuesConfig class which this list model will support.

When you invoke this method, you will reload the data in the list model (possibly notifying those monitoring the model). NOTE: This only works if your ValuesConfig has a public default constructor (as we use the newInstance() method from the class you pass to create these objects as we need them.

Parameters:
val - Class description of the ValuesConfig object to associate with the list model (must not be null).
See Also:
getValuesConfigClass()

getValuesConfigClass

public Class getValuesConfigClass()
Get the ValuesConfig class which this list model will support.

Returns:
Current Class value assigned - or null if not set to a valid value yet.
See Also:
setValuesConfigClass(java.lang.Class)

reload

public void reload()
Reloads set of available configurations.

This method fetches the list of all available configurations and then reloads the internal list model to match. NOTE: Do not invoke until you've set a non-null ValuesConfig object.

Since:
1.0

getSize

public int getSize()
Get number of configurations which are available.

Specified by:
getSize in interface ListModel
Returns:
Number of available configurations.
Since:
1.0

getElementAt

public Object getElementAt(int i)
Get the name of a particular configuration.

Specified by:
getElementAt in interface ListModel
Parameters:
idx - Index to retrieve name of config (in range of [0,getSize()-1].
Returns:
Object as specified index.
Since:
1.0

createValuesConfig

public ValuesConfig createValuesConfig()
Create a new ValuesConfig object of the appropriate type.

This method creates a new ValuesConfig object of the appropriate type. You can only use this method AFTER you've setValuesConfigClass(java.lang.Class) specified the appropriate class associated with the list model.

Returns:
A newly created values config object of the appropriate type (never returns null).
Throws:
IllegalStateException - If model hasn't been initialized with a proper ValuesConfig class.
Since:
1.0

setSelectedItem

public void setSelectedItem(Object val)
Set the selected item.

Specified by:
setSelectedItem in interface ComboBoxModel
Parameters:
val - New Object value to assign.
See Also:
getSelectedItem()

getSelectedItem

public Object getSelectedItem()
Get the selected item.

Specified by:
getSelectedItem in interface ComboBoxModel
Returns:
Current Object value assigned.
See Also:
setSelectedItem(java.lang.Object)


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