org.jhotdraw.draw.tool
Class ConnectionTool
- java.lang.Object
-
- org.jhotdraw.beans.AbstractBean
-
- org.jhotdraw.draw.tool.AbstractTool
-
- org.jhotdraw.draw.tool.ConnectionTool
-
- All Implemented Interfaces:
- java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, Tool
public class ConnectionTool extends AbstractTool
A tool to create a connection between two figures. TheConnectionFigureto be created is specified by a prototype. The location of the start and end points are controlled byConnectors.To create a connection using the ConnectionTool, the user does the following mouse gestures on a DrawingView:
- Press the mouse button inside of a Figure. If the ConnectionTool can find a Connector at this location, it uses it as the starting point for the connection.
- Drag the mouse while keeping the mouse button pressed, and then release the mouse button. This defines the end point of the connection. If the ConnectionTool finds a Connector at this location, it uses it as the end point of the connection and creates a ConnectionFigure.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ConnectionTool(ConnectionFigure prototype)Creates a new instance.ConnectionTool(ConnectionFigure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes)ConnectionTool(ConnectionFigure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes, java.lang.String presentationName)ConnectionTool(java.lang.String prototypeClassName)ConnectionTool(java.lang.String prototypeClassName, java.util.Map<AttributeKey,java.lang.Object> attributes, java.lang.String presentationName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidactivate(DrawingEditor editor)Activates the tool for the given editor.voiddeactivate(DrawingEditor editor)Deactivates the tool.voiddraw(java.awt.Graphics2D g)Draws the tool.ConnectionFiguregetPrototype()booleanisToolDoneAfterCreation()Returns true, if this tool fires toolDone immediately after a new figure has been created.voidmouseDragged(java.awt.event.MouseEvent e)Adjust the created connection.voidmouseMoved(java.awt.event.MouseEvent evt)voidmousePressed(java.awt.event.MouseEvent evt)Manipulates connections in a context dependent way.voidmouseReleased(java.awt.event.MouseEvent e)Connects the figures if the mouse is released over another figure.voidrepaintConnectors(java.awt.event.MouseEvent evt)Updates the list of connectors that we draw when the user moves or drags the mouse over a figure to which can connect.voidsetToolDoneAfterCreation(boolean newValue)If this is set to false, the CreationTool does not fire toolDone after a new Figure has been created.-
Methods inherited from class org.jhotdraw.draw.tool.AbstractTool
addToolListener, addUndoableEditListener, editCopy, editCut, editDelete, editDuplicate, editPaste, getActionMap, getInputMap, getToolTipText, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, supportsHandleInteraction, updateCursor
-
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
ConnectionTool
public ConnectionTool(ConnectionFigure prototype)
Creates a new instance.
-
ConnectionTool
public ConnectionTool(ConnectionFigure prototype, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes)
-
ConnectionTool
public ConnectionTool(ConnectionFigure prototype, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes, @Nullable java.lang.String presentationName)
-
ConnectionTool
public ConnectionTool(java.lang.String prototypeClassName)
-
ConnectionTool
public ConnectionTool(java.lang.String prototypeClassName, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes, @Nullable java.lang.String presentationName)
-
-
Method Detail
-
getPrototype
public ConnectionFigure getPrototype()
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent evt)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseMovedin classAbstractTool
-
repaintConnectors
public void repaintConnectors(java.awt.event.MouseEvent evt)
Updates the list of connectors that we draw when the user moves or drags the mouse over a figure to which can connect.
-
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:
mousePressedin interfacejava.awt.event.MouseListener- Overrides:
mousePressedin classAbstractTool
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
Adjust the created connection.
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
Connects the figures if the mouse is released over another figure.- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Overrides:
mouseReleasedin classAbstractTool
-
activate
public void activate(DrawingEditor editor)
Description copied from interface:ToolActivates the tool for the given editor. This method is called whenever the user switches to this tool.- Specified by:
activatein interfaceTool- Overrides:
activatein classAbstractTool
-
deactivate
public void deactivate(DrawingEditor editor)
Description copied from interface:ToolDeactivates the tool. This method is called whenever the user switches to another tool.- Specified by:
deactivatein interfaceTool- Overrides:
deactivatein classAbstractTool
-
draw
public void draw(java.awt.Graphics2D g)
Description copied from interface:ToolDraws the tool.- Specified by:
drawin interfaceTool- Overrides:
drawin classAbstractTool
-
setToolDoneAfterCreation
public void setToolDoneAfterCreation(boolean newValue)
If this is set to false, the CreationTool does not fire toolDone after a new Figure has been created. This allows to create multiple figures consecutively.
-
isToolDoneAfterCreation
public boolean isToolDoneAfterCreation()
Returns true, if this tool fires toolDone immediately after a new figure has been created.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG