com.rolemodelsoft.drawlet.basics
Class CanvasHandle

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
        |
        +--com.rolemodelsoft.drawlet.basics.CanvasHandle
Direct Known Subclasses:
BoxSelectionHandle, LabelEditHandle, LocatorConnectionHandle, SquareCanvasHandle

public abstract class CanvasHandle
extends AbstractInputEventHandler
implements Handle

This abstract class offers a simple base for handles to be used on a canvas. Subclasses need to provide, at a minimum, implementations for:

Typically, these types of handles wait for some outside object to ask them to takeControl() (e.g. mouse down on top of it), then they do something in response to mouse events, and finally they releaseControl() (e.g. mouse up).


Field Summary
protected  DrawingCanvas canvas
          The canvas upon which to "operate"
protected static int halfWidth
          Half the general width of handles.
protected static int HANDLE_SIZE
          The general size of handles (assuming same size in x and y direction).
protected  InputEventHandler previousTool
          The tool that was in control before this one took over.
 
Constructor Summary
CanvasHandle()
           
 
Method Summary
 boolean contains(int x, int y)
          Checks whether a specified x,y location is "inside" this handle.
static int defaultHandleSize()
          Answers the default value of HANDLE_SIZE;
protected  void finished()
          The handle has completed its task...
abstract  java.awt.Rectangle getBounds()
          Returns the current bounds of this handle.
protected  int getHandleHeight()
          Answers the height of the handle;
static int getHandleSize()
          Answer the value of HANDLE_SIZE.
protected  int getHandleWidth()
          Answers the width of the handle;
protected  int getX(java.awt.event.MouseEvent evt)
          Returns the proper x value for the given event.
protected  int getY(java.awt.event.MouseEvent evt)
          Returns the proper y value for the given event.
 boolean intersects(java.awt.Rectangle box)
          Answers whether the receiver intersects a Rectangular area.
 void mouseReleased(java.awt.event.MouseEvent e)
          By default, we are finished with our task when the mouse goes up, so we clean up.
 void paint(java.awt.Graphics g)
          Paints the handle.
 void releaseControl(DrawingCanvas canvas)
          Release control of the canvas and clean up if necessary.
static void setHandleSize(int size)
          Set the value of HANDLE_SIZE.
 void takeControl(DrawingCanvas canvas)
          Make the handle be the event handler for the canvas.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDoubleClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseSingleClicked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HANDLE_SIZE

protected static int HANDLE_SIZE
The general size of handles (assuming same size in x and y direction).

halfWidth

protected static int halfWidth
Half the general width of handles.

canvas

protected DrawingCanvas canvas
The canvas upon which to "operate"

previousTool

protected InputEventHandler previousTool
The tool that was in control before this one took over.
Constructor Detail

CanvasHandle

public CanvasHandle()
Method Detail

contains

public boolean contains(int x,
                        int y)
Checks whether a specified x,y location is "inside" this handle. x and y are defined to be relative to the coordinate system of this handle.
Specified by:
contains in interface Handle
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
boolean value of true if the specified x,y location is "inside" this handle; false otherwise.

defaultHandleSize

public static int defaultHandleSize()
Answers the default value of HANDLE_SIZE;
Returns:
an integer representing the default value of HANDLE_SIZE

finished

protected void finished()
The handle has completed its task... clean up as appropriate. Don't assume the canvas will cleanly ask us to releaseControl when we reset our tool. This is the way we release control from within.

getBounds

public abstract java.awt.Rectangle getBounds()
Returns the current bounds of this handle.
Specified by:
getBounds in interface Handle
Returns:
a Rectangle representing the current bounds of this handle

getHandleHeight

protected int getHandleHeight()
Answers the height of the handle;
Returns:
an integer representing the height of the handle

getHandleSize

public static int getHandleSize()
Answer the value of HANDLE_SIZE. This is the default size of handles in the system (assume same x and y size).
Returns:
an integer representing the value of HANDLE_SIZE

getHandleWidth

protected int getHandleWidth()
Answers the width of the handle;
Returns:
an integer representing the width of the handle

getX

protected int getX(java.awt.event.MouseEvent evt)
Returns the proper x value for the given event.
Parameters:
evt - the MouseEvent to get the corrected x for.
Returns:
an integer representing the proper x coordinate.

getY

protected int getY(java.awt.event.MouseEvent evt)
Returns the proper y value for the given event.
Parameters:
evt - the MouseEvent to get the corrected y for.
Returns:
an integer representing the proper y coordinate.

intersects

public boolean intersects(java.awt.Rectangle box)
Answers whether the receiver intersects a Rectangular area.
Specified by:
intersects in interface Handle
Parameters:
box - the Rectangular area
Returns:
boolean value of true if the receiver intersects the specified Rectangular area; false otherwise.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
By default, we are finished with our task when the mouse goes up, so we clean up. Subclasses may wish to override.
Overrides:
mouseReleased in class AbstractInputEventHandler
Parameters:
e - the event

paint

public void paint(java.awt.Graphics g)
Paints the handle.
Specified by:
paint in interface Handle
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.
Specified by:
releaseControl in interface Handle
Parameters:
canvas - the canvas which the receiver is to release control

setHandleSize

public static void setHandleSize(int size)
Set the value of HANDLE_SIZE. This is the default size of handles in the system (assume same x and y size).
Parameters:
size - the new size of handles.

takeControl

public void takeControl(DrawingCanvas canvas)
Make the handle be the event handler for the canvas. Note, once it takes control, it is obligated to return at a future point in time.
Specified by:
takeControl in interface Handle
Parameters:
canvas - the canvas to be the event handler for
See Also:
#locate