com.rolemodelsoft.drawlet.basics
Class LocatorConnectionHandle

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
        |
        +--com.rolemodelsoft.drawlet.basics.CanvasHandle
              |
              +--com.rolemodelsoft.drawlet.basics.LocatorConnectionHandle

public class LocatorConnectionHandle
extends CanvasHandle
implements FigureHolder

This class provides a handle that allows the corresponding figure to be connected to (or disconnected from) another figure (as a slave to its location). For example, this could be used to attach a label to another figure.


Field Summary
protected  int anchorX
          The x coordinate at which the handle was first pressed.
protected  int anchorY
          The y coordinate at which the handle was first pressed.
protected  Locator connection
          The locator at which to show the current or pending connection (or null while there is none to be displayed).
protected  Figure figure
          The figure we may connect/disconnect.
protected  Locator locator
          The locator at which to visibly place the handle.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
canvas, halfWidth, HANDLE_SIZE, previousTool
 
Constructor Summary
LocatorConnectionHandle(Figure figure)
          Constructs and initializes a new instance of a handle which can connect a Figure's location to another figure
 
Method Summary
protected  java.awt.Color defaultConnectionColor()
          Answer the default Color to use to draw the connection.
protected  Locator defaultLocator(Figure figure)
          Answer the default/initial locator.
 java.awt.Rectangle getBounds()
          Returns the current bounds of this handle.
protected  java.awt.Rectangle getConnectionBounds()
          Returns the current bounds of the part of this handle that identifies to what the figure is connected.
protected  java.awt.Color getConnectionColor()
          Answer the Color to use to draw the connection.
 Figure getFigure()
          Returns the figure associated with this handle.
protected  java.awt.Rectangle getLocatorBounds()
          Returns the current bounds of the part of this handle that identifies the point of connection to the figure.
 boolean isConnected()
          Answer whether or not the figure is actually connected to something
 void mouseDragged(java.awt.event.MouseEvent evt)
          Called if the mouse is dragged (the mouse button is down).
 void mousePressed(java.awt.event.MouseEvent evt)
          Called if the mouse is down.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Called if the mouse is released.
 void paint(java.awt.Graphics g)
          Paints the handle.
 void setFigure(Figure figure)
          Set the figure associated with this handle.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
contains, defaultHandleSize, finished, getHandleHeight, getHandleSize, getHandleWidth, getX, getY, intersects, releaseControl, setHandleSize, takeControl
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDoubleClicked, mouseEntered, mouseExited, mouseMoved, mouseSingleClicked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

figure

protected Figure figure
The figure we may connect/disconnect.

locator

protected Locator locator
The locator at which to visibly place the handle.

connection

protected Locator connection
The locator at which to show the current or pending connection (or null while there is none to be displayed).

anchorX

protected int anchorX
The x coordinate at which the handle was first pressed.

anchorY

protected int anchorY
The y coordinate at which the handle was first pressed.
Constructor Detail

LocatorConnectionHandle

public LocatorConnectionHandle(Figure figure)
Constructs and initializes a new instance of a handle which can connect a Figure's location to another figure
Parameters:
figure - the figure which we may wish to connect/disconnect/reconnect
Method Detail

defaultConnectionColor

protected java.awt.Color defaultConnectionColor()
Answer the default Color to use to draw the connection.
Returns:
the default Color to use to draw the connection

defaultLocator

protected Locator defaultLocator(Figure figure)
Answer the default/initial locator.
Parameters:
figure - the figure to return the default locator for
Returns:
the default/initial Locator

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of this handle.
Overrides:
getBounds in class CanvasHandle
Returns:
a Rectangle representing the current bounds of this handle

getConnectionBounds

protected java.awt.Rectangle getConnectionBounds()
Returns the current bounds of the part of this handle that identifies to what the figure is connected.
Returns:
a Rectangle representing the current bounds of the part of this handle that identifies to what the figure is connected

getConnectionColor

protected java.awt.Color getConnectionColor()
Answer the Color to use to draw the connection.
Returns:
the Color to use to draw the connection

getFigure

public Figure getFigure()
Returns the figure associated with this handle.
Specified by:
getFigure in interface FigureHolder
Returns:
the Figure associated with this handle

getLocatorBounds

protected java.awt.Rectangle getLocatorBounds()
Returns the current bounds of the part of this handle that identifies the point of connection to the figure.
Returns:
a Rectangle representing the current bounds of the part of this handle that identifies the point of connection to the figure

isConnected

public boolean isConnected()
Answer whether or not the figure is actually connected to something
Returns:
boolean value of true if the figure is actually connected to something; false otherwise.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Called if the mouse is dragged (the mouse button is down). Ask for a connection if over a figure. Use it, or the coordinates to display the other side of the pending connection.
Overrides:
mouseDragged in class AbstractInputEventHandler
Parameters:
evt - the event

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Called if the mouse is down. Show the connection point, if there is one and record where the mouse went down.
Overrides:
mousePressed in class AbstractInputEventHandler
Parameters:
evt - the event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Called if the mouse is released. If it goes up over a figure that provides a valid connection, use it as the base of the new relative locator for the figure and make sure the figure is in front of the figure to which we are connecting it. Otherwise, (if the mouse did not go up in the same place it went down) change the figure's locator to one that is not relative to any others.
Overrides:
mouseReleased in class CanvasHandle
Parameters:
evt - the event

paint

public void paint(java.awt.Graphics g)
Paints the handle. Filled in if connected, hollow if not. Draw the otherwise invisible connection if actively editing.
Overrides:
paint in class CanvasHandle
Parameters:
g - the specified Graphics window

setFigure

public void setFigure(Figure figure)
Set the figure associated with this handle. Reset the locator.
Specified by:
setFigure in interface FigureHolder
Parameters:
figure - the Figure to hold