org.jhotdraw.draw
Class BidirectionalConnectionTool

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractTool
          extended by org.jhotdraw.draw.BidirectionalConnectionTool
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, FigureListener, Tool

public class BidirectionalConnectionTool
extends AbstractTool
implements FigureListener

A tool that can be used to connect figures, to split connections, and to join two segments of a connection. ConnectionTools turns the visibility of the Connectors on when it enters a figure. The connection object to be created is specified by a prototype.

FIXME: Use a Tracker instance for each state of this tool.

XXX - This tool is not needed anywhere. We should get rid of it.

Version:
$Id: BidirectionalConnectionTool.java 564 2009-10-10 10:21:01Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
private  java.util.Map<AttributeKey,java.lang.Object> attributes
           
private  ConnectionFigure connection
          the currently created figure
private  Figure createdFigure
          the figure that was actually added Note, this can be a different figure from the one which has been created.
private  ConnectionFigure editedConnection
          the currently edited connection
private  Connector endConnector
           
private  ConnectionFigure prototype
          the prototypical figure that is used to create new connections.
private  int splitPoint
          the currently manipulated connection point
private  Connector startConnector
          the anchor point of the interaction
private  Figure target
           
private  Connector targetConnector
           
 
Fields inherited from class org.jhotdraw.draw.AbstractTool
anchor, editor, isWorking, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Constructor Summary
BidirectionalConnectionTool(ConnectionFigure prototype)
          Creates a new instance.
BidirectionalConnectionTool(ConnectionFigure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes)
           
 
Method Summary
 void activate(DrawingEditor editor)
          Activates the tool for the given editor.
 void areaInvalidated(FigureEvent evt)
          Sent when the drawing area used by the figure needs to be repainted.
 void attributeChanged(FigureEvent e)
          Sent when an attribute of the figure has changed.
protected  ConnectionFigure createFigure()
          Creates the ConnectionFigure.
 void deactivate(DrawingEditor editor)
          Deactivates the tool.
 void draw(java.awt.Graphics2D g)
          Draws the tool.
 void figureAdded(FigureEvent e)
          Sent when a figure was added to a drawing.
 void figureChanged(FigureEvent e)
          Sent when the geometry (for example the bounds) of the figure has changed.
 void figureHandlesChanged(FigureEvent e)
          Sent when handles of a Figure have been added, removed or replaced.
 void figureRemoved(FigureEvent e)
          Sent when a figure was removed from a drawing.
 void figureRequestRemove(FigureEvent e)
          Sent when the figure requests to be removed from a drawing.
private  Figure findConnectableFigure(java.awt.geom.Point2D.Double p, Drawing drawing)
           
protected  ConnectionFigure findConnection(java.awt.geom.Point2D.Double p, Drawing drawing)
          Finds an existing connection figure.
protected  Figure findConnectionStart(java.awt.geom.Point2D.Double p, Drawing drawing)
          Finds a connection start figure.
private  Connector findConnector(java.awt.geom.Point2D.Double p, Figure target, ConnectionFigure f)
           
protected  Figure findSource(java.awt.geom.Point2D.Double p, Drawing drawing)
          Finds a connectable figure target.
protected  Figure findTarget(java.awt.geom.Point2D.Double p, Drawing drawing)
          Finds a connectable figure target.
protected  ConnectionFigure getConnection()
          Gets the connection which is created by this tool
protected  Figure getCreatedFigure()
          Gets the figure that was actually added Note, this can be a different figure from the one which has been created.
protected  Connector getEndConnector()
           
protected  Connector getStartConnector()
           
protected  Connector getTargetConnector()
           
protected  Figure getTargetFigure()
           
 void mouseDragged(java.awt.event.MouseEvent e)
          Adjust the created connection or split segment.
 void mouseMoved(java.awt.event.MouseEvent evt)
           
 void mousePressed(java.awt.event.MouseEvent evt)
          Manipulates connections in a context dependent way.
 void mouseReleased(java.awt.event.MouseEvent e)
          Connects the figures if the mouse is released over another figure.
private  void setConnection(ConnectionFigure newConnection)
           
private  void setCreatedFigure(Figure newCreatedFigure)
           
private  void setEndConnector(Connector newEndConnector)
           
private  void setStartConnector(Connector newStartConnector)
           
private  void setTargetConnector(Connector newTargetConnector)
           
private  void setTargetFigure(Figure newTarget)
           
protected  void trackConnectors(java.awt.event.MouseEvent e)
           
 
Methods inherited from class org.jhotdraw.draw.AbstractTool
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, createActionMap, createInputMap, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireToolDone, fireToolStarted, getActionMap, getDrawing, getEditor, getInputMap, getToolTipText, getView, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, supportsHandleInteraction, updateCursor, viewToDrawing
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

private java.util.Map<AttributeKey,java.lang.Object> attributes

startConnector

private Connector startConnector
the anchor point of the interaction


endConnector

private Connector endConnector

targetConnector

private Connector targetConnector

target

private Figure target

connection

private ConnectionFigure connection
the currently created figure


splitPoint

private int splitPoint
the currently manipulated connection point


editedConnection

private ConnectionFigure editedConnection
the currently edited connection


createdFigure

private Figure createdFigure
the figure that was actually added Note, this can be a different figure from the one which has been created.


prototype

private ConnectionFigure prototype
the prototypical figure that is used to create new connections.

Constructor Detail

BidirectionalConnectionTool

public BidirectionalConnectionTool(ConnectionFigure prototype)
Creates a new instance.


BidirectionalConnectionTool

public BidirectionalConnectionTool(ConnectionFigure prototype,
                                   java.util.Map<AttributeKey,java.lang.Object> attributes)
Method Detail

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class AbstractTool

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Manipulates connections in a context dependent way. If the mouse down hits a figure start a new connection. If the mousedown hits a connection split a segment or join two segments.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class AbstractTool

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Adjust the created connection or split segment.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Connects the figures if the mouse is released over another figure.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class AbstractTool

activate

public void activate(DrawingEditor editor)
Description copied from interface: Tool
Activates the tool for the given editor. This method is called whenever the user switches to this tool.

Specified by:
activate in interface Tool
Overrides:
activate in class AbstractTool

deactivate

public void deactivate(DrawingEditor editor)
Description copied from interface: Tool
Deactivates the tool. This method is called whenever the user switches to another tool.

Specified by:
deactivate in interface Tool
Overrides:
deactivate in class AbstractTool

createFigure

protected ConnectionFigure createFigure()
Creates the ConnectionFigure. By default the figure prototype is cloned.


findSource

protected Figure findSource(java.awt.geom.Point2D.Double p,
                            Drawing drawing)
Finds a connectable figure target.


findTarget

protected Figure findTarget(java.awt.geom.Point2D.Double p,
                            Drawing drawing)
Finds a connectable figure target.


findConnection

protected ConnectionFigure findConnection(java.awt.geom.Point2D.Double p,
                                          Drawing drawing)
Finds an existing connection figure.


setConnection

private void setConnection(ConnectionFigure newConnection)

getConnection

protected ConnectionFigure getConnection()
Gets the connection which is created by this tool


trackConnectors

protected void trackConnectors(java.awt.event.MouseEvent e)

draw

public void draw(java.awt.Graphics2D g)
Description copied from interface: Tool
Draws the tool.

Specified by:
draw in interface Tool
Overrides:
draw in class AbstractTool

findConnector

private Connector findConnector(java.awt.geom.Point2D.Double p,
                                Figure target,
                                ConnectionFigure f)

findConnectionStart

protected Figure findConnectionStart(java.awt.geom.Point2D.Double p,
                                     Drawing drawing)
Finds a connection start figure.


findConnectableFigure

private Figure findConnectableFigure(java.awt.geom.Point2D.Double p,
                                     Drawing drawing)

setStartConnector

private void setStartConnector(Connector newStartConnector)

getStartConnector

protected Connector getStartConnector()

setEndConnector

private void setEndConnector(Connector newEndConnector)

getEndConnector

protected Connector getEndConnector()

setTargetConnector

private void setTargetConnector(Connector newTargetConnector)

getTargetConnector

protected Connector getTargetConnector()

setTargetFigure

private void setTargetFigure(Figure newTarget)

getTargetFigure

protected Figure getTargetFigure()

getCreatedFigure

protected Figure getCreatedFigure()
Gets the figure that was actually added Note, this can be a different figure from the one which has been created.


setCreatedFigure

private void setCreatedFigure(Figure newCreatedFigure)

areaInvalidated

public void areaInvalidated(FigureEvent evt)
Description copied from interface: FigureListener
Sent when the drawing area used by the figure needs to be repainted.

Specified by:
areaInvalidated in interface FigureListener

figureAdded

public void figureAdded(FigureEvent e)
Description copied from interface: FigureListener
Sent when a figure was added to a drawing.

Specified by:
figureAdded in interface FigureListener

figureChanged

public void figureChanged(FigureEvent e)
Description copied from interface: FigureListener
Sent when the geometry (for example the bounds) of the figure has changed.

Specified by:
figureChanged in interface FigureListener

figureRemoved

public void figureRemoved(FigureEvent e)
Description copied from interface: FigureListener
Sent when a figure was removed from a drawing.

Specified by:
figureRemoved in interface FigureListener

figureRequestRemove

public void figureRequestRemove(FigureEvent e)
Description copied from interface: FigureListener
Sent when the figure requests to be removed from a drawing.

Specified by:
figureRequestRemove in interface FigureListener

attributeChanged

public void attributeChanged(FigureEvent e)
Description copied from interface: FigureListener
Sent when an attribute of the figure has changed.

Specified by:
attributeChanged in interface FigureListener

figureHandlesChanged

public void figureHandlesChanged(FigureEvent e)
Description copied from interface: FigureListener
Sent when handles of a Figure have been added, removed or replaced.

DrawingViews listen to this event to repopulate the Handles.

A Figure should not fire this event, if just the state or the location of Handle has changed.

Specified by:
figureHandlesChanged in interface FigureListener