JHotDraw 7.2

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.

Version:
2.1 2007-05-18 Changed due to changes in the canConnect methods of the ConnectionFigure interface.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
 
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.
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.
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.
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, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.


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

findConnectionStart

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


getStartConnector

protected Connector getStartConnector()

getEndConnector

protected Connector getEndConnector()

getTargetConnector

protected Connector getTargetConnector()

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.


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

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