Class Attribute<V>

java.lang.Object
mgui.interfaces.AbstractInterfaceObject
mgui.interfaces.attributes.Attribute<V>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Attribute<V>>, InterfaceObject, NamedObject, TreeObject, CleanableObject, XMLObject
Direct Known Subclasses:
AttributeSelection, AttributeSelectionMap, ShapeAttribute

public class Attribute<V>
extends AbstractInterfaceObject
implements java.lang.Cloneable, XMLObject, java.lang.Comparable<Attribute<V>>
Class serves as a general-purpose attribute. Attributes are stored as Objects, with a String identifier. Once an Attribute is set, all subsequent set operations perform a check to ensure the new value is an instance of the original class (or its subclass). Attributes store an AttributeNode object, which is null until it is requested.
Author:
Andrew Reid
See Also:
AttributeTreeNode
  • Field Details

    • name

      protected java.lang.String name
    • value

      protected V value
    • object_class

      protected java.lang.Class<V> object_class
    • isNumeric

      protected boolean isNumeric
    • isEditable

      protected boolean isEditable
    • isCopiable

      protected boolean isCopiable
    • isSecret

      protected boolean isSecret
  • Constructor Details

    • Attribute

      protected Attribute()
    • Attribute

      public Attribute​(java.lang.String name, java.lang.Class<V> clazz)
      Instantiates a new Attribute object.
      Parameters:
      thisName - Name of the attribute
      clazz - Class of this attribute's value
    • Attribute

      public Attribute​(java.lang.String name, V value)
      Instantiates a new Attribute object.
      Parameters:
      name - Name of the attribute
      value - Value of the attribute
    • Attribute

      public Attribute​(java.lang.String name, V value, boolean isEditable)
      Instantiates a new Attribute object.
      Parameters:
      name - Name of the attribute
      value - Value of the attribute
      isEditable - Is this attribute editable?
    • Attribute

      public Attribute​(java.lang.String name, V value, boolean isEditable, boolean isCopiable)
      Instantiates a new Attribute object.
      Parameters:
      name - Name of the attribute
      value - Value of the attribute
      isEditable - Is this attribute editable?
      isCopiable - Is this attribute copiable?
  • Method Details

    • isCopiable

      public boolean isCopiable()
      Is this attribute copiable?
      Returns:
    • compareTo

      public int compareTo​(Attribute<V> attribute)
      Specified by:
      compareTo in interface java.lang.Comparable<V>
    • getName

      public java.lang.String getName()
      Description copied from interface: NamedObject
      Gets the name for this object.
      Specified by:
      getName in interface NamedObject
      Overrides:
      getName in class AbstractInterfaceObject
      Returns:
    • setName

      public void setName​(java.lang.String name)
      Description copied from interface: NamedObject
      Sets the name for this object.
      Specified by:
      setName in interface NamedObject
      Overrides:
      setName in class AbstractInterfaceObject
    • getTreeLabel

      public java.lang.String getTreeLabel()
      Description copied from interface: TreeObject
      Returns the label text to appear in a tree node.
      Specified by:
      getTreeLabel in interface TreeObject
      Overrides:
      getTreeLabel in class AbstractInterfaceObject
      Returns:
    • setEditable

      public void setEditable​(boolean b)
    • isEditable

      public boolean isEditable()
    • isNumeric

      public boolean isNumeric()
    • setSecret

      public void setSecret​(boolean b)
    • isSecret

      public boolean isSecret()
    • setFromAttribute

      public void setFromAttribute​(Attribute<V> a)
    • setFromAttribute

      public void setFromAttribute​(Attribute<V> a, boolean fire)
    • setValue

      public boolean setValue​(java.lang.Object value)
      Sets the value of this attribute, and notifies its listeners of the change. The value will only be changed if "isEditable" is true.
      Parameters:
      value -
      Returns:
    • setValue

      public boolean setValue​(java.lang.Object value, boolean fire)
      Sets the value of this attribute.
      Parameters:
      value -
      fire - Whether to notify listeners
      Returns:
    • setValue

      public boolean setValue​(java.lang.Object value, boolean fire, boolean ignore_editable)
      Sets the value of this attribute.
      Parameters:
      value -
      fire - Whether to notify listeners
      ignore_editable - If true, ignores this attribute's "isEditable" state; otherwise the value will only be changed if "isEditable" is true
      Returns:
    • getValue

      public V getValue()
      Returns the value of this Attribute.
      Returns:
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • issueTreeNode

      public InterfaceTreeNode issueTreeNode()
      Description copied from class: AbstractInterfaceObject
      Issues a new tree node and sets it using AbstractInterfaceObject.setTreeNode(mgui.interfaces.trees.InterfaceTreeNode). The tree node is stored in this object, which facilitates their destruction when necessary (e.g., when this object is destroyed). All issued tree nodes can informed of changes to their user object using the method AbstractInterfaceObject.updateTreeNodes().
      Specified by:
      issueTreeNode in interface TreeObject
      Overrides:
      issueTreeNode in class AbstractInterfaceObject
      Returns:
      a new InterfaceTreeNode
    • setTreeNode

      public void setTreeNode​(InterfaceTreeNode treeNode)
      Description copied from interface: TreeObject
      Sets the children for this node's InterfaceTreeNode.
      Specified by:
      setTreeNode in interface TreeObject
      Overrides:
      setTreeNode in class AbstractInterfaceObject
    • getValueStr

      public java.lang.String getValueStr()
    • getValueStr

      public java.lang.String getValueStr​(java.lang.String pattern)
    • addAttributeListener

      public void addAttributeListener​(AttributeListener a)
    • removeAttributeListener

      public void removeAttributeListener​(AttributeListener a)
    • fireAttributeListeners

      public void fireAttributeListeners()
    • getDTD

      public java.lang.String getDTD()
      Description copied from interface: XMLObject
      Returns the Data Type Declaration (DTD) for this object's XML representation

      See http://en.wikipedia.org/wiki/Document_Type_Definition for a description.

      Specified by:
      getDTD in interface XMLObject
      Returns:
    • getLocalName

      public java.lang.String getLocalName()
      Description copied from interface: XMLObject
      Returns the local name associated with this XML object.
      Specified by:
      getLocalName in interface XMLObject
      Returns:
    • getXML

      public java.lang.String getXML()
      Description copied from interface: XMLObject
      Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use the XMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater) functions to write larger objects to file.
      Specified by:
      getXML in interface XMLObject
      Returns:
    • getXML

      public java.lang.String getXML​(int tab)
      Description copied from interface: XMLObject
      Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use the XMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater) functions to write larger objects to file.
      Specified by:
      getXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the opening XML wrapper
      Returns:
    • getXMLSchema

      public java.lang.String getXMLSchema()
      Description copied from interface: XMLObject
      Returns the XML schema for this object's XML representation

      See http://en.wikipedia.org/wiki/XML_schema.

      Specified by:
      getXMLSchema in interface XMLObject
      Returns:
    • getShortXML

      public java.lang.String getShortXML​(int tab)
      Description copied from interface: XMLObject
      Returns a short XML representation of this object.
      Specified by:
      getShortXML in interface XMLObject
      Returns:
    • handleXMLElementEnd

      public void handleXMLElementEnd​(java.lang.String localName) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles the end of an XML element.
      Specified by:
      handleXMLElementEnd in interface XMLObject
      Parameters:
      localName - Local name of the element
      Throws:
      org.xml.sax.SAXException
    • handleXMLElementStart

      public void handleXMLElementStart​(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles the start of an XML element.
      Specified by:
      handleXMLElementStart in interface XMLObject
      Parameters:
      localName - Local name of the element
      attributes - Set of element attributes
      type - The XMLType of this element
      Throws:
      org.xml.sax.SAXException
    • getObjectClass

      public java.lang.Class<V> getObjectClass()
      Returns the object class for this parameterized Attribute.
      Returns:
    • handleXMLString

      public void handleXMLString​(java.lang.String string) throws org.xml.sax.SAXException
      Attempts to handle an XML string intended to set the value of this Attribute.
      Specified by:
      handleXMLString in interface XMLObject
      Parameters:
      string - String to handle
      Throws:
      org.xml.sax.SAXException
    • getXMLInstance

      public static XMLObject getXMLInstance​(org.xml.sax.Attributes attributes)
    • getGenericInstance

      protected static <T> Attribute<T> getGenericInstance​(java.lang.String name, java.lang.Class<T> clazz)
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      Throws:
      java.io.IOException
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, ProgressUpdater progress_bar) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file, as XMLType.Normal. The default format of XMLFormat.Ascii will be used. The basic contract for this method is that it should not write a newline character at its start or end.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      options - XMLOutputOptions defining the write parameters
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, XMLObject.XMLType type, XMLObject.XMLEncoding format, ProgressUpdater progress_bar) throws java.io.IOException
      Throws:
      java.io.IOException