kaapo.project
Class DiagramComponentWrapper

java.lang.Object
  extended by kaapo.Observable
      extended by kaapo.project.DiagramComponentWrapper
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
ConnectionWrapper, ElementWrapper

public abstract class DiagramComponentWrapper
extends Observable
implements Serializable, Cloneable

Abstract base class for element and connection wrappers.

For general info on the wrapper mechanism, see the documentation of Diagram.

Each diagram component wrapper maintains a list of incoming and outgoing connections to the wrapper.

If a wrapper needs to be cast to a concrete wrapper class (ElementWrapper or ConnectionWrapper) to access all available methods, it can be done with the following logic: if getDiagramComponent().isElement() returns true, it is safe to cast the wrapper to ElementWrapper; otherwise, it is safe to cast the wrapper to ConnectionWrapper.

See Also:
Diagram, Serialized Form

Field Summary
protected  DCGraphics dcgraphics
           
protected  DiagramComponent dComponent
           
protected  Vector<ConnectionWrapper> inConnections
           
protected  Vector<ConnectionWrapper> outConnections
           
 
Constructor Summary
protected DiagramComponentWrapper()
           
  DiagramComponentWrapper(DiagramComponent dc)
           
 
Method Summary
protected  void addConnection(ConnectionWrapper cw)
          Adds a connection to wrapper.
 boolean canMove()
          Tells whether the wrapper can be moved by user.
 boolean canResize()
          Tells whether the wrapper can be resized by user.
 DCGraphics getDCGraphics(ProjectManager pm)
          Returns the DCGraphics component associated to this wrapper.
 DiagramComponent getDiagramComponent()
          Returns the diagram component associated to this wrapper.
 List<ConnectionWrapper> getInConnections()
          Returns the incoming connections of the wrapper.
 List<ConnectionWrapper> getOutConnections()
          Returns the outgoing connections of the wrapper.
abstract  void moveXY(double changeX, double changeY, Selection selected)
          Moves a DiagramComponent in the Diagram this wrapper is in.
 void reinstateConnections(List<ConnectionWrapper> inConnections, List<ConnectionWrapper> outConnections)
          Reinstates all the connections removed with removeAllConnections.
 void removeAllConnections()
          Removes all connections from wrapper.
protected  boolean removeConnection(ConnectionWrapper cw)
          Removes a connection from wrapper.
 
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

dComponent

protected DiagramComponent dComponent

dcgraphics

protected transient DCGraphics dcgraphics

inConnections

protected Vector<ConnectionWrapper> inConnections

outConnections

protected Vector<ConnectionWrapper> outConnections
Constructor Detail

DiagramComponentWrapper

protected DiagramComponentWrapper()

DiagramComponentWrapper

public DiagramComponentWrapper(DiagramComponent dc)
Method Detail

getDCGraphics

public DCGraphics getDCGraphics(ProjectManager pm)
Returns the DCGraphics component associated to this wrapper. Every call to this method returns the same instance.

Parameters:
pm - Project manager

getDiagramComponent

public DiagramComponent getDiagramComponent()
Returns the diagram component associated to this wrapper.


addConnection

protected void addConnection(ConnectionWrapper cw)
Adds a connection to wrapper. Automatically determines whether the connection is an incoming or outcoming connection - or both.

If the connection is already part of the wrapper, this method does nothing.

Parameters:
cw - Connection wrapper to be added
Throws:
IllegalArgumentException - if neither the connection's start nor end point is this wrapper.

removeConnection

protected boolean removeConnection(ConnectionWrapper cw)
Removes a connection from wrapper. Also updates the start component and end component fields of the connection.

Parameters:
cw - The connection to be removed.
Returns:
True if the connection was removed, false if it was connected to this wrapper.

removeAllConnections

public void removeAllConnections()
Removes all connections from wrapper.


getInConnections

public List<ConnectionWrapper> getInConnections()
Returns the incoming connections of the wrapper. The connections have the end point set to this wrapper.

Returns:
List of connection wrappers; possibly empty, but not null. The list is a copy of the real list and can't be used to modify the connection list.

getOutConnections

public List<ConnectionWrapper> getOutConnections()
Returns the outgoing connections of the wrapper. The connections have the start point set to this wrapper.

Returns:
List of connection wrappers; possibly empty, but not null. The list is a copy of the real list and can't be used to modify the connection list.

reinstateConnections

public void reinstateConnections(List<ConnectionWrapper> inConnections,
                                 List<ConnectionWrapper> outConnections)
Reinstates all the connections removed with removeAllConnections.


canResize

public boolean canResize()
Tells whether the wrapper can be resized by user.


canMove

public boolean canMove()
Tells whether the wrapper can be moved by user.


moveXY

public abstract void moveXY(double changeX,
                            double changeY,
                            Selection selected)
Moves a DiagramComponent in the Diagram this wrapper is in.

Parameters:
changeX - change in x
changeY - change in y
selected - all the moved DiagramComponents