|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.AbstractListModel
com.ccg.swing.ClassComboBoxModel
public final class ClassComboBoxModel
A ComboBoxModel implementation where each of
the available items is a ObjectFactory item.
This class is designed to manage a collection of ObjectFactory objects in a manner that a user can
choose from them via a GUI widget. You can build the model in code,
but it is primarily intended to be used in conjunction with a
resource file (see addFromLookup for
details).
ObjectFactory,
Serialized Form| Field Summary |
|---|
| Fields inherited from class javax.swing.AbstractListModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
ClassComboBoxModel()
Construction of empty set of choices. |
|
| Method Summary | |
|---|---|
int |
addFromLookup(Lookup l,
String tag)
Dynamically creates and adds ObjectFactory
instances based upon a lookup table. |
void |
addObjectFactories(ObjectFactory[] ofa)
Add an array of choices to the model. |
void |
addObjectFactory(ObjectFactory of)
Add a single ObjectFactory instance. |
void |
clear()
Clears the entire contents of the model. |
Object |
getElementAt(int i)
Get a reference to a particular choice. |
ObjectFactory |
getObjectFactory(String name)
Searches the model for a ObjectFactory
whose class name or "toString" name matches the name specified. |
int |
getObjectFactoryIndex(String name)
Searches the model for a ObjectFactory
whose class name or "toString" name matches the name specified. |
Object |
getSelectedItem()
Get the currently selected ObjectFactory
(or null if none). |
int |
getSize()
Get number of choices which are available. |
void |
setSelectedItem(Object val)
Set the currently selected item (or null if nothing should be selected). |
| 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 |
|---|
public ClassComboBoxModel()
This initializes the list with a empty set of choices.
| Method Detail |
|---|
public void addObjectFactory(ObjectFactory of)
ObjectFactory instance.
This method adds a new item to the list of available choices.
of - ObjectFactory to add - must not be null.public void addObjectFactories(ObjectFactory[] ofa)
This entry is used to add an entire array of menu choices to the model.
ofa - Array of ObjectFactory objects - must not be null and none of
the array entries are permitted to be null.public void clear()
This entry is used to remove ALL entries from the model (leaving no available choices).
public int addFromLookup(Lookup l,
String tag)
throws IllegalArgumentException
ObjectFactory
instances based upon a lookup table.
This method allows one to dynamically add entries to the model
based upon the contents of lookup table. For example, assume one
had loaded a LookupProperties object with a property file containing the
following:
ocm.0.class=java.util.Date ocm.0.text=Time Stamp ocm.1.class=java.lang.Object ocm.1.text=New Object
The following could then be used to construct and intialize the model:
ClassComboBoxModel model = new ClassComboBoxModel();
model.addFromLookup(myLookup,"ocm");
You could then create combo boxes and lists in the following manner:
JList mlist = new JList(model);
JComboBox mbox = new JComboBox(model);
The user would see the text names "Time Stamp" and "New
Object" as the available choices, however, as a developer, you
would have access to the real ObjectFactory
when looking at what the user chose.
The entries must have the form:
TAG.N.class=CLASS TAG.N.text=TEXT
Where TAG is used to identify your collection (and must match the 'tag' parameter passed). N is a integer counter starting at 0 and incremented by 1 for each additional choice. CLASS is the fully qualified class name to associate with the entry - typically you will want to make sure the class has a default constructor available. TEXT is the text that you want the user to see.
l - Lookup table to search for entries (must not be null).tag - The TAG which identifies your collection (must not be null).
IllegalArgumentException - If we could not resolve one of the string value(s) retrieved
for the TAG.N.class key to a available class within the
CLASSPATH.public Object getElementAt(int i)
getElementAt in interface ListModelidx - Index to retrieve name of config (in range of [0,getSize()-1].
ObjectFactory.public int getSize()
getSize in interface ListModelpublic int getObjectFactoryIndex(String name)
ObjectFactory
whose class name or "toString" name matches the name specified.
name - Name to match (case insensitive) must not be null.
public ObjectFactory getObjectFactory(String name)
ObjectFactory
whose class name or "toString" name matches the name specified.
name - Name to match (case insensitive) must not be null.
public void setSelectedItem(Object val)
setSelectedItem in interface ComboBoxModelval - The ObjectFactory to select from the model (it may either be a
reference to a actual ObjectFactory instance), or the string
name as recognized by getObjectFactory(String).getSelectedItem()public Object getSelectedItem()
ObjectFactory
(or null if none).
getSelectedItem in interface ComboBoxModelObjectFactory instance), or null if nothing
selected.setSelectedItem(java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||