Package mgui.interfaces.attributes
Class AttributeSelection<V>
java.lang.Object
mgui.interfaces.AbstractInterfaceObject
mgui.interfaces.attributes.Attribute<V>
mgui.interfaces.attributes.AttributeSelection<V>
- All Implemented Interfaces:
java.awt.event.ItemListener,java.lang.Cloneable,java.lang.Comparable<Attribute<V>>,java.util.EventListener,InterfaceObject,NamedObject,TreeObject,CleanableObject,XMLObject
public class AttributeSelection<V> extends Attribute<V> implements java.awt.event.ItemListener
Extends
Attribute to allow a list of options, one or none of which is the current value.
This form of the Attribute class allows attributes to be displayed as a set of possible
options, and provides a JComboBox for rendering.
The link to the list that is passed to the constructor is maintained; thus, external updates to that list
will result in a change to this AttributeSelection's list.
If a value is set using the setValue method, which is not in the list,
the attribute will assume that value, but it will not be added to the list.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType -
Field Summary
Fields Modifier and Type Field Description protected booleanallow_unlistedprotected InterfaceComboBoxcombo_boxprotected java.util.ArrayList<V>listprotected intlistWidthFields inherited from class mgui.interfaces.attributes.Attribute
isCopiable, isEditable, isNumeric, isSecret, name, object_class, valueFields inherited from class mgui.interfaces.AbstractInterfaceObject
isDestroyed, tree_nodes -
Constructor Summary
Constructors Constructor Description AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz)Constructs a new attribute selection with default initial selection.AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, boolean isEditable, boolean isCopiable)Constructs a new attribute selection with default initial selection.AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection)Constructs a new attribute selection with the specified initial selection.AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection, int width)Constructs a new attribute selection with the specified initial selection and combo box width.AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection, int width, boolean isEditable, boolean isCopiable) -
Method Summary
Modifier and Type Method Description booleanallowsUnlisted()Whether this list allows unlisted valuesvoidallowUnlisted(boolean b)Set whether this list allows unlisted valuesInterfaceComboBoxgetComboBox()Return a combo box containing this list, and with the specified list widthInterfaceComboBoxgetComboBox(int width)Return a combo box containing this list, and with the specified list widthjava.util.ArrayList<?>getList()voiditemStateChanged(java.awt.event.ItemEvent e)booleanselect(java.lang.Object selection)Sets the current selection.voidsetList(java.util.ArrayList<V> values)booleansetValue(java.lang.Object value, boolean fire)Sets the value of this attribute.Methods inherited from class mgui.interfaces.attributes.Attribute
addAttributeListener, clone, compareTo, fireAttributeListeners, getDTD, getGenericInstance, getLocalName, getName, getObjectClass, getShortXML, getTreeLabel, getValue, getValueStr, getValueStr, getXML, getXML, getXMLInstance, getXMLSchema, handleXMLElementEnd, handleXMLElementStart, handleXMLString, isCopiable, isEditable, isNumeric, isSecret, issueTreeNode, removeAttributeListener, setEditable, setFromAttribute, setFromAttribute, setName, setSecret, setTreeNode, setValue, setValue, toString, writeXML, writeXML, writeXML, writeXMLMethods inherited from class mgui.interfaces.AbstractInterfaceObject
clean, destroy, isDestroyed, updateTreeNodesMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
list
-
listWidth
protected int listWidth -
combo_box
-
allow_unlisted
protected boolean allow_unlisted
-
-
Constructor Details
-
AttributeSelection
public AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz)Constructs a new attribute selection with default initial selection.- Parameters:
name-list-clazz- Class for this object; necessary for generics
-
AttributeSelection
public AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, boolean isEditable, boolean isCopiable)Constructs a new attribute selection with default initial selection.- Parameters:
name-list-clazz- Class for this object; necessary for generics
-
AttributeSelection
public AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection)Constructs a new attribute selection with the specified initial selection.- Parameters:
name-list-selection-
-
AttributeSelection
public AttributeSelection(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection, int width)Constructs a new attribute selection with the specified initial selection and combo box width.- Parameters:
name-list-selection-
-
AttributeSelection
-
-
Method Details
-
allowUnlisted
public void allowUnlisted(boolean b)Set whether this list allows unlisted values- Parameters:
b-
-
allowsUnlisted
public boolean allowsUnlisted()Whether this list allows unlisted values -
select
public boolean select(java.lang.Object selection)Sets the current selection. If the selection is not in the list, does nothing and returns false;- Parameters:
selection-- Returns:
trueif the selection is in the list,falseotherwise.
-
setValue
public boolean setValue(java.lang.Object value, boolean fire)Description copied from class:AttributeSets the value of this attribute. -
setList
-
getList
public java.util.ArrayList<?> getList() -
getComboBox
Return a combo box containing this list, and with the specified list width- Returns:
-
getComboBox
Return a combo box containing this list, and with the specified list width- Returns:
-
itemStateChanged
public void itemStateChanged(java.awt.event.ItemEvent e)- Specified by:
itemStateChangedin interfacejava.awt.event.ItemListener
-