JHotDraw 6.0b1

org.jhotdraw.contrib
Class TextAreaTool

java.lang.Object
  extended by org.jhotdraw.standard.AbstractTool
      extended by org.jhotdraw.standard.CreationTool
          extended by org.jhotdraw.contrib.TextAreaTool
All Implemented Interfaces:
Tool
Direct Known Subclasses:
HTMLTextAreaTool

public class TextAreaTool
extends CreationTool

A TextAreaTool creates TextAreaFigures.
To create a new text area, the user drags a rectangle on the drawing on a free spot.
When releasing the mouse the tool calls the area's editor to enter the text.
If the tool is clicked on an existing area the tool simply calls the area's editor.
When creating a new area, if the user leaves the text empty, the newly created area figure is discarded.


Nested Class Summary
static class TextAreaTool.UndoActivity
          Handles undo/redo for text areas
 
Nested classes/interfaces inherited from class org.jhotdraw.standard.AbstractTool
AbstractTool.EventDispatcher
 
Field Summary
protected  Figure fEditedFigure
          The edited figure
protected  FloatingTextArea fTextField
          The field used for editing
protected  TextHolder fTypingTarget
          The typing target
 
Constructor Summary
TextAreaTool(DrawingEditor newDrawingEditor, Figure prototype)
          Constructor for the TextAreaTool object
 
Method Summary
 void activate()
          Activates the figure's editor
protected  void beginEdit(TextHolder figure, Figure selectedFigure)
          Begins editing the figure's text
protected  Undoable createUndoActivity()
          Factory method for undo activity
 void deactivate()
          Terminates the editing of a text figure.
protected  void endEdit()
          Ends editing of the figure's text
protected  Figure getEditedFigure()
          Gets the editedFigure attribute of the TextAreaTool
protected  java.awt.Font getFont(TextHolder figure)
          Gets the font to be used for editing the figure
protected  TextHolder getTypingTarget()
          Gets the typingTarget attribute of the TextAreaTool
 boolean isActivated()
          Test whether the text tool is currently activated and is displaying a overlay TextFigure for accepting input.
 void mouseDown(java.awt.event.MouseEvent e, int x, int y)
          If the pressed figure is a TextHolder and it accepts editing it can be edited.
If there is no pressed figure a new text figure is created.
 void mouseDrag(java.awt.event.MouseEvent e, int x, int y)
          Drags to set the initial text area display box
 void mouseUp(java.awt.event.MouseEvent e, int x, int y)
          If creating a figure it ends the creation process and calls the editor
protected  void setEditedFigure(Figure figure)
          Sets the editedFigure attribute of the TextAreaTool
protected  void setTypingTarget(TextHolder newTypingTarget)
          Sets the typingTarget attribute of the TextAreaTool
 
Methods inherited from class org.jhotdraw.standard.CreationTool
createFigure, getAddedFigure, getAddedFigures, getCreatedFigure, getPrototypeFigure, setAddedFigure, setAddedFigures, setCreatedFigure, setPrototypeFigure
 
Methods inherited from class org.jhotdraw.standard.AbstractTool
addToolListener, checkUsable, createEventDispatcher, createViewChangeListener, drawing, editor, getActiveDrawing, getActiveView, getAnchorX, getAnchorY, getEventDispatcher, getUndoActivity, isActive, isEnabled, isUsable, keyDown, mouseMove, removeToolListener, setAnchorX, setAnchorY, setEditor, setEnabled, setUndoActivity, setUsable, setView, view, viewCreated, viewDestroying, viewSelectionChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fTextField

protected FloatingTextArea fTextField
The field used for editing


fTypingTarget

protected TextHolder fTypingTarget
The typing target


fEditedFigure

protected Figure fEditedFigure
The edited figure

Constructor Detail

TextAreaTool

public TextAreaTool(DrawingEditor newDrawingEditor,
                    Figure prototype)
Constructor for the TextAreaTool object

Parameters:
newDrawingEditor - the managing drawing editor
prototype - the prototype for the figure
Method Detail

mouseDown

public void mouseDown(java.awt.event.MouseEvent e,
                      int x,
                      int y)
If the pressed figure is a TextHolder and it accepts editing it can be edited.
If there is no pressed figure a new text figure is created.

Specified by:
mouseDown in interface Tool
Overrides:
mouseDown in class CreationTool
Parameters:
e - Description of the Parameter
x - Description of the Parameter
y - Description of the Parameter

mouseDrag

public void mouseDrag(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Drags to set the initial text area display box

Specified by:
mouseDrag in interface Tool
Overrides:
mouseDrag in class CreationTool
Parameters:
e - Description of the Parameter
x - Description of the Parameter
y - Description of the Parameter

mouseUp

public void mouseUp(java.awt.event.MouseEvent e,
                    int x,
                    int y)
If creating a figure it ends the creation process and calls the editor

Specified by:
mouseUp in interface Tool
Overrides:
mouseUp in class CreationTool
Parameters:
e - Description of the Parameter
x - Description of the Parameter
y - Description of the Parameter
See Also:
Figure.isEmpty()

deactivate

public void deactivate()
Terminates the editing of a text figure.

Specified by:
deactivate in interface Tool
Overrides:
deactivate in class CreationTool
See Also:
Tool.deactivate()

activate

public void activate()
Activates the figure's editor

Specified by:
activate in interface Tool
Overrides:
activate in class CreationTool

isActivated

public boolean isActivated()
Test whether the text tool is currently activated and is displaying a overlay TextFigure for accepting input.

Returns:
true, if the text tool has a accepting target TextFigure for its input, false otherwise

beginEdit

protected void beginEdit(TextHolder figure,
                         Figure selectedFigure)
Begins editing the figure's text

Parameters:
figure - the typing target
selectedFigure - the edited figure

getFont

protected java.awt.Font getFont(TextHolder figure)
Gets the font to be used for editing the figure

Parameters:
figure - the figure
Returns:
The font

endEdit

protected void endEdit()
Ends editing of the figure's text


setTypingTarget

protected void setTypingTarget(TextHolder newTypingTarget)
Sets the typingTarget attribute of the TextAreaTool

Parameters:
newTypingTarget - The new typingTarget value

getEditedFigure

protected Figure getEditedFigure()
Gets the editedFigure attribute of the TextAreaTool

Returns:
The editedFigure value

setEditedFigure

protected void setEditedFigure(Figure figure)
Sets the editedFigure attribute of the TextAreaTool

Parameters:
figure - The new editedFigure value

getTypingTarget

protected TextHolder getTypingTarget()
Gets the typingTarget attribute of the TextAreaTool

Returns:
The typingTarget value

createUndoActivity

protected Undoable createUndoActivity()
Factory method for undo activity

Overrides:
createUndoActivity in class CreationTool
Returns:
Description of the Return Value

JHotDraw 6.0b1