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
  • Field Details

    • list

      protected java.util.ArrayList<V> list
    • listWidth

      protected int listWidth
    • combo_box

      protected InterfaceComboBox 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

      public AttributeSelection​(java.lang.String name, java.util.ArrayList<V> list, java.lang.Class<V> clazz, V selection, int width, boolean isEditable, boolean isCopiable)
  • 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.
      Overrides:
      setValue in class Attribute<V>
      fire - Whether to notify listeners
      Returns:
    • setList

      public void setList​(java.util.ArrayList<V> values)
    • getList

      public java.util.ArrayList<?> getList()
    • getComboBox

      public InterfaceComboBox getComboBox()
      Return a combo box containing this list, and with the specified list width
      Returns:
    • getComboBox

      public InterfaceComboBox getComboBox​(int width)
      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 interface java.awt.event.ItemListener