Class AttributeList

java.lang.Object
mgui.interfaces.AbstractInterfaceObject
mgui.interfaces.attributes.AttributeList
All Implemented Interfaces:
java.lang.Cloneable, AttributeListener, InterfaceObject, NamedObject, TreeObject, CleanableObject, XMLObject, IconObject

public class AttributeList
extends AbstractInterfaceObject
implements java.lang.Cloneable, AttributeListener, IconObject, XMLObject
Stores a list of Attribute objects, and provides methods to access and modify them, as well as set methods to intersect and union with other lists. This class also listens for changes on its attributes and can inform all listeners of these changes.

It provides XML reading writing implementations.

It constructs its own tree nodes vis the setTreeNode method; these nodes can be used to modify attribute values. The AttributeList should be used for all InterfaceObject instances which require attributes.

Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Details

    • attributes

      protected java.util.HashMap<java.lang.String,​Attribute<?>> attributes
    • category_attributes

      protected java.util.HashMap<java.lang.String,​java.util.ArrayList<Attribute<?>>> category_attributes
    • updateable

      public boolean updateable
  • Constructor Details

    • AttributeList

      public AttributeList()
  • Method Details

    • getObjectIcon

      public javax.swing.Icon getObjectIcon()
      Description copied from interface: IconObject
      Returns the Icon associated with this object.
      Specified by:
      getObjectIcon in interface IconObject
      Returns:
    • getAsList

      public java.util.ArrayList<Attribute<?>> getAsList()
    • hasAttribute

      public boolean hasAttribute​(java.lang.String name)
    • hasAttribute

      public boolean hasAttribute​(Attribute<?> attribute)
    • 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:
    • add

      public void add​(Attribute<?> attribute)
      Adds an attribute to the default list
      Parameters:
      thisAttr -
    • add

      public void add​(java.lang.String category, Attribute<?> attribute)
      Adds an attribute to the specified category. If the category does not exist, creates a new one.
      Parameters:
      category -
      attribute -
    • addCategory

      public java.util.ArrayList<Attribute<?>> addCategory​(java.lang.String category)
    • removeCategory

      public void removeCategory​(java.lang.String category)
    • remove

      public void remove​(java.lang.String name)
    • remove

      public void remove​(Attribute<?> thisAttr)
    • replace

      public void replace​(Attribute<?> thisAttr)
    • getValue

      public java.lang.Object getValue​(java.lang.String name)
      Get the current value of the attribute named name.
      Parameters:
      name -
      Returns:
    • setAttribute

      public boolean setAttribute​(Attribute<?> thisAttr)
      Sets the given attribute. If an attribute by this name already exists, it is overriden.
      Parameters:
      thisAttr -
      Returns:
    • setAttribute

      public <V> boolean setAttribute​(Attribute<V> attribute, boolean fire)
    • getAttribute

      public Attribute<?> getAttribute​(int index)
      Returns the attribute at the specified index. Note: this function will be deprecated.
      Parameters:
      index -
      Returns:
    • getAttribute

      public Attribute<?> getAttribute​(java.lang.String name)
      Gets the Attribute object for the specified name; returns null if this attribute does not exist.
      Parameters:
      name -
      Returns:
    • setValueForced

      public <V> boolean setValueForced​(java.lang.String name, V value)
      Sets the value of the attribute represented by name; ignores the isEditable flag.
      Parameters:
      thisAttr -
      thisValue -
      Returns:
    • setValue

      public <V> boolean setValue​(java.lang.String name, V value)
      Sets the value of the attribute represented by name.
      Parameters:
      thisAttr -
      thisValue -
      Returns:
    • setValue

      public <V> boolean setValue​(java.lang.String name, V value, boolean fire)
    • setValue

      public <V> boolean setValue​(Attribute<V> attribute)
      Type Parameters:
      V -
      Parameters:
      attribute -
      Returns:
    • addAttributeListener

      public void addAttributeListener​(AttributeListener a)
    • removeAttributeListener

      public void removeAttributeListener​(AttributeListener a)
    • fireAttributeListeners

      public void fireAttributeListeners​(Attribute<?> a)
    • setAttributeListeners

      public void setAttributeListeners​(AttributeList a)
    • toString

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

      public int getSize()
    • clone

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

      public void attributeUpdated​(AttributeEvent e)
      Description copied from interface: AttributeListener
      Called when an Attribute's value has been updated.
      Specified by:
      attributeUpdated in interface AttributeListener
    • getKeys

      public java.util.ArrayList<java.lang.String> getKeys()
    • 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
    • setIntersection

      public void setIntersection​(AttributeList list)
      Set any attributes which intersect with the passed list.
    • setIntersection

      public void setIntersection​(AttributeList list, boolean fire)
      Set any attributes which intersect with the passed list.
    • setIntersection

      public void setIntersection​(java.util.List<Attribute<?>> list, boolean fire)
      Set any attributes which intersect with the passed list.
    • setUnion

      public void setUnion​(AttributeList list)
      Sets this AttributeList to the union of itself and list. The values of attributes which already exist in this list are updated to reflect the new values.
      Parameters:
      list -
    • setUnion

      public void setUnion​(AttributeList list, boolean overwrite)
      Sets this AttributeList to the union of itself and list. If overwrite is true, the values of attributes which already exist in this list are updated to reflect the new values; otherwise the current values are preserved. Note that if the attribute's type is different in the new list, overwriting will also change the type.
      Parameters:
      list -
      overwrite -
    • 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:
    • handleXMLElementEnd

      public void handleXMLElementEnd​(java.lang.String localName)
      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
    • handleXMLElementStart

      public void handleXMLElementStart​(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
      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
    • handleXMLString

      public void handleXMLString​(java.lang.String s)
      Description copied from interface: XMLObject
      Handles a string within an XML element.
      Specified by:
      handleXMLString in interface XMLObject
      Parameters:
      s - String to handle
    • getXMLInstance

      public static XMLObject getXMLInstance​(org.xml.sax.Attributes attributes)
    • 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
    • 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: