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 boolean
allow_unlisted
protected InterfaceComboBox
combo_box
protected java.util.ArrayList<V>
list
protected int
listWidth
Fields inherited from class mgui.interfaces.attributes.Attribute
isCopiable, isEditable, isNumeric, isSecret, name, object_class, value
Fields 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 boolean
allowsUnlisted()
Whether this list allows unlisted valuesvoid
allowUnlisted(boolean b)
Set whether this list allows unlisted valuesInterfaceComboBox
getComboBox()
Return a combo box containing this list, and with the specified list widthInterfaceComboBox
getComboBox(int width)
Return a combo box containing this list, and with the specified list widthjava.util.ArrayList<?>
getList()
void
itemStateChanged(java.awt.event.ItemEvent e)
boolean
select(java.lang.Object selection)
Sets the current selection.void
setList(java.util.ArrayList<V> values)
boolean
setValue(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, writeXML
Methods inherited from class mgui.interfaces.AbstractInterfaceObject
clean, destroy, isDestroyed, updateTreeNodes
Methods 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:
true
if the selection is in the list,false
otherwise.
-
setValue
public boolean setValue(java.lang.Object value, boolean fire)Description copied from class:Attribute
Sets 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:
itemStateChanged
in interfacejava.awt.event.ItemListener
-