JHotDraw 7.0.6

org.jhotdraw.draw
Class ConnectionTool

java.lang.Object
  extended by org.jhotdraw.draw.AbstractTool
      extended by org.jhotdraw.draw.ConnectionTool
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, FigureListener, Tool

public class ConnectionTool
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.


Field Summary
protected  boolean isPressed
           
protected  ConnectionFigure prototype
          the prototypical figure that is used to create new connections.
 
Fields inherited from class org.jhotdraw.draw.AbstractTool
anchor, editor, isWorking, listenerList
 
Constructor Summary
ConnectionTool(ConnectionFigure prototype)
          Creates a new instance.
ConnectionTool(ConnectionFigure prototype, java.util.Map attributes)
           
ConnectionTool(java.lang.String prototypeClassName)
           
ConnectionTool(java.lang.String prototypeClassName, java.util.Map<AttributeKey,java.lang.Object> attributes)
           
 
Method Summary
 void activate(DrawingEditor editor)
          Activates the tool for the given view.
protected  boolean canConnect(Figure start)
           
protected  boolean canConnect(Figure start, Figure end)
           
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 figureAreaInvalidated(FigureEvent evt)
          Sent when an area used by the figure needs to be repainted.
 void figureAttributeChanged(FigureEvent e)
          Sent when an attribute of the figure has changed.
 void figureChanged(FigureEvent e)
          Sent when the geometry (e.g.
 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  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.
protected  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()
           
 ConnectionFigure getPrototype()
           
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 setConnection(ConnectionFigure newConnection)
           
protected  void setCreatedFigure(Figure newCreatedFigure)
           
protected  void setEndConnector(Connector newEndConnector)
           
protected  void setStartConnector(Connector newStartConnector)
           
protected  void trackConnectors(java.awt.event.MouseEvent e)
           
 
Methods inherited from class org.jhotdraw.draw.AbstractTool
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireToolDone, fireToolStarted, getDrawing, getEditor, getView, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, removeToolListener, removeUndoableEditListener, updateCursor, viewToDrawing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prototype

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


isPressed

protected boolean isPressed
Constructor Detail

ConnectionTool

public ConnectionTool(ConnectionFigure prototype)
Creates a new instance.


ConnectionTool

public ConnectionTool(ConnectionFigure prototype,
                      java.util.Map attributes)

ConnectionTool

public ConnectionTool(java.lang.String prototypeClassName)

ConnectionTool

public ConnectionTool(java.lang.String prototypeClassName,
                      java.util.Map<AttributeKey,java.lang.Object> attributes)
Method Detail

getPrototype

public ConnectionFigure getPrototype()

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

canConnect

protected boolean canConnect(Figure start)

canConnect

protected boolean canConnect(Figure start,
                             Figure end)

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 view. This method is called whenever the user switches to this tool. Use this method to reinitialize a tool. Note, a valid view must be present in order for the tool to accept activation

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. Use this method to do some clean-up when the tool is switched. Subclassers should always call super.deactivate.

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

protected 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

protected 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

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

setStartConnector

protected void setStartConnector(Connector newStartConnector)

getStartConnector

protected Connector getStartConnector()

setEndConnector

protected void setEndConnector(Connector newEndConnector)

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.


setCreatedFigure

protected void setCreatedFigure(Figure newCreatedFigure)

figureAreaInvalidated

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

Specified by:
figureAreaInvalidated 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 (e.g. 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

figureAttributeChanged

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

Specified by:
figureAttributeChanged in interface FigureListener

Copyright 1996-2006 © JHotDraw.org