JHotDraw 7.4.1

org.jhotdraw.draw
Class LineConnectionFigure

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractFigure
          extended by org.jhotdraw.draw.AbstractAttributedFigure
              extended by org.jhotdraw.draw.BezierFigure
                  extended by org.jhotdraw.draw.LineFigure
                      extended by org.jhotdraw.draw.LineConnectionFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ConnectionFigure, Figure, DOMStorable
Direct Known Subclasses:
DependencyFigure, LabeledLineConnectionFigure

public class LineConnectionFigure
extends LineFigure
implements ConnectionFigure

A ConnectionFigure which connects two figures using a bezier path.

The bezier path can be laid out manually using bezier handles provided by this figure, or automatically using a Liner which can be set using the JavaBeans property liner.

Version:
$Id: LineConnectionFigure.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
static java.lang.String LINER_PROPERTY
          The name of the JaveBeans property liner.
 
Fields inherited from class org.jhotdraw.draw.BezierFigure
path
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Fields inherited from interface org.jhotdraw.draw.Figure
CONNECTABLE_PROPERTY, REMOVABLE_PROPERTY, SELECTABLE_PROPERTY, TRANSFORMABLE_PROPERTY
 
Constructor Summary
LineConnectionFigure()
          Creates a new instance.
 
Method Summary
 void addNotify(Drawing drawing)
          This method is invoked, when the Figure is being removed from a Drawing.
 boolean canConnect(Connector start)
          Checks if this ConnectionFigure can be connect to the specified Connector.
 boolean canConnect(Connector start, Connector end)
          Returns true, if this ConnectionFigure can connect the specified Connectors.
 LineConnectionFigure clone()
          Returns a clone of the figure, with clones of all aggregated figures, such as children and decorators.
 java.util.Collection<Handle> createHandles(int detailLevel)
          Gets the handles of the figure.
 BezierPath getBezierPath()
          FIXME - Liner must work with API of LineConnection!
 Connector getEndConnector()
          Gets the end Connector.
 Figure getEndFigure()
          Gets the end figure of the connection.
 Liner getLiner()
          Get a Liner object which encapsulated a lineout algorithm for this figure.
 Connector getStartConnector()
          Gets the start Connector.
 Figure getStartFigure()
          Gets the start figure of the connection.
protected  void handleConnect(Connector start, Connector end)
          Handles the connection of a connection.
protected  void handleDisconnect(Connector start, Connector end)
          Handles the disconnection of a connection.
 boolean handleMouseClick(java.awt.geom.Point2D.Double p, java.awt.event.MouseEvent evt, DrawingView view)
          Handles a mouse click.
 void lineout()
          A lineout algorithm is used to define how the child components should be laid out in relation to each other.
 void read(DOMInput in)
           
protected  void readLiner(DOMInput in)
           
protected  void readPoints(DOMInput in)
           
 void remap(java.util.Map<Figure,Figure> oldToNew, boolean disconnectIfNotInMap)
          After cloning a collection of figures, the ConnectionFigures contained in this collection still connect to the original figures instead of to the clones.
 void removeNotify(Drawing drawing)
          This method is invoked, when the Figure is being removed from a Drawing.
 void reverseConnection()
           
 void setConnectable(boolean newValue)
          ConnectionFigures cannot be connected and always sets connectable to false.
 void setEndConnector(Connector newEnd)
          Sets the end Connector of the connection.
 void setEndPoint(java.awt.geom.Point2D.Double p)
          Convenience method for setting the point coordinate of the end point.
 void setLiner(Liner newValue)
          Set a Liner object which encapsulated a lineout algorithm for this figure.
 void setNode(int index, BezierPath.Node p)
          Sets a control point.
 void setPoint(int index, java.awt.geom.Point2D.Double p)
          Sets the point coordinate of control point 0 at the specified node.
 void setStartConnector(Connector newStart)
          Sets the start Connector of the connection.
 void setStartPoint(java.awt.geom.Point2D.Double p)
          Convenience method for setting the point coordinate of the start point.
 void transform(java.awt.geom.AffineTransform tx)
          Ensures that a connection is updated if the connection was moved.
 void updateConnection()
          Updates the start and end point of the figure and fires figureChanged events.
 void validate()
           
 void write(DOMOutput out)
           
protected  void writeLiner(DOMOutput out)
           
protected  void writePoints(DOMOutput out)
           
 
Methods inherited from class org.jhotdraw.draw.BezierFigure
addNode, addNode, chop, contains, drawCaps, drawFill, drawStroke, findCompatibleConnector, findConnector, findNode, findSegment, getBounds, getCappedPath, getCenter, getDrawingArea, getEndPoint, getNode, getNodeCount, getOutermostPoint, getPoint, getPoint, getPointOnPath, getStartPoint, getTransformRestoreData, invalidate, isClosed, joinSegments, joinSegments, layout, removeAllNodes, removeNode, restoreTransformTo, set, setBezierPath, setBounds, setClosed, setPoint, splitSegment, splitSegment
 
Methods inherited from class org.jhotdraw.draw.AbstractAttributedFigure
applyAttributesTo, draw, drawText, get, getAttributeKey, getAttributes, getAttributesRestoreData, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, restoreAttributesTo, setAttributeEnabled, setAttributes, writeAttributes
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, basicClone, changed, findFigureInside, fireAreaInvalidated, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureHandlesChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getConnectors, getCursor, getDecomposition, getDrawing, getFontRenderContext, getLayer, getLock, getPreferredSize, getTool, getToolTipText, handleDrop, includes, isChanging, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, removeFigureListener, requestRemove, setBounds, setRemovable, setSelectable, setTransformable, setVisible, toString, willChange
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.ConnectionFigure
getEndPoint, getNode, getNodeCount, getPoint, getStartPoint
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addPropertyChangeListener, changed, contains, draw, findCompatibleConnector, findConnector, findFigureInside, get, getActions, getAttributes, getAttributesRestoreData, getBounds, getConnectors, getCursor, getDecomposition, getDrawingArea, getLayer, getPreferredSize, getTool, getToolTipText, getTransformRestoreData, handleDrop, includes, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, removeFigureListener, removePropertyChangeListener, requestRemove, restoreAttributesTo, restoreTransformTo, set, setBounds, willChange
 

Field Detail

LINER_PROPERTY

public static final java.lang.String LINER_PROPERTY
The name of the JaveBeans property liner.

See Also:
Constant Field Values
Constructor Detail

LineConnectionFigure

public LineConnectionFigure()
Creates a new instance.

Method Detail

transform

public void transform(java.awt.geom.AffineTransform tx)
Ensures that a connection is updated if the connection was moved.

Specified by:
transform in interface Figure
Overrides:
transform in class BezierFigure
Parameters:
tx - The transformation.
See Also:
Figure.getTransformRestoreData(), Figure.restoreTransformTo(java.lang.Object)

createHandles

public java.util.Collection<Handle> createHandles(int detailLevel)
Gets the handles of the figure. It returns the normal PolylineHandles but adds ChangeConnectionHandles at the start and end.

Specified by:
createHandles in interface Figure
Overrides:
createHandles in class LineFigure
Parameters:
detailLevel - The detail level of the handles. Usually this is 0 for bounding box handles and 1 for point handles. The value -1 is used by the SelectAreaTracker and the HandleTracker to highlight figures, over which the mouse pointer is hovering.
Returns:
a Collection of handles
See Also:
Handle

setConnectable

public void setConnectable(boolean newValue)
ConnectionFigures cannot be connected and always sets connectable to false.

Overrides:
setConnectable in class AbstractFigure

updateConnection

public void updateConnection()
Description copied from interface: ConnectionFigure
Updates the start and end point of the figure and fires figureChanged events.

Specified by:
updateConnection in interface ConnectionFigure

validate

public void validate()
Overrides:
validate in class BezierFigure

canConnect

public boolean canConnect(Connector start,
                          Connector end)
Description copied from interface: ConnectionFigure
Returns true, if this ConnectionFigure can connect the specified Connectors. Implement this method to constrain the allowed connections between figures.

Specified by:
canConnect in interface ConnectionFigure

getEndConnector

public Connector getEndConnector()
Description copied from interface: ConnectionFigure
Gets the end Connector. Returns null, if there is no end connection.

Specified by:
getEndConnector in interface ConnectionFigure

getEndFigure

public Figure getEndFigure()
Description copied from interface: ConnectionFigure
Gets the end figure of the connection. This is a convenience method for doing getEndConnector().getOwner() and handling null cases.

Specified by:
getEndFigure in interface ConnectionFigure

getStartConnector

public Connector getStartConnector()
Description copied from interface: ConnectionFigure
Gets the start Connector. Returns null, if there is no start connection.

Specified by:
getStartConnector in interface ConnectionFigure

getStartFigure

public Figure getStartFigure()
Description copied from interface: ConnectionFigure
Gets the start figure of the connection. This is a convenience method for doing getStartConnector().getOwner() and handling null cases.

Specified by:
getStartFigure in interface ConnectionFigure

setEndConnector

public void setEndConnector(Connector newEnd)
Description copied from interface: ConnectionFigure
Sets the end Connector of the connection. Set this to null to disconnect the end connection.

Specified by:
setEndConnector in interface ConnectionFigure
Parameters:
newEnd - the end Connector of the connection

setStartConnector

public void setStartConnector(Connector newStart)
Description copied from interface: ConnectionFigure
Sets the start Connector of the connection. Set this to null to disconnect the start connection.

Specified by:
setStartConnector in interface ConnectionFigure
Parameters:
newStart - the start Connector of the connection

addNotify

public void addNotify(Drawing drawing)
This method is invoked, when the Figure is being removed from a Drawing. This method invokes handleConnect, if the Figure is connected.

Specified by:
addNotify in interface Figure
Overrides:
addNotify in class AbstractFigure
See Also:
handleConnect(org.jhotdraw.draw.connector.Connector, org.jhotdraw.draw.connector.Connector)

removeNotify

public void removeNotify(Drawing drawing)
This method is invoked, when the Figure is being removed from a Drawing. This method invokes handleDisconnect, if the Figure is connected.

Specified by:
removeNotify in interface Figure
Overrides:
removeNotify in class AbstractFigure
See Also:
handleDisconnect(org.jhotdraw.draw.connector.Connector, org.jhotdraw.draw.connector.Connector)

handleDisconnect

protected void handleDisconnect(Connector start,
                                Connector end)
Handles the disconnection of a connection. Override this method to handle this event.

Note: This method is only invoked, when the Figure is part of a Drawing. If the Figure is removed from a Drawing, this method is invoked on behalf of the removeNotify call to the Figure.

See Also:
removeNotify(org.jhotdraw.draw.Drawing)

handleConnect

protected void handleConnect(Connector start,
                             Connector end)
Handles the connection of a connection. Override this method to handle this event.

Note: This method is only invoked, when the Figure is part of a Drawing. If the Figure is added to a Drawing this method is invoked on behalf of the addNotify call to the Figure.


clone

public LineConnectionFigure clone()
Description copied from interface: Figure
Returns a clone of the figure, with clones of all aggregated figures, such as children and decorators. The cloned figure does not clone the list of FigureListeners from its original.

Specified by:
clone in interface Figure
Overrides:
clone in class BezierFigure

remap

public void remap(java.util.Map<Figure,Figure> oldToNew,
                  boolean disconnectIfNotInMap)
Description copied from interface: Figure
After cloning a collection of figures, the ConnectionFigures contained in this collection still connect to the original figures instead of to the clones. Using This operation and providing a map, which maps from the original collection of figures to the new collection, connections can be remapped to the new figures.

Specified by:
remap in interface Figure
Overrides:
remap in class AbstractFigure

canConnect

public boolean canConnect(Connector start)
Description copied from interface: ConnectionFigure
Checks if this ConnectionFigure can be connect to the specified Connector. This is used to provide an early feedback to the user, when he/she creates a new connection.

Specified by:
canConnect in interface ConnectionFigure

handleMouseClick

public boolean handleMouseClick(java.awt.geom.Point2D.Double p,
                                java.awt.event.MouseEvent evt,
                                DrawingView view)
Handles a mouse click.

Specified by:
handleMouseClick in interface Figure
Overrides:
handleMouseClick in class LineFigure
Parameters:
p - The location of the mouse event.
evt - The mouse event.
view - The drawing view which is the source of the mouse event.
Returns:
Returns true, if the event was consumed.

readPoints

protected void readPoints(DOMInput in)
                   throws java.io.IOException
Overrides:
readPoints in class BezierFigure
Throws:
java.io.IOException

read

public void read(DOMInput in)
          throws java.io.IOException
Specified by:
read in interface DOMStorable
Overrides:
read in class BezierFigure
Throws:
java.io.IOException

readLiner

protected void readLiner(DOMInput in)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public void write(DOMOutput out)
           throws java.io.IOException
Specified by:
write in interface DOMStorable
Overrides:
write in class BezierFigure
Throws:
java.io.IOException

writeLiner

protected void writeLiner(DOMOutput out)
                   throws java.io.IOException
Throws:
java.io.IOException

writePoints

protected void writePoints(DOMOutput out)
                    throws java.io.IOException
Overrides:
writePoints in class BezierFigure
Throws:
java.io.IOException

setLiner

public void setLiner(Liner newValue)
Description copied from interface: ConnectionFigure
Set a Liner object which encapsulated a lineout algorithm for this figure. Typically, a Liner accesses the child components of this figure and arranges their graphical presentation.

Specified by:
setLiner in interface ConnectionFigure
Parameters:
newValue - encapsulation of a lineout algorithm.

setNode

public void setNode(int index,
                    BezierPath.Node p)
Description copied from class: BezierFigure
Sets a control point.

Specified by:
setNode in interface ConnectionFigure
Overrides:
setNode in class BezierFigure

lineout

public void lineout()
Description copied from interface: ConnectionFigure
A lineout algorithm is used to define how the child components should be laid out in relation to each other. The task for lineouting the child components for presentation is delegated to a Liner which can be plugged in at runtime.

Specified by:
lineout in interface ConnectionFigure

getBezierPath

public BezierPath getBezierPath()
FIXME - Liner must work with API of LineConnection!

Overrides:
getBezierPath in class BezierFigure

getLiner

public Liner getLiner()
Description copied from interface: ConnectionFigure
Get a Liner object which encapsulated a lineout algorithm for this figure. Typically, a Liner accesses the child components of this figure and arranges their graphical presentation.

Specified by:
getLiner in interface ConnectionFigure
Returns:
lineout strategy used by this figure

setStartPoint

public void setStartPoint(java.awt.geom.Point2D.Double p)
Description copied from class: BezierFigure
Convenience method for setting the point coordinate of the start point. If the BezierFigure has not at least two nodes, nodes are added to the figure until the BezierFigure has at least two nodes.

Specified by:
setStartPoint in interface ConnectionFigure
Overrides:
setStartPoint in class BezierFigure

setPoint

public void setPoint(int index,
                     java.awt.geom.Point2D.Double p)
Description copied from class: BezierFigure
Sets the point coordinate of control point 0 at the specified node.

Specified by:
setPoint in interface ConnectionFigure
Overrides:
setPoint in class BezierFigure

setEndPoint

public void setEndPoint(java.awt.geom.Point2D.Double p)
Description copied from class: BezierFigure
Convenience method for setting the point coordinate of the end point. If the BezierFigure has not at least two nodes, nodes are added to the figure until the BezierFigure has at least two nodes.

Specified by:
setEndPoint in interface ConnectionFigure
Overrides:
setEndPoint in class BezierFigure

reverseConnection

public void reverseConnection()

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.