com.rolemodelsoft.drawlet.text
Class LabelEditHandle

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

public class LabelEditHandle
extends CanvasHandle

A handle one can use to edit labels. Currently this is rather primitive as it does not allow for insert and replacing of a subset of text... this should be a temporary limitation. This would typically be invoked as an editTool (see Figure), but could be used in other contexts.


Field Summary
protected  Figure figure
          The figure whose label we are editing.
protected  java.lang.String string
          The local copy of the string being edited.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
canvas, halfWidth, HANDLE_SIZE, previousTool
 
Constructor Summary
LabelEditHandle(Figure figure)
          Answer a new instance prepared to edit the figure.
 
Method Summary
 java.awt.Rectangle getBounds()
          Returns the current bounds of this handle.
 java.awt.Rectangle getLabelBounds()
          Returns the current bounds of the label.
protected  DrawingStyle getStyle()
          Answer the DrawingStyle to use when displaying.
 void keyTyped(java.awt.event.KeyEvent evt)
          Called if a character is typed.
 void mousePressed(java.awt.event.MouseEvent evt)
          Called if the mouse is pressed.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Called if the mouse goes up.
 void paint(java.awt.Graphics g)
          Paints the receiver.
 void releaseControl(DrawingCanvas canvas)
          Release control of the canvas and clean up if necessary.
 void takeControl(DrawingCanvas canvas)
          Make the handle be the event handler for the canvas.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.CanvasHandle
contains, defaultHandleSize, finished, getHandleHeight, getHandleSize, getHandleWidth, getX, getY, intersects, setHandleSize
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, mouseClicked, mouseDoubleClicked, mouseDragged, 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 whose label we are editing. Note the figure must also implement LabelHolder.

string

protected java.lang.String string
The local copy of the string being edited.
Constructor Detail

LabelEditHandle

public LabelEditHandle(Figure figure)
Answer a new instance prepared to edit the figure.
Parameters:
figure - the figure whose label is to be edited.
Throws:
java.lang.IllegalArgumentException - If the figure does not implement LabelHolder interface.
Method Detail

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.

getLabelBounds

public java.awt.Rectangle getLabelBounds()
Returns the current bounds of the label.
Returns:
a Rectangle representing the current bounds of the label.

getStyle

protected DrawingStyle getStyle()
Answer the DrawingStyle to use when displaying.
Returns:
the DrawingStyle to use when displaying.

keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
Called if a character is typed. Edit the text. For now this just means adding to what has been typed so far, or backspacing over it. Should allow text insertion/replacement in future.
Overrides:
keyTyped in class AbstractInputEventHandler
Parameters:
evt - the event

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Called if the mouse is pressed. If outside our bounds, give up control and pass event on to underlying tool. Inside, do nothing. In the future this should probably denote a type of "cursor" placement for specific editing.
Overrides:
mousePressed in class AbstractInputEventHandler
Parameters:
evt - the event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Called if the mouse goes up. Currently, do nothing. In the future this should probably denote a block of text as selected for edit.
Overrides:
mouseReleased in class CanvasHandle
Parameters:
evt - the event.

paint

public void paint(java.awt.Graphics g)
Paints the receiver.
Overrides:
paint in class CanvasHandle
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.
Overrides:
releaseControl in class CanvasHandle
Parameters:
canvas - the canvas which the receiver is to release control

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.
Overrides:
takeControl in class CanvasHandle
Parameters:
x - the x coordinate
y - the y coordinate