com.rolemodelsoft.drawlet.shapes.lines
Class ConnectedLineCreationHandle

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
        |
        +--com.rolemodelsoft.drawlet.basics.CanvasHandle
              |
              +--com.rolemodelsoft.drawlet.basics.SquareCanvasHandle
                    |
                    +--com.rolemodelsoft.drawlet.shapes.lines.ConnectedLineCreationHandle
Direct Known Subclasses:
AdornedLineCreationHandle

public class ConnectedLineCreationHandle
extends SquareCanvasHandle
implements FigureHolder

This class provides a handle that creates connected lines from one figure to another.


Field Summary
protected  Figure figure
          The figure to which the handle is attached.
protected  ConnectingLine line
          The line being constructed.
protected  Locator locator
          The location at which the handle is displayed which will also serve as a prototype of the starting point of any line.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
canvas, halfWidth, HANDLE_SIZE, previousTool
 
Constructor Summary
ConnectedLineCreationHandle(Figure figure)
          Construct and initialize a handle that will create connecting lines from a figure to some other figure.
ConnectedLineCreationHandle(Figure figure, Locator locator)
          Construct and initialize a handle that will create connecting lines from a figure to some other figure.
 
Method Summary
protected  ConnectingLine basicNewLine(Locator point)
          Answers a new ConnectingLine.
protected  int centerX()
          Answer the x coordinate at the center of the handle.
protected  int centerY()
          Answer the y coordinate at the center of the handle.
protected  Locator defaultLocator(Figure figure)
          Answer the default/initial locator.
 Figure getFigure()
          Returns the figure associated with this handle.
protected  void mouseDoubleClicked(java.awt.event.MouseEvent evt)
          Called if the mouse is double-clicked.
 void mouseDragged(java.awt.event.MouseEvent evt)
          Called if the mouse is dragged (the mouse button is down).
 void mouseMoved(java.awt.event.MouseEvent evt)
          Called if the mouse is moved (the mouse button is up).
 void mousePressed(java.awt.event.MouseEvent evt)
          Called when the mouse goes down.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Called if the mouse goes up.
protected  void movePoint(int pointIndex, int x, int y)
          Move the identified point of the line.
 void paint(java.awt.Graphics g)
          Paints the handle.
 void releaseControl(DrawingCanvas canvas)
          Release control of the canvas and clean up if necessary.
 void setFigure(Figure figure)
          Set the figure associated with this handle.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.SquareCanvasHandle
getBounds
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
contains, defaultHandleSize, finished, getHandleHeight, getHandleSize, getHandleWidth, getX, getY, intersects, setHandleSize, takeControl
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, 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 to which the handle is attached.

locator

protected Locator locator
The location at which the handle is displayed which will also serve as a prototype of the starting point of any line. This will typically be a FigureRelativePoint, but not necessarily.

line

protected ConnectingLine line
The line being constructed.
Constructor Detail

ConnectedLineCreationHandle

public ConnectedLineCreationHandle(Figure figure)
Construct and initialize a handle that will create connecting lines from a figure to some other figure.
Parameters:
figure - the figure to which the handle is attached.

ConnectedLineCreationHandle

public ConnectedLineCreationHandle(Figure figure,
                                   Locator locator)
Construct and initialize a handle that will create connecting lines from a figure to some other figure.
Parameters:
figure - the figure to which the handle is attached.
locator - the locator at which to locate the handle and beginning of any lines.
Method Detail

basicNewLine

protected ConnectingLine basicNewLine(Locator point)
Answers a new ConnectingLine. This is a template method.
Parameters:
point - the point at which the new line should start.
Returns:
a new ConnectingLine.

centerX

protected int centerX()
Answer the x coordinate at the center of the handle.
Overrides:
centerX in class SquareCanvasHandle
Returns:
an integer representing the x coordinate at the center of the handle

centerY

protected int centerY()
Answer the y coordinate at the center of the handle.
Overrides:
centerY in class SquareCanvasHandle
Returns:
an integer representing the y coordinate at the center of the handle

defaultLocator

protected Locator defaultLocator(Figure figure)
Answer the default/initial locator.
Parameters:
figure - the Figure the Locator is to be relative to.
Returns:
the default/initial Locator

getFigure

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

mouseDoubleClicked

protected void mouseDoubleClicked(java.awt.event.MouseEvent evt)
Called if the mouse is double-clicked.
Overrides:
mouseDoubleClicked in class AbstractInputEventHandler
Parameters:
evt - the event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Called if the mouse is dragged (the mouse button is down). If in the midst of constructing a line, move its latest point.
Overrides:
mouseDragged in class AbstractInputEventHandler
Parameters:
evt - the event
See Also:
movePoint(int, int, int)

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Called if the mouse is moved (the mouse button is up). If in the midst of constructing a line, move its latest point.
Overrides:
mouseMoved in class AbstractInputEventHandler
Parameters:
evt - the event
See Also:
movePoint(int, int, int)

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Called when the mouse goes down. If we're not already in the midst of constructing a line, start one.
Overrides:
mousePressed in class AbstractInputEventHandler
Parameters:
evt - the event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Called if the mouse goes up. Connect the latest point to any underlying figure if possible. If the shift key is down, add a point and keep constructing. If not, we're done.
Overrides:
mouseReleased in class CanvasHandle
Parameters:
evt - the event

movePoint

protected void movePoint(int pointIndex,
                         int x,
                         int y)
Move the identified point of the line. Assumes that pointIndex is a valid point in the current line being edited.
Parameters:
pointIndex - the index of the point to move.
x - the x coordinate
y - the y coordinate

paint

public void paint(java.awt.Graphics g)
Paints the handle.
Overrides:
paint in class SquareCanvasHandle
Parameters:
g - the specified Graphics window

releaseControl

public void releaseControl(DrawingCanvas canvas)
Release control of the canvas and clean up if necessary. Since this is a public method, don't assume the receiver actually has control. Since we're obviously done constructing the line, see if it's valid If not, delete it. Prepare to create a new one next time we get control.
Overrides:
releaseControl in class CanvasHandle
Parameters:
canvas - the canvas which the receiver is to release control of.

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 associate with.