Package mgui.interfaces.attributes
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
-
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
isCopiable
protected boolean
isEditable
protected boolean
isNumeric
protected boolean
isSecret
protected java.lang.String
name
protected java.lang.Class<V>
object_class
protected V
value
Fields inherited from class mgui.interfaces.AbstractInterfaceObject
isDestroyed, tree_nodes
-
Constructor Summary
Constructors Modifier Constructor Description protected
Attribute()
Attribute(java.lang.String name, java.lang.Class<V> clazz)
Instantiates a newAttribute
object.Attribute(java.lang.String name, V value)
Instantiates a newAttribute
object.Attribute(java.lang.String name, V value, boolean isEditable)
Instantiates a newAttribute
object.Attribute(java.lang.String name, V value, boolean isEditable, boolean isCopiable)
Instantiates a newAttribute
object. -
Method Summary
Modifier and Type Method Description void
addAttributeListener(AttributeListener a)
java.lang.Object
clone()
int
compareTo(Attribute<V> attribute)
void
fireAttributeListeners()
java.lang.String
getDTD()
Returns the Data Type Declaration (DTD) for this object's XML representationprotected static <T> Attribute<T>
getGenericInstance(java.lang.String name, java.lang.Class<T> clazz)
java.lang.String
getLocalName()
Returns the local name associated with this XML object.java.lang.String
getName()
Gets the name for this object.java.lang.Class<V>
getObjectClass()
Returns the object class for this parameterizedAttribute
.java.lang.String
getShortXML(int tab)
Returns a short XML representation of this object.java.lang.String
getTreeLabel()
Returns the label text to appear in a tree node.V
getValue()
Returns the value of thisAttribute
.java.lang.String
getValueStr()
java.lang.String
getValueStr(java.lang.String pattern)
java.lang.String
getXML()
Returns this object's XML representation as a single string.java.lang.String
getXML(int tab)
Returns this object's XML representation as a single string.static XMLObject
getXMLInstance(org.xml.sax.Attributes attributes)
java.lang.String
getXMLSchema()
Returns the XML schema for this object's XML representationvoid
handleXMLElementEnd(java.lang.String localName)
Handles the end of an XML element.void
handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
Handles the start of an XML element.void
handleXMLString(java.lang.String string)
Attempts to handle an XML string intended to set the value of thisAttribute
.boolean
isCopiable()
Is this attribute copiable?boolean
isEditable()
boolean
isNumeric()
boolean
isSecret()
InterfaceTreeNode
issueTreeNode()
Issues a new tree node and sets it usingAbstractInterfaceObject.setTreeNode(mgui.interfaces.trees.InterfaceTreeNode)
.void
removeAttributeListener(AttributeListener a)
void
setEditable(boolean b)
void
setFromAttribute(Attribute<V> a)
void
setFromAttribute(Attribute<V> a, boolean fire)
void
setName(java.lang.String name)
Sets the name for this object.void
setSecret(boolean b)
void
setTreeNode(InterfaceTreeNode treeNode)
Sets the children for this node'sInterfaceTreeNode
.boolean
setValue(java.lang.Object value)
Sets the value of this attribute, and notifies its listeners of the change.boolean
setValue(java.lang.Object value, boolean fire)
Sets the value of this attribute.boolean
setValue(java.lang.Object value, boolean fire, boolean ignore_editable)
Sets the value of this attribute.java.lang.String
toString()
void
writeXML(int tab, java.io.Writer writer)
Writes the XML representation of this object to file.void
writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar)
Writes the XML representation of this object to file, asXMLType.Normal
.void
writeXML(int tab, java.io.Writer writer, XMLObject.XMLType type, XMLObject.XMLEncoding format, ProgressUpdater progress_bar)
void
writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes the XML representation of this object to file.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
-
name
protected java.lang.String name -
value
-
object_class
-
isNumeric
protected boolean isNumeric -
isEditable
protected boolean isEditable -
isCopiable
protected boolean isCopiable -
isSecret
protected boolean isSecret
-
-
Constructor Details
-
Attribute
protected Attribute() -
Attribute
Instantiates a newAttribute
object.- Parameters:
thisName
- Name of the attributeclazz
- Class of this attribute's value
-
Attribute
Instantiates a newAttribute
object.- Parameters:
name
- Name of the attributevalue
- Value of the attribute
-
Attribute
Instantiates a newAttribute
object.- Parameters:
name
- Name of the attributevalue
- Value of the attributeisEditable
- Is this attribute editable?
-
Attribute
Instantiates a newAttribute
object.- Parameters:
name
- Name of the attributevalue
- Value of the attributeisEditable
- Is this attribute editable?isCopiable
- Is this attribute copiable?
-
-
Method Details
-
isCopiable
public boolean isCopiable()Is this attribute copiable?- Returns:
-
compareTo
- Specified by:
compareTo
in interfacejava.lang.Comparable<V>
-
getName
public java.lang.String getName()Description copied from interface:NamedObject
Gets the name for this object.- Specified by:
getName
in interfaceNamedObject
- Overrides:
getName
in classAbstractInterfaceObject
- Returns:
-
setName
public void setName(java.lang.String name)Description copied from interface:NamedObject
Sets the name for this object.- Specified by:
setName
in interfaceNamedObject
- Overrides:
setName
in classAbstractInterfaceObject
-
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 interfaceTreeObject
- Overrides:
getTreeLabel
in classAbstractInterfaceObject
- 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
-
setFromAttribute
-
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" istrue
.- 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 listenersignore_editable
- Iftrue
, ignores this attribute's "isEditable" state; otherwise the value will only be changed if "isEditable" istrue
- Returns:
-
getValue
Returns the value of thisAttribute
.- Returns:
-
clone
public java.lang.Object clone()- Overrides:
clone
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
issueTreeNode
Description copied from class:AbstractInterfaceObject
Issues a new tree node and sets it usingAbstractInterfaceObject.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 methodAbstractInterfaceObject.updateTreeNodes()
.- Specified by:
issueTreeNode
in interfaceTreeObject
- Overrides:
issueTreeNode
in classAbstractInterfaceObject
- Returns:
- a new
InterfaceTreeNode
-
setTreeNode
Description copied from interface:TreeObject
Sets the children for this node'sInterfaceTreeNode
.- Specified by:
setTreeNode
in interfaceTreeObject
- Overrides:
setTreeNode
in classAbstractInterfaceObject
-
getValueStr
public java.lang.String getValueStr() -
getValueStr
public java.lang.String getValueStr(java.lang.String pattern) -
addAttributeListener
-
removeAttributeListener
-
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 representationSee http://en.wikipedia.org/wiki/Document_Type_Definition for a description.
-
getLocalName
public java.lang.String getLocalName()Description copied from interface:XMLObject
Returns the local name associated with this XML object.- Specified by:
getLocalName
in interfaceXMLObject
- 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 theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
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 theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
getXMLSchema
public java.lang.String getXMLSchema()Description copied from interface:XMLObject
Returns the XML schema for this object's XML representation- Specified by:
getXMLSchema
in interfaceXMLObject
- 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 interfaceXMLObject
- Returns:
-
handleXMLElementEnd
public void handleXMLElementEnd(java.lang.String localName) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the end of an XML element.- Specified by:
handleXMLElementEnd
in interfaceXMLObject
- 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.SAXExceptionDescription copied from interface:XMLObject
Handles the start of an XML element.- Specified by:
handleXMLElementStart
in interfaceXMLObject
- Parameters:
localName
- Local name of the elementattributes
- Set of element attributestype
- TheXMLType
of this element- Throws:
org.xml.sax.SAXException
-
getObjectClass
Returns the object class for this parameterizedAttribute
.- Returns:
-
handleXMLString
public void handleXMLString(java.lang.String string) throws org.xml.sax.SAXExceptionAttempts to handle an XML string intended to set the value of thisAttribute
.- Specified by:
handleXMLString
in interfaceXMLObject
- Parameters:
string
- String to handle- Throws:
org.xml.sax.SAXException
-
getXMLInstance
-
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.IOExceptionDescription 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 ofXMLFormat.Ascii
will be used. -
writeXML
public void writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file, asXMLType.Normal
. The default format ofXMLFormat.Ascii
will be used. The basic contract for this method is that it should not write a newline character at its start or end. -
writeXML
public void writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription 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 ofXMLFormat.Ascii
will be used. -
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
-