kaapo.project
Class ProjectComponent

java.lang.Object
  extended by kaapo.Observable
      extended by kaapo.project.ProjectComponent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Diagram, DiagramComponent

public abstract class ProjectComponent
extends Observable
implements Serializable

Abstract base class for diagrams, elements and connections. ProjectComponent maintains the attribute map that all project components have. The attribute map is a collection of name/value pairs. All attributes must be added to the project component with addAttribute.

Author:
hkovaska
See Also:
Attribute, Serialized Form

Nested Class Summary
static class ProjectComponent.ObservableMessage
           
 
Field Summary
protected  HashMap<String,Attribute> attributeMap
           
protected  AttributePanel attributePanel
           
 
Constructor Summary
ProjectComponent()
           
 
Method Summary
 void addAttribute(String name, Attribute.AttributeType type)
          Adds attribute to project component with null as initial value.
 void addAttribute(String name, Attribute.AttributeType type, Object value)
          Adds attribute to project component.
protected  AttributePanel buildAttributePanel(ProjectManager pm)
          Build a new attribute panel.
 Object getAttribute(String name)
          Returns the value of given attribute.
 Map<String,Attribute> getAttributeMap()
          Returns the attributes as a map.
 AttributePanel getAttributePanel(ProjectManager pm)
          Returns the attribute panel instance associated with this project component.
abstract  ImageIcon getSmallIcon()
          Returns a 16*16 icon representing the project component type.
abstract  String getTypeName()
          Returns the component type name formatted in a human-friendly manner.
 boolean hasAttribute(String name)
          Tells whether the attribute is in the attribute map.
 Object removeAttribute(String name)
          Removes attribute from project component.
 void setAttribute(String name, Object value)
          Sets the value of an attribute.
 
Methods inherited from class kaapo.Observable
addObserver, notifyObservers, notifyObservers, removeAllObservers, removeObserver, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributeMap

protected HashMap<String,Attribute> attributeMap

attributePanel

protected transient AttributePanel attributePanel
Constructor Detail

ProjectComponent

public ProjectComponent()
Method Detail

getSmallIcon

public abstract ImageIcon getSmallIcon()
Returns a 16*16 icon representing the project component type. The icon is used by GUI in the diagram tree.


getTypeName

public abstract String getTypeName()
Returns the component type name formatted in a human-friendly manner. For example, a UML class diagram type should return "Class Diagram" or "UML Class Diagram" or similar, not "classdiagram" or "uml_class_diagram".


hasAttribute

public boolean hasAttribute(String name)
Tells whether the attribute is in the attribute map.

Parameters:
name - Attribute name
Returns:
True if is member, false otherwise.

addAttribute

public void addAttribute(String name,
                         Attribute.AttributeType type,
                         Object value)
Adds attribute to project component.

Parameters:
name - Attribute name
type - Attribute type
value - Initial attribute value
Throws:
IllegalArgumentException - If an attribute with the same name is already in the project component or if the value is of wrong type. To replace an attribute, remove the old one first with removeAttribute.

addAttribute

public void addAttribute(String name,
                         Attribute.AttributeType type)
Adds attribute to project component with null as initial value.

Parameters:
name - Attribute name
type - Attribute type

getAttribute

public Object getAttribute(String name)
Returns the value of given attribute. The Object instance may be cast to a specialized class according to the rules documented in the Attribute class.

Parameters:
name - Attributename
Returns:
Value of the attribute; may be null if the value is null.
Throws:
IllegalArgumentException - if the attribute doesn't exist. If you're not sure whether the attribute exists, check with hasAttribute() first.
See Also:
Attribute

setAttribute

public void setAttribute(String name,
                         Object value)
Sets the value of an attribute.

Parameters:
name - Attribute name
value - New attribute value.
Throws:
IllegalArgumentException - if the attribute doesn't exist.

removeAttribute

public Object removeAttribute(String name)
Removes attribute from project component. After this, calls to getAttribute and setAttribute are illegal.

Parameters:
name - Name of the attribute to be removed.
Returns:
The value of the attribute just before it was removed.
Throws:
IllegalArgumentException - if the attribute doesn't exist.

getAttributeMap

public Map<String,Attribute> getAttributeMap()
Returns the attributes as a map. The map returned is a copy of the real map.

Returns:
Attribute map

buildAttributePanel

protected AttributePanel buildAttributePanel(ProjectManager pm)
Build a new attribute panel. This method must build a new instance on every call. The default implementation returns a GenericAttributePanel instance. If you want to make your own attribute panel, override this method.

Parameters:
pm - Project Manager
Returns:
A new attribute panel
See Also:
GenericAttributePanel

getAttributePanel

public AttributePanel getAttributePanel(ProjectManager pm)
Returns the attribute panel instance associated with this project component. Every call to this method returns the same panel instance.

Parameters:
pm - Project Manager. This is needed by the attribute panel because it must access the undo stack when modifying attributes.
Returns:
Attribute panel