JHotDraw 6.0b1

org.jhotdraw.standard
Class ConnectionTool

java.lang.Object
  extended by org.jhotdraw.standard.AbstractTool
      extended by org.jhotdraw.standard.ConnectionTool
All Implemented Interfaces:
Tool
Direct Known Subclasses:
SplitConnectionTool

public class ConnectionTool
extends AbstractTool

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.


Design Patterns

 o Prototype
ConnectionTools creates the connection by cloning a prototype.


See Also:
ConnectionFigure, Object.clone()

Nested Class Summary
static class ConnectionTool.UndoActivity
           
 
Nested classes/interfaces inherited from class org.jhotdraw.standard.AbstractTool
AbstractTool.EventDispatcher
 
Constructor Summary
ConnectionTool(DrawingEditor newDrawingEditor, ConnectionFigure newPrototype)
           
 
Method Summary
protected  ConnectionFigure createConnection()
          Creates the ConnectionFigure.
protected  Undoable createUndoActivity()
          Factory method for undo activity
 void deactivate()
          Deactivates the tool.
protected  Figure findConnectableFigure(int x, int y, Drawing drawing)
          Returns the topmost? figure that can connect and is at the current mouse location.
protected  ConnectionFigure findConnection(int x, int y, Drawing drawing)
          Finds an existing connection figure.
protected  Figure findConnectionStart(int x, int y, Drawing drawing)
          Finds a connection start figure.
protected  Connector findConnector(int x, int y, Figure f)
           
protected  Figure findSource(int x, int y, Drawing drawing)
          Finds a connectable figure target.
protected  Figure findTarget(int x, int y, Drawing drawing)
          Finds a connectable figure target at the current mouse location that can 1.
protected  Figure getAddedFigure()
          Gets the figure that was actually added Note, this can be a different figure from the one which has been created.
protected  ConnectionFigure getConnection()
          Gets the connection which is created by this tool
protected  Connector getEndConnector()
           
protected  Connector getStartConnector()
           
protected  Connector getTargetConnector()
           
protected  Figure getTargetFigure()
           
 void mouseDown(java.awt.event.MouseEvent e, int x, int y)
          Manipulates connections in a context dependent way.
 void mouseDrag(java.awt.event.MouseEvent e, int x, int y)
          Adjust the created connection or split segment.
 void mouseMove(java.awt.event.MouseEvent e, int x, int y)
          Handles mouse move events in the drawing view.
 void mouseUp(java.awt.event.MouseEvent e, int x, int y)
          Connects the figures if the mouse is released over another figure.
protected  void setAddedFigure(Figure newAddedFigure)
           
protected  void setConnection(ConnectionFigure newConnection)
           
protected  void setEndConnector(Connector newEndConnector)
           
protected  void setStartConnector(Connector newStartConnector)
           
protected  void setTargetConnector(Connector newTargetConnector)
           
protected  void setTargetFigure(Figure newTarget)
           
protected  void trackConnectors(java.awt.event.MouseEvent e, int x, int y)
          Attempts to set the Connector to be connected to based on the current location of the mouse.
 
Methods inherited from class org.jhotdraw.standard.AbstractTool
activate, addToolListener, checkUsable, createEventDispatcher, createViewChangeListener, drawing, editor, getActiveDrawing, getActiveView, getAnchorX, getAnchorY, getEventDispatcher, getUndoActivity, isActive, isEnabled, isUsable, keyDown, removeToolListener, setAnchorX, setAnchorY, setEditor, setEnabled, setUndoActivity, setUsable, setView, view, viewCreated, viewDestroying, viewSelectionChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionTool

public ConnectionTool(DrawingEditor newDrawingEditor,
                      ConnectionFigure newPrototype)
Method Detail

mouseMove

public void mouseMove(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Handles mouse move events in the drawing view.

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

mouseDown

public void mouseDown(java.awt.event.MouseEvent e,
                      int x,
                      int y)
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:
mouseDown in interface Tool
Overrides:
mouseDown in class AbstractTool

mouseDrag

public void mouseDrag(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Adjust the created connection or split segment.

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

mouseUp

public void mouseUp(java.awt.event.MouseEvent e,
                    int x,
                    int y)
Connects the figures if the mouse is released over another figure.

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

deactivate

public void deactivate()
Description copied from class: AbstractTool
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. An inactive tool should never be deactivated

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

createConnection

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


findSource

protected Figure findSource(int x,
                            int y,
                            Drawing drawing)
Finds a connectable figure target.


findTarget

protected Figure findTarget(int x,
                            int y,
                            Drawing drawing)
Finds a connectable figure target at the current mouse location that can 1. Connect to things 2. Is not already connected to the current Connection (no self connection) 3. The current Connection can make a connection between it and the start figure.


findConnection

protected ConnectionFigure findConnection(int x,
                                          int y,
                                          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,
                               int x,
                               int y)
Attempts to set the Connector to be connected to based on the current location of the mouse.


findConnector

protected Connector findConnector(int x,
                                  int y,
                                  Figure f)

findConnectionStart

protected Figure findConnectionStart(int x,
                                     int y,
                                     Drawing drawing)
Finds a connection start figure.


findConnectableFigure

protected Figure findConnectableFigure(int x,
                                       int y,
                                       Drawing drawing)
Returns the topmost? figure that can connect and is at the current mouse location.


setStartConnector

protected void setStartConnector(Connector newStartConnector)

getStartConnector

protected Connector getStartConnector()

setEndConnector

protected void setEndConnector(Connector newEndConnector)

getEndConnector

protected Connector getEndConnector()

setTargetConnector

protected void setTargetConnector(Connector newTargetConnector)

getTargetConnector

protected Connector getTargetConnector()

setTargetFigure

protected void setTargetFigure(Figure newTarget)

getTargetFigure

protected Figure getTargetFigure()

getAddedFigure

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


setAddedFigure

protected void setAddedFigure(Figure newAddedFigure)

createUndoActivity

protected Undoable createUndoActivity()
Factory method for undo activity


JHotDraw 6.0b1