org.jhotdraw.contrib
Class TextAreaFigure

java.lang.Object
  extended by org.jhotdraw.standard.AbstractFigure
      extended by org.jhotdraw.figures.AttributeFigure
          extended by org.jhotdraw.contrib.TextAreaFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, Figure, FigureChangeListener, TextHolder, Storable
Direct Known Subclasses:
HTMLTextAreaFigure

public class TextAreaFigure
extends AttributeFigure
implements FigureChangeListener, 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 rectangle, ie: FillColor, PenColor for the border, FontSize, FontStyle, and FontName, as well as four additional attributes LeftMargin, RightMargin, TopMargin, and TabSize.

Version:
<$CURRENT_VERSION$>
Author:
Eduardo Francos - InContext
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jhotdraw.framework.Figure
POPUP_MENU
 
Constructor Summary
TextAreaFigure()
          Constructor for the TextAreaFigure object
 
Method Summary
 boolean acceptsTyping()
          Tests whether the figure accepts typing.
 void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
          Sets the display box for the figure
 void connect(Figure figure)
          Connects the figure to another figure
 java.awt.Font createFont()
          Creates the font from current attributes.
 void disconnect(Figure disconnectFigure)
          Disconnects a text holder from a connect figure.
 java.awt.Rectangle displayBox()
          Returns the current display box for the figure
 void draw(java.awt.Graphics g)
          Draws the figure.
 void drawBackground(java.awt.Graphics g)
          Draws the background for the figure.
 void drawFrame(java.awt.Graphics g)
          Draws the frame around the text
 void figureChanged(FigureChangeEvent e)
          A connected figure has changed, update the figure's location
 void figureInvalidated(FigureChangeEvent e)
          Description of the Method
 void figureRemoved(FigureChangeEvent e)
          The figure is about to be removed from another composite figure
 void figureRequestRemove(FigureChangeEvent e)
          A request to remove the figure from another composite figure
 void figureRequestUpdate(FigureChangeEvent e)
          Sent when an update should happen.
 java.lang.Object getAttribute(java.lang.String name)
          Deprecated. use getAttribute(FigureAttributeConstant)
 java.awt.Font getFont()
          Gets the font.
 Figure getRepresentingFigure()
          Usually, a TextHolders is implemented by a Figure subclass.
 java.lang.String getText()
          Gets the text of the figure
 java.awt.Color getTextColor()
          Gets the text color of a figure.
 HandleEnumeration handles()
          Returns an iterator of standard sizing handles to manipulate the figure
 boolean isEmpty()
          Gets the empty attribute of the figure.
 boolean isFontDirty()
          Gets the fontDirty attribute of the TextAreaFigure object
 boolean isReadOnly()
           
 boolean isSizeDirty()
          Returns the current size dirty status
 boolean isTextDirty()
          Gets the textDirty attribute of the TextAreaFigure object
 void moveBy(int x, int y)
          Moves the figure the supplied offset
 int overlayColumns()
          Gets the number of columns to be overlaid when the figure is edited.
 void read(StorableInput dr)
          Reads the figure from StorableInput
 void setAttribute(java.lang.String name, java.lang.Object value)
          Deprecated. use setAttribute(FigureAttributeConstant, Object)
 void setFont(java.awt.Font newFont)
          Sets the font.
 void setFontDirty(boolean newFontIsDirty)
          Sets the fontDirty attribute of the TextAreaFigure object
 void setReadOnly(boolean newReadOnly)
           
 void setSizeDirty(boolean newSizeIsDirty)
          Called to set the dirty status of the size
 void setText(java.lang.String newText)
          Sets the text of the figure
 java.awt.Rectangle textDisplayBox()
          Returns the display box for the text
 void write(StorableOutput dw)
          Writes the figure to StorableOutput
 
Methods inherited from class org.jhotdraw.figures.AttributeFigure
getAttribute, getDefaultAttribute, getDefaultAttribute, getFillColor, getFrameColor, initDefaultAttribute, setAttribute, setDefaultAttribute
 
Methods inherited from class org.jhotdraw.standard.AbstractFigure
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, changed, clone, connectedTextLocator, connectionInsets, connectorAt, connectorVisibility, containsPoint, decompose, displayBox, displayBox, figures, findFigureInside, getDecoratedFigure, getDependendFigures, getTextHolder, getZValue, includes, invalidate, listener, release, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextAreaFigure

public TextAreaFigure()
Constructor for the TextAreaFigure object

Method Detail

getText

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

Specified by:
getText in interface TextHolder
Returns:
The text value

setText

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

Specified by:
setText in interface TextHolder
Parameters:
newText - The new text value

textDisplayBox

public java.awt.Rectangle textDisplayBox()
Returns the display box for the text

Specified by:
textDisplayBox in interface TextHolder
Returns:
Description of the Return Value

createFont

public java.awt.Font createFont()
Creates the font from current attributes.

Returns:
Description of the Return Value

isReadOnly

public boolean isReadOnly()

setReadOnly

public void setReadOnly(boolean newReadOnly)

acceptsTyping

public boolean acceptsTyping()
Tests whether the figure accepts typing.

Specified by:
acceptsTyping in interface TextHolder
Returns:
Description of the Return Value

isTextDirty

public boolean isTextDirty()
Gets the textDirty attribute of the TextAreaFigure object

Returns:
The textDirty value

setSizeDirty

public void setSizeDirty(boolean newSizeIsDirty)
Called to set the dirty status of the size

Parameters:
newSizeIsDirty - The new sizeDirty value

isSizeDirty

public boolean isSizeDirty()
Returns the current size dirty status

Returns:
The sizeDirty value

getFont

public java.awt.Font getFont()
Gets the font.

Specified by:
getFont in interface TextHolder
Returns:
The font value

setFont

public void setFont(java.awt.Font newFont)
Sets the font.

Parameters:
newFont - The new font value

overlayColumns

public int overlayColumns()
Gets the number of columns to be overlaid when the figure is edited.
This method is mandatory by the TextHolder interface but is not used by the TextAreaFigure/TextAreaTool couple because the overlay always covers the text area display box

Specified by:
overlayColumns in interface TextHolder
Returns:
the number of overlay columns

basicDisplayBox

public void basicDisplayBox(java.awt.Point origin,
                            java.awt.Point corner)
Sets the display box for the figure

Specified by:
basicDisplayBox in interface Figure
Specified by:
basicDisplayBox in class AbstractFigure
Parameters:
origin - origin point
corner - corner point
See Also:
Figure

handles

public HandleEnumeration handles()
Returns an iterator of standard sizing handles to manipulate the figure

Specified by:
handles in interface Figure
Specified by:
handles in class AbstractFigure
Returns:
Description of the Return Value
See Also:
Handle

displayBox

public java.awt.Rectangle displayBox()
Returns the current display box for the figure

Specified by:
displayBox in interface Figure
Specified by:
displayBox in class AbstractFigure
Returns:
Description of the Return Value
See Also:
Figure.basicDisplayBox(java.awt.Point, java.awt.Point)

moveBy

public void moveBy(int x,
                   int y)
Moves the figure the supplied offset

Specified by:
moveBy in interface Figure
Overrides:
moveBy in class AbstractFigure
Parameters:
x - x displacement
y - y displacement

drawBackground

public void drawBackground(java.awt.Graphics g)
Draws the background for the figure. Called by the superclass with the colors set from the current attribute values

Parameters:
g - The graphics to use for the drawing
See Also:
AttributeFigure.draw(java.awt.Graphics)

draw

public void draw(java.awt.Graphics g)
Draws the figure. Overriden so as to draw the text once everything else has been drawn

Specified by:
draw in interface Figure
Overrides:
draw in class AttributeFigure
Parameters:
g - The graphics to use for the drawing

drawFrame

public void drawFrame(java.awt.Graphics g)
Draws the frame around the text

Parameters:
g - The graphics to use for the drawing
See Also:
AttributeFigure.draw(java.awt.Graphics)

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Deprecated. use getAttribute(FigureAttributeConstant)

A text area figure uses the "LeftMargin", "RightMargin", "TopMargin", "TabSize", "FontSize", "FontStyle", and "FontName" attributes

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AttributeFigure
Parameters:
name - the attribute's name
Returns:
the attribute value

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Deprecated. use setAttribute(FigureAttributeConstant, Object)

A text area figure uses the "LeftMargin", "RightMargin", "TopMargin", "TabSize", "FontSize", "FontStyle", and "FontName" attributes

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AttributeFigure
Parameters:
name - the new attribute name
value - the new attribute value

write

public void write(StorableOutput dw)
Writes the figure to StorableOutput

Specified by:
write in interface Storable
Overrides:
write in class AttributeFigure
Parameters:
dw - the output storable

read

public void read(StorableInput dr)
          throws java.io.IOException
Reads the figure from StorableInput

Specified by:
read in interface Storable
Overrides:
read in class AttributeFigure
Parameters:
dr - Description of the Parameter
Throws:
java.io.IOException - the inout storable

connect

public void connect(Figure figure)
Connects the figure to another figure

Specified by:
connect in interface TextHolder
Parameters:
figure - the connecting figure

disconnect

public void disconnect(Figure disconnectFigure)
Disconnects a text holder from a connect figure.

Specified by:
disconnect in interface TextHolder
Parameters:
disconnectFigure - the disconnecting figure

figureInvalidated

public void figureInvalidated(FigureChangeEvent e)
Description of the Method

Specified by:
figureInvalidated in interface FigureChangeListener
Parameters:
e - Description of the Parameter

figureChanged

public void figureChanged(FigureChangeEvent e)
A connected figure has changed, update the figure's location

Specified by:
figureChanged in interface FigureChangeListener
Parameters:
e - Description of the Parameter

figureRemoved

public void figureRemoved(FigureChangeEvent e)
The figure is about to be removed from another composite figure

Specified by:
figureRemoved in interface FigureChangeListener
Parameters:
e - Description of the Parameter

figureRequestRemove

public void figureRequestRemove(FigureChangeEvent e)
A request to remove the figure from another composite figure

Specified by:
figureRequestRemove in interface FigureChangeListener
Parameters:
e - Description of the Parameter

figureRequestUpdate

public void figureRequestUpdate(FigureChangeEvent e)
Description copied from interface: FigureChangeListener
Sent when an update should happen.

Specified by:
figureRequestUpdate in interface FigureChangeListener
Parameters:
e - Description of the Parameter

getTextColor

public java.awt.Color getTextColor()
Gets the text color of a figure. This is a convenience method.

Returns:
The textColor value
See Also:
getAttribute(java.lang.String)

isEmpty

public boolean isEmpty()
Gets the empty attribute of the figure. True if there is no text

Specified by:
isEmpty in interface Figure
Overrides:
isEmpty in class AbstractFigure
Returns:
The empty value
See Also:
Figure.isEmpty()

isFontDirty

public boolean isFontDirty()
Gets the fontDirty attribute of the TextAreaFigure object

Returns:
The fontDirty value

setFontDirty

public void setFontDirty(boolean newFontIsDirty)
Sets the fontDirty attribute of the TextAreaFigure object

Parameters:
newFontIsDirty - The new fontDirty value

getRepresentingFigure

public Figure getRepresentingFigure()
Usually, a TextHolders is implemented by a Figure subclass. To avoid casting a TextHolder to a Figure this method can be used for polymorphism (in this case, let the (same) object appear to be of another type). Note, that the figure returned is not the figure to which the TextHolder is (and its representing figure) connected.

Specified by:
getRepresentingFigure in interface TextHolder
Returns:
figure responsible for representing the content of this TextHolder