com.rolemodelsoft.drawlet.shapes
Class BoundsHandle

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
        |
        +--com.rolemodelsoft.drawlet.basics.CanvasHandle
              |
              +--com.rolemodelsoft.drawlet.basics.SquareCanvasHandle
                    |
                    +--com.rolemodelsoft.drawlet.shapes.BoundsHandle
Direct Known Subclasses:
BottomHandle, BottomLeftHandle, BottomRightHandle, LeftHandle, RightHandle, TopHandle, TopLeftHandle, TopRightHandle

public abstract class BoundsHandle
extends SquareCanvasHandle
implements FigureHolder

Although there are plenty of ways to add Handles to figures, a common thing to do is put them on the corners or sides of some rectangular area (e.g. the bounds). This abstract class serves as a base for handles that do just that. Subclasses need to implement, at a minimum: Their own constructors, modeled after this one's defaultLocator(Figure); and should probably define a mouseDrag(Event,int,int) method to invoke the provided resize(int,int) or reshape(int,int,int,int) method if the handle is there to allow reshaping of the underlying figure.


Field Summary
protected  Figure figure
          The figure whose bounds the handle may modify.
protected  Locator locator
          The locator defining where to place the handle.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
canvas, halfWidth, HANDLE_SIZE, previousTool
 
Constructor Summary
BoundsHandle(Figure figure)
          Constructs and initializes a new instance of a handle which can affect the figure's bounds in some way.
 
Method Summary
 int centerX()
          Answer the x coordinate at the center of the handle.
 int centerY()
          Answer the y coordinate at the center of the handle.
protected abstract  Locator defaultLocator(Figure figure)
          Answer the default/initial locator.
 Figure getFigure()
          Returns the figure associated with this handle.
 void mouseDragged(java.awt.event.MouseEvent evt)
          Called if the mouse is dragged (the mouse button is down).
 void reshape(int x, int y, int width, int height)
          Reshape the figure and cleanly repaint the canvas.
 void resize(int width, int height)
          Resize the figure and cleanly repaint the canvas.
 void setFigure(Figure figure)
          Set the figure associated with this handle.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.SquareCanvasHandle
getBounds, paint
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
contains, defaultHandleSize, finished, getHandleHeight, getHandleSize, getHandleWidth, getX, getY, intersects, mouseReleased, releaseControl, setHandleSize, takeControl
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDoubleClicked, 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

figure

protected Figure figure
The figure whose bounds the handle may modify.

locator

protected Locator locator
The locator defining where to place the handle.
Constructor Detail

BoundsHandle

public BoundsHandle(Figure figure)
Constructs and initializes a new instance of a handle which can affect the figure's bounds in some way. Subclasses should use a similar constructor, invoking super.
Parameters:
figure - the figure whose bounds we may wish to change.
Method Detail

centerX

public 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

public 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 abstract Locator defaultLocator(Figure figure)
Answer the default/initial locator.
Parameters:
figure - the figure
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 associated with this handle

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Called if the mouse is dragged (the mouse button is down). Resize/reshape the figure as appropriate. Consume the event. Subclasses should provide their own behavior to resize/reshape the figure.
Overrides:
mouseDragged in class AbstractInputEventHandler
Parameters:
evt - the event
See Also:
resize(int, int), reshape(int, int, int, int)

reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
Reshape the figure and cleanly repaint the canvas.
Parameters:
x - the new x.
y - the new y.
width - the new width.
height - the new height.

resize

public void resize(int width,
                   int height)
Resize the figure and cleanly repaint the canvas. Note that we're assuming that at least some of the other handles must be repainted.
Parameters:
width - the new width.
height - the new height.

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.