JHotDraw 7.0.6

org.jhotdraw.draw
Class TextAreaFigure

java.lang.Object
  extended by org.jhotdraw.draw.AbstractFigure
      extended by org.jhotdraw.draw.AttributedFigure
          extended by org.jhotdraw.draw.TextAreaFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Figure, TextHolder, DOMStorable

public class TextAreaFigure
extends AttributedFigure
implements TextHolder

A TextAreaFigure contains formatted text.
It automatically rearranges the text to fit its allocated display area, breaking the lines at word boundaries whenever possible.
The text can contain either LF or CRLF sequences to separate paragraphs, as well as tab characters for table like formatting and alignment.
Currently the tabs are distributed at regular intervals as determined by the TabSize property. Tabs align correctly with either fixed or variable fonts.
If, when resizing, the vertical size of the display box is not enough to display all the text, TextAreaFigure displays a dashed red line at the bottom of the figure to indicate there is hidden text.
TextAreFigure uses all standard attributes for the area Rectangle2D.Double, ie: FillColor, PenColor for the border, FontSize, FontStyle, and FontName, as well as four additional attributes LeftMargin, RightMargin, TopMargin, and TabSize.

XXX - TextAreaFigure should not draw a rectangle on its own but rather rely on a decorator. We probably need a DecoratorConnector for this and we need a way to specify the inner bounds of the decorator. We also need a way to center the text of the TextAreaFigure verticaly and horizontaly.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, decorator, listenerList
 
Constructor Summary
TextAreaFigure()
          Creates a new instance.
TextAreaFigure(java.lang.String text)
           
 
Method Summary
 void basicSetBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
          Sets the logical bounds of the figure and of its decorator figure.
 void basicTransform(java.awt.geom.AffineTransform tx)
          Moves the figure.
 TextAreaFigure clone()
          Returns a clone of the figure.
 boolean contains(java.awt.geom.Point2D.Double p)
          Checks if a point is contained by the figure.
 java.util.Collection<Handle> createHandles(int detailLevel)
          Creates handles used to manipulate the figure.
protected  void drawFill(java.awt.Graphics2D g)
          This method is called by method draw() to draw the fill area of the figure.
protected  void drawStroke(java.awt.Graphics2D g)
          This method is called by method draw() to draw the text of the figure .
protected  void drawText(java.awt.Graphics2D g)
           
 java.awt.geom.Rectangle2D.Double getBounds()
          Returns the logical bounds of the figure as a Rectangle.
 java.awt.Color getFillColor()
           
 java.awt.Font getFont()
           
 float getFontSize()
           
 Insets2DDouble getInsets()
          Returns the insets used to draw text.
 TextHolder getLabelFor()
           
 java.lang.Object getRestoreData()
          Gets data which can be used to restore the shape of the figure after a basicTransform has been applied to it.
 int getTabSize()
          Gets the number of characters used to expand tabs.
 java.lang.String getText()
          Gets the text shown by the text figure.
 java.awt.Color getTextColor()
           
 int getTextColumns()
          Gets the number of columns to be overlaid when the figure is edited.
 Tool getTool(java.awt.geom.Point2D.Double p)
          Returns a specialized tool for the given coordinate.
 boolean isEditable()
           
 void read(DOMInput in)
           
protected  void readBounds(DOMInput in)
           
 void restoreTo(java.lang.Object geometry)
          Restores the shape of the figure to a previously stored state.
 void setEditable(boolean b)
           
 void setFontSize(float size)
           
 void setText(java.lang.String newText)
          Sets the text shown by the text figure.
protected  void validate()
           
 void write(DOMOutput out)
           
protected  void writeBounds(DOMOutput out)
           
 
Methods inherited from class org.jhotdraw.draw.AttributedFigure
applyAttributesTo, basicSetAttribute, drawConnectors, drawFigure, getAttribute, getAttributeKey, getAttributes, getFigureDrawBounds, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, setAttribute, setAttributeEnabled, setAttributes, writeAttributes
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, addNotify, addUndoableEditListener, basicClone, canConnect, changed, draw, drawDecorator, findCompatibleConnector, findConnector, findFigureInside, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getCourtingConnection, getCursor, getDecomposition, getDecorator, getDrawBounds, getDrawing, getEndPoint, getFontRenderContext, getLayer, getLock, getPreferredSize, getStartPoint, getTooltip, handleDrop, handleMouseClick, includes, invalidate, isChanging, isConnectorsVisible, isDrawDecoratorFirst, isInteractive, isVisible, remap, remap, removeFigureListener, removeNotify, removeUndoableEditListener, requestRemove, setBounds, setBounds, setConnectorsVisible, setDecorator, setDrawDecoratorFirst, setInteractive, setVisible, toString, transform, updateDecoratorBounds, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addNotify, addUndoableEditListener, basicSetAttribute, canConnect, changed, draw, findCompatibleConnector, findConnector, findFigureInside, getActions, getAttribute, getAttributes, getCursor, getDecomposition, getDecorator, getDrawBounds, getEndPoint, getLayer, getPreferredSize, getStartPoint, getTooltip, handleDrop, handleMouseClick, includes, invalidate, isConnectorsVisible, isInteractive, isVisible, remap, removeFigureListener, removeNotify, removeUndoableEditListener, requestRemove, setAttribute, setConnectorsVisible, setDecorator, setVisible, willChange
 

Constructor Detail

TextAreaFigure

public TextAreaFigure()
Creates a new instance.


TextAreaFigure

public TextAreaFigure(java.lang.String text)
Method Detail

getText

public java.lang.String getText()
Gets the text shown by the text figure.

Specified by:
getText in interface TextHolder

setText

public void setText(java.lang.String newText)
Sets the text shown by the text figure.

Specified by:
setText in interface TextHolder

basicSetBounds

public void basicSetBounds(java.awt.geom.Point2D.Double anchor,
                           java.awt.geom.Point2D.Double lead)
Description copied from interface: Figure
Sets the logical bounds of the figure and of its decorator figure.

This is used by Tool's which create a new Figure and by Tool's which connect a Figure to another Figure.

This is a basic operation which does not fire events.

Specified by:
basicSetBounds in interface Figure
Parameters:
anchor - the start point of the bounds
lead - the end point of the bounds
See Also:
Figure.getBounds()

basicTransform

public void basicTransform(java.awt.geom.AffineTransform tx)
Description copied from class: AbstractFigure
Moves the figure. This is the method that subclasses override.

This is a basic operation for which no events are fired.

Specified by:
basicTransform in interface Figure
Specified by:
basicTransform in class AbstractFigure
Parameters:
tx - The transformation.

contains

public boolean contains(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Checks if a point is contained by the figure.

This is used for hit testing by Tool's.

Specified by:
contains in interface Figure

getInsets

public Insets2DDouble getInsets()
Returns the insets used to draw text.

Specified by:
getInsets in interface TextHolder

getTabSize

public int getTabSize()
Description copied from interface: TextHolder
Gets the number of characters used to expand tabs.

Specified by:
getTabSize in interface TextHolder

drawText

protected void drawText(java.awt.Graphics2D g)
Overrides:
drawText in class AttributedFigure

drawFill

protected void drawFill(java.awt.Graphics2D g)
Description copied from class: AttributedFigure
This method is called by method draw() to draw the fill area of the figure. AttributedFigure configures the Graphics2D object with the FILL_COLOR attribute before calling this method. If the FILL_COLOR attribute is null, this method is not called.

Specified by:
drawFill in class AttributedFigure

drawStroke

protected void drawStroke(java.awt.Graphics2D g)
Description copied from class: AttributedFigure
This method is called by method draw() to draw the text of the figure . AttributedFigure configures the Graphics2D object with the TEXT_COLOR attribute before calling this method. If the TEXT_COLOR attribute is null, this method is not called.

Specified by:
drawStroke in class AttributedFigure

getBounds

public java.awt.geom.Rectangle2D.Double getBounds()
Description copied from interface: Figure
Returns the logical bounds of the figure as a Rectangle. The logical bounds are used by some Handle objects for adjusting the figure.

Specified by:
getBounds in interface Figure

createHandles

public java.util.Collection<Handle> createHandles(int detailLevel)
Description copied from interface: Figure
Creates handles used to manipulate the figure.

Specified by:
createHandles in interface Figure
Overrides:
createHandles in class AbstractFigure
Parameters:
detailLevel - The detail level of the handles. Usually this is 0 for bounding box handles and 1 for point handles.
Returns:
a Collection of handles
See Also:
Handle

validate

protected void validate()
Overrides:
validate in class AbstractFigure

isEditable

public boolean isEditable()
Specified by:
isEditable in interface TextHolder

setEditable

public void setEditable(boolean b)

getTextColumns

public int getTextColumns()
Description copied from interface: TextHolder
Gets the number of columns to be overlaid when the figure is edited.

Specified by:
getTextColumns in interface TextHolder

getTool

public Tool getTool(java.awt.geom.Point2D.Double p)
Returns a specialized tool for the given coordinate.

Returns null, if no specialized tool is available.

Specified by:
getTool in interface Figure
Overrides:
getTool in class AbstractFigure

readBounds

protected void readBounds(DOMInput in)
                   throws java.io.IOException
Throws:
java.io.IOException

writeBounds

protected void writeBounds(DOMOutput out)
                    throws java.io.IOException
Throws:
java.io.IOException

read

public void read(DOMInput in)
          throws java.io.IOException
Specified by:
read in interface DOMStorable
Overrides:
read in class AttributedFigure
Throws:
java.io.IOException

write

public void write(DOMOutput out)
           throws java.io.IOException
Specified by:
write in interface DOMStorable
Overrides:
write in class AttributedFigure
Throws:
java.io.IOException

clone

public TextAreaFigure clone()
Description copied from interface: Figure
Returns a clone of the figure.

Specified by:
clone in interface Figure
Overrides:
clone in class AttributedFigure

getLabelFor

public TextHolder getLabelFor()
Specified by:
getLabelFor in interface TextHolder

restoreTo

public void restoreTo(java.lang.Object geometry)
Description copied from interface: Figure
Restores the shape of the figure to a previously stored state.

Specified by:
restoreTo in interface Figure

getRestoreData

public java.lang.Object getRestoreData()
Description copied from interface: Figure
Gets data which can be used to restore the shape of the figure after a basicTransform has been applied to it.

Specified by:
getRestoreData in interface Figure
See Also:
Figure.basicTransform(AffineTransform)

getFont

public java.awt.Font getFont()
Specified by:
getFont in interface TextHolder

getTextColor

public java.awt.Color getTextColor()
Specified by:
getTextColor in interface TextHolder

getFillColor

public java.awt.Color getFillColor()
Specified by:
getFillColor in interface TextHolder

setFontSize

public void setFontSize(float size)
Specified by:
setFontSize in interface TextHolder

getFontSize

public float getFontSize()
Specified by:
getFontSize in interface TextHolder

Copyright 1996-2006 © JHotDraw.org