org.argouml.uml.diagram.ui
Class UMLDiagram

java.lang.Object
  extended byorg.tigris.gef.base.Diagram
      extended byorg.argouml.ui.ArgoDiagram
          extended byorg.argouml.uml.diagram.ui.UMLDiagram
All Implemented Interfaces:
EventListener, org.tigris.gef.graph.GraphListener, PropertyChangeListener, Serializable
Direct Known Subclasses:
UMLActivityDiagram, UMLClassDiagram, UMLCollaborationDiagram, UMLDeploymentDiagram, UMLSequenceDiagram, UMLStateDiagram, UMLUseCaseDiagram

public abstract class UMLDiagram
extends ArgoDiagram
implements PropertyChangeListener

This class provides support for writing a UML diagram for argo using the GEF framework.

It adds common buttons, a namespace, capability to delete itself when its namespace is deleted, some help with creating a valid diagram name.

There are various methods for returning 'structures' of Actions which are used to build toolbars and dropdown buttons within toolbars. These structures are arrays of Objects. An array element is actually either an Action, null or another array. When building a toolbar an Action is used to create a button and null is used to create a spacer in the toolbar. An element containing an array results in a dropdown toolbar button being created which contains all the items in that array.

The "owner" of the UMLDiagram needs to be set to the one and only UML modelelement of which the diagram depends. E.g. for a class diagram is that its namespace, and for a collaboration diagram is that the Collaboration UML object. Override the getOwner method to return the owner.

TODO: MVW: I am not sure of the following:
The "namespace" of the diagram is e.g. used when creating new elements that are shown on the diagram; they will have their namespace set according this. It is NOT necessarily equal to the "owner".

MVW: I am sure about the following:
The "namespace" of the diagram is e.g. used to register a listener to the UML model, to be notified if this element is removed; which will imply that this diagram has to be deleted, too. Hence the namespace of e.g. a collaboration diagram should be the represented classifier or, in case of a represented operation, its owner.

See Also:
Serialized Form

Field Summary
private static Action actionBroom
           
private static Action actionCircle
           
private static Action actionComment
          Tool to add a comment node.
private static Action actionCommentLink
          Tool to create an relationship between a comment node and some other node using a polyedge.
private static Action actionInk
           
private static Action actionLine
           
private static Action actionPoly
           
private static Action actionRectangle
           
private static Action actionRRectangle
           
private static Action actionSelect
           
private static Action actionSpline
           
private static Action actionText
           
private  int diagramSerial
          The serial number for new diagrams.
private static Logger LOG
           
private  Object namespace
           
(package private) static long serialVersionUID
           
private  JToolBar toolBar
           
 
Fields inherited from class org.argouml.ui.ArgoDiagram
 
Fields inherited from class org.tigris.gef.base.Diagram
_comments, _name, _toolBar, NAME_KEY, SCALE_KEY
 
Constructor Summary
UMLDiagram()
          The constructor.
UMLDiagram(Object ns)
           
UMLDiagram(String name, Object ns)
           
 
Method Summary
 void deselectAllTools()
          Set all toolbar buttons to unselected other then the toolbar button with the supplied action.
 void deselectOtherTools(Action otherThanAction)
          Set all toolbar buttons to unselected other then the toolbar button with the supplied action.
 Object[] getActions()
          Return actions available for building toolbar or similar.
 String getClassAndModelID()
           
private  Object[] getCommentActions()
          Get a 'structure' of actions for appending the comment tools to the toolbar.
 JToolBar getJToolBar()
          Get the toolbar for the diagram.
abstract  String getLabelName()
           
private  Object[] getManipulateActions()
          Get a 'structure' of actions for appending the manipulation mode tools to the toolbar.
 Object getNamespace()
           
protected  int getNextDiagramSerial()
           
 Object getOwner()
          The default implementation for diagrams that have the namespace as their owner.
private  Object[] getShapeActions()
          Get a 'structure' of actions for appending primitive drawing tools to the toolbar.
private  Object[] getShapePopupActions()
          Get a 'structure' of actions for showing in the shape primitives popup tool button.
protected abstract  Object[] getUmlActions()
          Implement in the ancestor to get a 'structure' of actions for appending the UML creation tools to the toolbar.
 void initialize(Object owner)
           
 void initToolBar()
          Create the toolbar based on actions for the specific diagram subclass.
protected  Action makeCreateAssociationAction(Object aggregationKind, boolean unidirectional, String descr)
          Factory method to build an Action for creating an association edge in the diagram.
protected  Action makeCreateEdgeAction(Object modelElement, String descr)
          Factory method to build an Action for creating an edge in the diagram.
protected  Action makeCreateNodeAction(Object modelElement, String descr)
          Factory method to build an Action for creating a node in the diagram.
 boolean needsToBeRemoved()
          This method shall indicate if the diagram needs to be removed because the modelelements on which it depends are removed.
 void propertyChange(PropertyChangeEvent evt)
          This diagram listens to events from its namespace ModelElement; when the modelelement is removed, we also want to delete this diagram.
 void removeAsTarget()
          Removes the UMLDiagram and all the figs on it as listener to UML Events.
 void resetDiagramSerial()
          Reset the diagram serial counter to the initial value.
 void setAsTarget()
          Adds the UMLDiagram and all the figs on it as listener to UML Events.
 void setNamespace(Object ns)
          Sets the namespace of the Diagram, and adds the diagram as a listener of its namespace in the UML model (so that it can delete itself when the model element is deleted).
 
Methods inherited from class org.argouml.ui.ArgoDiagram
damage, getContainingFig, getEdges, getItemUID, getNodes, getVetoMessage, setItemUID, setName, toString
 
Methods inherited from class org.tigris.gef.base.Diagram
add, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, bringForward, bringToFront, countContained, edgeAdded, edgeRemoved, elements, elementsIn, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getComments, getGraphController, getGraphModel, getLayer, getName, getScale, getShowSingleMultiplicity, getToolBar, graphChanged, hit, nodeAdded, nodeRemoved, postLoad, postSave, preSave, presentationFor, remove, remove, removeAll, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, reorder, sendBackward, sendToBack, setComments, setGraphModel, setLayer, setScale, setShowSingleMultiplicity, setToolBar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG

diagramSerial

private int diagramSerial
The serial number for new diagrams. Used to create an unique number for the name of the diagram.


actionComment

private static Action actionComment
Tool to add a comment node.


actionCommentLink

private static Action actionCommentLink
Tool to create an relationship between a comment node and some other node using a polyedge.


actionSelect

private static Action actionSelect

actionBroom

private static Action actionBroom

actionRectangle

private static Action actionRectangle

actionRRectangle

private static Action actionRRectangle

actionCircle

private static Action actionCircle

actionLine

private static Action actionLine

actionText

private static Action actionText

actionPoly

private static Action actionPoly

actionSpline

private static Action actionSpline

actionInk

private static Action actionInk

namespace

private Object namespace

toolBar

private JToolBar toolBar

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

UMLDiagram

public UMLDiagram()
The constructor.


UMLDiagram

public UMLDiagram(Object ns)
Parameters:
ns - the UML namespace of this diagram

UMLDiagram

public UMLDiagram(String name,
                  Object ns)
Parameters:
name - the name of the diagram
ns - the UML namespace of this diagram
Method Detail

initialize

public void initialize(Object owner)
Overrides:
initialize in class ArgoDiagram
See Also:
Diagram.initialize(java.lang.Object)

getNamespace

public Object getNamespace()
Returns:
the namespace for the diagram

setNamespace

public void setNamespace(Object ns)
Sets the namespace of the Diagram, and adds the diagram as a listener of its namespace in the UML model (so that it can delete itself when the model element is deleted).

Parameters:
ns - the namespace for the diagram

getClassAndModelID

public String getClassAndModelID()
See Also:
Diagram.getClassAndModelID()

getOwner

public Object getOwner()
The default implementation for diagrams that have the namespace as their owner.

Returns:
the namespace

getJToolBar

public JToolBar getJToolBar()
Get the toolbar for the diagram.

Returns:
the diagram toolbar

initToolBar

public void initToolBar()
Create the toolbar based on actions for the specific diagram subclass.

See Also:
Diagram.initToolBar()

getActions

public Object[] getActions()
Return actions available for building toolbar or similar.

Returns:
an array of available actions.

getUmlActions

protected abstract Object[] getUmlActions()
Implement in the ancestor to get a 'structure' of actions for appending the UML creation tools to the toolbar.

Returns:
the actions structure

getManipulateActions

private Object[] getManipulateActions()
Get a 'structure' of actions for appending the manipulation mode tools to the toolbar.

Returns:
the actions structure

getCommentActions

private Object[] getCommentActions()
Get a 'structure' of actions for appending the comment tools to the toolbar.

Returns:
the actions structure

getShapeActions

private Object[] getShapeActions()
Get a 'structure' of actions for appending primitive drawing tools to the toolbar.

Returns:
the actions structure

getShapePopupActions

private Object[] getShapePopupActions()
Get a 'structure' of actions for showing in the shape primitives popup tool button.

Returns:
the actions structure

propertyChange

public void propertyChange(PropertyChangeEvent evt)
This diagram listens to events from its namespace ModelElement; when the modelelement is removed, we also want to delete this diagram.

There is also a risk that if this diagram was the one shown in the diagram panel, then it will remain after it has been deleted. So we need to deselect this diagram.

Specified by:
propertyChange in interface PropertyChangeListener
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

removeAsTarget

public void removeAsTarget()
Removes the UMLDiagram and all the figs on it as listener to UML Events. Is called by setTarget in TabDiagram to improve performance.


setAsTarget

public void setAsTarget()
Adds the UMLDiagram and all the figs on it as listener to UML Events. Together with removeAsModelListener this is a performance improvement.


deselectOtherTools

public void deselectOtherTools(Action otherThanAction)
Set all toolbar buttons to unselected other then the toolbar button with the supplied action.

Parameters:
otherThanAction - the action of the button that is NOT to be deselected

deselectAllTools

public void deselectAllTools()
Set all toolbar buttons to unselected other then the toolbar button with the supplied action.


makeCreateNodeAction

protected Action makeCreateNodeAction(Object modelElement,
                                      String descr)
Factory method to build an Action for creating a node in the diagram.

Parameters:
modelElement - identifies the model element type to make
descr - the description to give this action.
Returns:
The action to create a new node.

makeCreateEdgeAction

protected Action makeCreateEdgeAction(Object modelElement,
                                      String descr)
Factory method to build an Action for creating an edge in the diagram.

Parameters:
modelElement - identifies the model element type to make
descr - the description to give this action.
Returns:
The action to create a new node.

makeCreateAssociationAction

protected Action makeCreateAssociationAction(Object aggregationKind,
                                             boolean unidirectional,
                                             String descr)
Factory method to build an Action for creating an association edge in the diagram.

Parameters:
aggregationKind - the type of aggregation for this association
unidirectional - true if this is a one way association.
descr - the description to give this action.
Returns:
The action to create a new association.

resetDiagramSerial

public void resetDiagramSerial()
Reset the diagram serial counter to the initial value. This should e.g. be done when the menuitem File->New is activated.


getNextDiagramSerial

protected int getNextDiagramSerial()
Returns:
Returns the diagramSerial.

getLabelName

public abstract String getLabelName()
Returns:
a string that can be used as a label for this kind of diagram

needsToBeRemoved

public boolean needsToBeRemoved()
This method shall indicate if the diagram needs to be removed because the modelelements on which it depends are removed. The default implementation is applicable to e.g. a ClassDiagram, which only depends on its namespace.

Matters get more complicated for e.g. a Statechart Diagram, which also depends on its context (the represented modelelement). Hence such a diagram needs to override this method.

Returns:
true if the diagram needs to be removed


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook