JHotDraw 6.0b1

org.jhotdraw.figures
Class TextFigure

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

public class TextFigure
extends AttributeFigure
implements FigureChangeListener, TextHolder

A text figure.

See Also:
TextTool, Serialized Form

Constructor Summary
TextFigure()
           
 
Method Summary
 boolean acceptsTyping()
          Tests whether the figure accepts typing.
 void basicDisplayBox(java.awt.Point newOrigin, java.awt.Point newCorner)
          Sets the display box of a figure.
protected  void basicMoveBy(int x, int y)
          Moves the figure.
 void changed()
          Updates the location whenever the figure changes itself.
 void connect(Figure figure)
          Connects a text holder to another figure.
static java.awt.Font createCurrentFont()
          Creates the current font to be used for new text figures.
 void disconnect(Figure disconnectFigure)
          Disconnects a text holder from a connect figure.
 java.awt.Rectangle displayBox()
          Gets the display box of a figure.
 void drawBackground(java.awt.Graphics g)
          Draws the background of the figure.
 void drawFrame(java.awt.Graphics g)
          Draws the frame of the figure.
 void figureChanged(FigureChangeEvent e)
          Sent when a figure changed
 void figureInvalidated(FigureChangeEvent e)
          Sent when an area is invalid
 void figureRemoved(FigureChangeEvent e)
          Sent when a figure was removed
 void figureRequestRemove(FigureChangeEvent e)
          Sent when requesting to remove a figure.
 void figureRequestUpdate(FigureChangeEvent e)
          Sent when an update should happen.
 java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
          A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.
 java.lang.Object getAttribute(java.lang.String name)
          Deprecated. use getAttribute(FigureAttributeConstant) instead
 java.awt.Font getFont()
          Gets the font.
protected  OffsetLocator getLocator()
           
 Figure getObservedFigure()
           
 Figure getRepresentingFigure()
          Usually, a TextHolders is implemented by a Figure subclass.
 java.lang.String getText()
          Gets the text shown by the text figure.
 TextHolder getTextHolder()
          Some figures have the ability to hold text.
 HandleEnumeration handles()
          Returns the handles of a Figure that can be used to manipulate some of its attributes.
protected  void markDirty()
           
 void moveBy(int x, int y)
          Moves the figure by the given offset.
 int overlayColumns()
          Gets the number of columns to be overlaid when the figure is edited.
 void read(StorableInput dr)
          Reads the Figure from a StorableInput.
 boolean readOnly()
          Tests whether this figure is read only.
 void release()
          A figure is released from the drawing.
 void setAttribute(FigureAttributeConstant attributeConstant, java.lang.Object value)
          A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Deprecated. use setAttribute(FigureAttributeConstant, Object) instead
static void setCurrentFontName(java.lang.String name)
          Sets the current font name
static void setCurrentFontSize(int size)
          Sets the current font size.
static void setCurrentFontStyle(int style)
          Sets the current font style.
 void setFont(java.awt.Font newFont)
          Sets the font.
protected  void setLocator(OffsetLocator newLocator)
           
protected  void setObservedFigure(Figure newObservedFigure)
           
 void setReadOnly(boolean isReadOnly)
          Sets the read only status of the text figure.
 void setText(java.lang.String newText)
          Sets the text shown by the text figure.
 java.awt.Rectangle textDisplayBox()
           
protected  java.awt.Dimension textExtent()
           
protected  void updateLocation()
          Updates the location relative to the connected figure.
 void write(StorableOutput dw)
          Stores the Figure to a StorableOutput.
 
Methods inherited from class org.jhotdraw.figures.AttributeFigure
draw, getDefaultAttribute, getDefaultAttribute, getFillColor, getFrameColor, initDefaultAttribute, setDefaultAttribute
 
Methods inherited from class org.jhotdraw.standard.AbstractFigure
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, clone, connectedTextLocator, connectionInsets, connectorAt, connectorVisibility, containsPoint, decompose, displayBox, displayBox, figures, findFigureInside, getDecoratedFigure, getDependendFigures, getZValue, includes, invalidate, invalidateRectangle, isEmpty, listener, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFigure

public TextFigure()
Method Detail

moveBy

public void moveBy(int x,
                   int y)
Description copied from class: AbstractFigure
Moves the figure by the given offset.

Specified by:
moveBy in interface Figure
Overrides:
moveBy in class AbstractFigure
Parameters:
x - the x delta
y - the y delta
See Also:
Figure.moveBy(int, int)

basicMoveBy

protected void basicMoveBy(int x,
                           int y)
Description copied from class: AbstractFigure
Moves the figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicMoveBy in class AbstractFigure
See Also:
AbstractFigure.moveBy(int, int)

basicDisplayBox

public void basicDisplayBox(java.awt.Point newOrigin,
                            java.awt.Point newCorner)
Description copied from class: AbstractFigure
Sets the display box of a figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicDisplayBox in interface Figure
Specified by:
basicDisplayBox in class AbstractFigure
Parameters:
newOrigin - the new origin
newCorner - the new corner
See Also:
Figure.basicDisplayBox(java.awt.Point, java.awt.Point)

displayBox

public java.awt.Rectangle displayBox()
Description copied from class: AbstractFigure
Gets the display box of a figure.

Specified by:
displayBox in interface Figure
Specified by:
displayBox in class AbstractFigure
See Also:
Figure.displayBox()

textDisplayBox

public java.awt.Rectangle textDisplayBox()
Specified by:
textDisplayBox in interface TextHolder
See Also:
TextHolder.textDisplayBox()

readOnly

public boolean readOnly()
Tests whether this figure is read only.


setReadOnly

public void setReadOnly(boolean isReadOnly)
Sets the read only status of the text figure.


getFont

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

Specified by:
getFont in interface TextHolder
See Also:
TextHolder.getFont()

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
See Also:
TextHolder.getRepresentingFigure()

setFont

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


changed

public void changed()
Updates the location whenever the figure changes itself.

Specified by:
changed in interface Figure
Overrides:
changed in class AbstractFigure
See Also:
Figure.changed()

getAttribute

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

A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AttributeFigure
See Also:
Figure.getAttribute(java.lang.String)

getAttribute

public java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AttributeFigure
See Also:
Figure.getAttribute(org.jhotdraw.framework.FigureAttributeConstant)

setAttribute

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

A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AttributeFigure
See Also:
Figure.setAttribute(java.lang.String, java.lang.Object)

setAttribute

public void setAttribute(FigureAttributeConstant attributeConstant,
                         java.lang.Object value)
A text figure understands the "FontSize", "FontStyle", and "FontName" attributes.

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AttributeFigure
See Also:
Figure.setAttribute(org.jhotdraw.framework.FigureAttributeConstant, java.lang.Object)

getText

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

Specified by:
getText in interface TextHolder
See Also:
TextHolder.getText()

setText

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

Specified by:
setText in interface TextHolder
See Also:
TextHolder.setText(java.lang.String)

acceptsTyping

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

Specified by:
acceptsTyping in interface TextHolder
See Also:
TextHolder.acceptsTyping()

drawBackground

public void drawBackground(java.awt.Graphics g)
Description copied from class: AttributeFigure
Draws the background of the figure.

Overrides:
drawBackground in class AttributeFigure
See Also:
AttributeFigure.drawBackground(java.awt.Graphics)

drawFrame

public void drawFrame(java.awt.Graphics g)
Description copied from class: AttributeFigure
Draws the frame of the figure.

Overrides:
drawFrame in class AttributeFigure
See Also:
AttributeFigure.drawFrame(java.awt.Graphics)

textExtent

protected java.awt.Dimension textExtent()

markDirty

protected void markDirty()

overlayColumns

public int overlayColumns()
Gets the number of columns to be overlaid when the figure is edited.

Specified by:
overlayColumns in interface TextHolder
See Also:
TextHolder.overlayColumns()

handles

public HandleEnumeration handles()
Description copied from class: AbstractFigure
Returns the handles of a Figure that can be used to manipulate some of its attributes.

Specified by:
handles in interface Figure
Specified by:
handles in class AbstractFigure
Returns:
a type-safe iterator of handles
See Also:
Figure.handles()

write

public void write(StorableOutput dw)
Description copied from class: AttributeFigure
Stores the Figure to a StorableOutput.

Specified by:
write in interface Storable
Overrides:
write in class AttributeFigure
See Also:
Storable.write(org.jhotdraw.util.StorableOutput)

read

public void read(StorableInput dr)
          throws java.io.IOException
Description copied from class: AttributeFigure
Reads the Figure from a StorableInput.

Specified by:
read in interface Storable
Overrides:
read in class AttributeFigure
Throws:
java.io.IOException
See Also:
Storable.read(org.jhotdraw.util.StorableInput)

connect

public void connect(Figure figure)
Description copied from interface: TextHolder
Connects a text holder to another figure.

Specified by:
connect in interface TextHolder
See Also:
TextHolder.connect(org.jhotdraw.framework.Figure)

figureChanged

public void figureChanged(FigureChangeEvent e)
Description copied from interface: FigureChangeListener
Sent when a figure changed

Specified by:
figureChanged in interface FigureChangeListener
See Also:
FigureChangeListener.figureChanged(org.jhotdraw.framework.FigureChangeEvent)

figureRemoved

public void figureRemoved(FigureChangeEvent e)
Description copied from interface: FigureChangeListener
Sent when a figure was removed

Specified by:
figureRemoved in interface FigureChangeListener
See Also:
FigureChangeListener.figureRemoved(org.jhotdraw.framework.FigureChangeEvent)

figureRequestRemove

public void figureRequestRemove(FigureChangeEvent e)
Description copied from interface: FigureChangeListener
Sent when requesting to remove a figure.

Specified by:
figureRequestRemove in interface FigureChangeListener
See Also:
FigureChangeListener.figureRequestRemove(org.jhotdraw.framework.FigureChangeEvent)

figureInvalidated

public void figureInvalidated(FigureChangeEvent e)
Description copied from interface: FigureChangeListener
Sent when an area is invalid

Specified by:
figureInvalidated in interface FigureChangeListener
See Also:
FigureChangeListener.figureInvalidated(org.jhotdraw.framework.FigureChangeEvent)

figureRequestUpdate

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

Specified by:
figureRequestUpdate in interface FigureChangeListener
See Also:
FigureChangeListener.figureRequestUpdate(org.jhotdraw.framework.FigureChangeEvent)

updateLocation

protected void updateLocation()
Updates the location relative to the connected figure. The TextFigure is centered around the located point.


release

public void release()
Description copied from class: AbstractFigure
A figure is released from the drawing. You never call this method directly. Release notifies its listeners.

Specified by:
release in interface Figure
Overrides:
release in class AbstractFigure
See Also:
Figure.release()

disconnect

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

Specified by:
disconnect in interface TextHolder
See Also:
TextHolder.disconnect(org.jhotdraw.framework.Figure)

setObservedFigure

protected void setObservedFigure(Figure newObservedFigure)

getObservedFigure

public Figure getObservedFigure()

setLocator

protected void setLocator(OffsetLocator newLocator)

getLocator

protected OffsetLocator getLocator()

getTextHolder

public TextHolder getTextHolder()
Description copied from interface: Figure
Some figures have the ability to hold text. This method returns the adjunctant TextHolder.

Specified by:
getTextHolder in interface Figure
Overrides:
getTextHolder in class AbstractFigure
Returns:
See Also:
Figure.getTextHolder()

createCurrentFont

public static java.awt.Font createCurrentFont()
Creates the current font to be used for new text figures.


setCurrentFontName

public static void setCurrentFontName(java.lang.String name)
Sets the current font name


setCurrentFontSize

public static void setCurrentFontSize(int size)
Sets the current font size.


setCurrentFontStyle

public static void setCurrentFontStyle(int style)
Sets the current font style.


JHotDraw 6.0b1