JHotDraw 7.1

org.jhotdraw.draw
Class TextAreaTool

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractTool
          extended by org.jhotdraw.draw.CreationTool
              extended by org.jhotdraw.draw.TextAreaTool
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, Tool

public class TextAreaTool
extends CreationTool
implements java.awt.event.ActionListener

A tool to create new or edit existing figures that implement the TextHolderFigure interface, such as TextAreaFigure. The figure to be created is specified by a prototype.

To create a figure using the TextAreaTool, the user does the following mouse gestures on a DrawingView:

  1. Press the mouse button over the DrawingView. This defines the start point of the Figure bounds.
  2. Drag the mouse while keeping the mouse button pressed, and then release the mouse button. This defines the end point of the Figure bounds.
When the user has performed these mouse gesture, the TextAreaTool overlays a text area over the drawing where the user can enter the text for the Figure.

To edit an existing text figure using the TextAreaTool, the user does the following mouse gesture on a DrawingView:

  1. Press the mouse button over a Figure on the DrawingView.

The TextAreaTool then uses Figure.findFigureInside to find a Figure that implements the TextHolderFigure interface and that is editable. Then it overlays a text area over the drawing where the user can enter the text for the Figure.

XXX - Maybe this class should be split up into a CreateTextAreaTool and a EditTextAreaTool.

Version:
2.2 2007-11-25 Added variable isForCreationOnly.
2.1 2007-08-22 Added support for property 'toolDoneAfterCreation'.
2.0 2006-01-14 Changed to support double precison coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
TextHolderFigure, FloatingTextArea, Serialized Form

Field Summary
 
Fields inherited from class org.jhotdraw.draw.CreationTool
createdFigure
 
Fields inherited from class org.jhotdraw.draw.AbstractTool
anchor, editor, isWorking, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Constructor Summary
TextAreaTool(TextHolderFigure prototype)
          Creates a new instance.
TextAreaTool(TextHolderFigure prototype, java.util.Map attributes)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
           
protected  void beginEdit(TextHolderFigure textHolder)
           
protected  void creationFinished(Figure createdFigure)
          This method allows subclasses to do perform additonal user interactions after the new figure has been created.
 void deactivate(DrawingEditor editor)
          Deactivates the tool.
 void draw(java.awt.Graphics2D g)
          Draws the tool.
protected  void endEdit()
           
 boolean isForCreationOnly()
          Returns true, if this tool can be only be used for creation of TextHolderFigures and not for editing existing ones.
 void mousePressed(java.awt.event.MouseEvent e)
          Creates a new figure at the mouse location.
 void setForCreationOnly(boolean newValue)
          By default this tool is used to create a new TextHolderFigure.
 void setRubberbandColor(java.awt.Color c)
          Sets the rubberband color for the tool.
 
Methods inherited from class org.jhotdraw.draw.CreationTool
activate, createFigure, getAddedFigure, getCreatedFigure, getPrototype, isToolDoneAfterCreation, mouseDragged, mouseReleased, setToolDoneAfterCreation
 
Methods inherited from class org.jhotdraw.draw.AbstractTool
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, createActionMap, createInputMap, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireToolDone, fireToolStarted, getActionMap, getDrawing, getEditor, getInputMap, getView, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, mouseMoved, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, updateCursor, viewToDrawing
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextAreaTool

public TextAreaTool(TextHolderFigure prototype)
Creates a new instance.


TextAreaTool

public TextAreaTool(TextHolderFigure prototype,
                    java.util.Map attributes)
Method Detail

setRubberbandColor

public void setRubberbandColor(java.awt.Color c)
Sets the rubberband color for the tool. Setting this to null, disables the rubberband.

Parameters:
c - Rubberband color or null.

setForCreationOnly

public void setForCreationOnly(boolean newValue)
By default this tool is used to create a new TextHolderFigure. If this property is set to false, the tool is used to create a new TextHolderFigure or to edit an existing TextHolderFigure.


isForCreationOnly

public boolean isForCreationOnly()
Returns true, if this tool can be only be used for creation of TextHolderFigures and not for editing existing ones.


deactivate

public void deactivate(DrawingEditor editor)
Description copied from interface: Tool
Deactivates the tool. This method is called whenever the user switches to another tool.

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Creates a new figure at the mouse location. If editing is in progress, this finishes editing.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class CreationTool

creationFinished

protected void creationFinished(Figure createdFigure)
This method allows subclasses to do perform additonal user interactions after the new figure has been created. The implementation of this class just invokes fireToolDone.

Overrides:
creationFinished in class CreationTool

draw

public void draw(java.awt.Graphics2D g)
Description copied from interface: Tool
Draws the tool.

Specified by:
draw in interface Tool
Overrides:
draw in class AbstractTool

beginEdit

protected void beginEdit(TextHolderFigure textHolder)

endEdit

protected void endEdit()

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.