com.rolemodelsoft.drawlet.text
Class TextLabel

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractPaintable
        |
        +--com.rolemodelsoft.drawlet.basics.AbstractFigure
              |
              +--com.rolemodelsoft.drawlet.text.TextLabel

public class TextLabel
extends AbstractFigure
implements LabelHolder, RelatedLocationListener

This provides a basic implementation of a figure which displays simple text. It is assumed that this figure may be connected to another figure via its locator, but it can be used as just raw text also.

See Also:
Serialized Form

Field Summary
protected  java.awt.Font font
          The font with which to paint the label.
protected  int height
          Used to cache the height value to calc bounds faster.
protected  int left
          Used to cache the left value to calc bounds faster.
protected  MovableLocator locator
          The location of the label, the topLeft of where the string shows up.
protected  StringRenderer renderer
          The renderer used to actually display the label.
protected  java.lang.String string
          The string which serves as the label.
protected  java.awt.Color textColor
          The color with which to paint the label.
protected  int top
          Used to cache the top value to calc bounds faster.
protected static int unset
          Since ints are not objects and zero could be valid for any cache, we need to come up with "unset" values for each.
protected  int width
          Used to cache the width value to calc bounds faster.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
listeners, locationListeners
 
Constructor Summary
TextLabel()
          Constructs a new instance of a label.
TextLabel(java.awt.Color color)
          Constructs and initializes a new instance of a label with the given Color.
TextLabel(java.awt.Font font)
          Constructs and initializes a new instance of a label with the given Font.
TextLabel(java.awt.Font font, java.awt.Color color)
          Constructs and initializes a new instance of a label with the given Font and Color.
TextLabel(java.lang.String string)
          Constructs and initializes a new instance of a label with the given String.
TextLabel(java.lang.String string, java.awt.Font font)
          Constructs and initializes a new instance of a label with the given String and Font.
TextLabel(java.lang.String string, java.awt.Font font, java.awt.Color color)
          Constructs and initializes a new instance of a label with the given String, Font, and Color.
 
Method Summary
protected  void basicMove(Locator newLocator)
          Moves the receiver to a new location.
protected  void basicTranslate(int x, int y)
          Moves the receiver in the x and y direction.
protected  java.awt.Font defaultFont()
          Answer the default/initial value for the Font.
protected  MovableLocator defaultLocator()
          Answer the default/initial value for the Locator.
protected  java.lang.String defaultString()
          Answer the default/initial value for the String.
protected  java.awt.Color defaultTextColor()
          Answer the default/initial value for the color to paint the text.
 java.lang.Object duplicateIn(java.util.Hashtable duplicates)
          Duplicates the receiver and places the duplicate in the given Hashtable.
 Handle editTool(int x, int y)
          Answers a Handle that will provide editing capabilities on the receiver.
protected  void freeFromFigure(Figure figure)
          Remove any dependence on the Figure.
 java.awt.Rectangle getBounds()
          Returns the current bounds of the receiver.
 java.awt.Font getFont()
          Answer the Font with which the receiver paints.
 Handle[] getHandles()
          Answer the Handles associated with the receiver.
 int getHeight()
          Returns the height of the receiver.
 java.awt.Rectangle getLabelBounds()
          Returns the current bounds of the label.
protected  int getLabelHeight()
          Returns the height of the label of this figure.
protected  int getLabelLeft()
          Returns the leftmost coordinate of the label of this figure.
protected  int getLabelTop()
          Returns the topmost coordinate of the label of this figure.
protected  int getLabelWidth()
          Returns the width of the label of this figure.
 int getLeft()
          Returns the leftmost coordinate of the receiver.
 Locator getLocator()
          Returns the current locator of the receiver.
protected  StringRenderer getRenderer()
          Answer the renderer to use to display the label.
 java.lang.String getString()
          Answer the String the receiver paints.
 DrawingStyle getStyle()
          Answer the DrawingStyle which defines how to paint the receiver.
 java.awt.Color getTextColor()
          Answer the Color to use when drawing text.
 int getTop()
          Returns the topmost coordinate of the receiver.
 int getWidth()
          Returns the width of the receiver.
protected  boolean isListening(Figure figure)
          Answers whether the receiver is listening to the figure directly or indirectly (via chain of listeners).
 boolean isObsolete()
          Answers whether the receiver is obsolete True if some event has happened that makes this a meaningless object.
 void locationChanged(java.beans.PropertyChangeEvent event)
          Called when the location of something the receiver is listening to has changed.
 void move(Locator locator)
          Moves the receiver to a new location.
 void paint(java.awt.Graphics g)
          Paints the receiver.
 void postDuplicate(java.util.Hashtable duplicates)
          After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile.
 void relationChanged(java.beans.PropertyChangeEvent event)
          Called when the relation of something the receiver is listening to has changed.
 Locator requestConnection(Figure requestor, int x, int y)
          Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the requesting Figure.
protected  void resetBoundsCache()
          Flush caches with respect to determining bounds.
protected  void resetLocationCache()
          Flush caches with respect to determining location
protected  void resetSizeCache()
          Flush caches with respect to determining size
 void setFont(java.awt.Font newFont)
          Set the Font with which to paint text This is a TemplateMethod with hooks: resetBoundsCache() changedShape()
 void setString(java.lang.String newString)
          Set the string the figure paints.
 void setStyle(DrawingStyle style)
          Set the style defining how to paint the figure.
 void setTextColor(java.awt.Color color)
          Set the Color to use when drawing text.
 void shapeChanged(java.beans.PropertyChangeEvent event)
          Called when the shape of something the receiver is listening to has changed.
 void sizeChanged(java.beans.PropertyChangeEvent event)
          Called when the size of something the receiver is listening to has changed.
protected  void updateLocation()
          The Figure has notified the receiver of a change.
protected  int xMargin()
          Answer the margin to use in the x direction.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
addPropertyChangeListener, addRelatedLocationListener, basicMove, changedLocation, changedShape, changedSize, contains, contains, contains, deleteLocationListeners, disconnect, duplicate, estimatedDuplicateSize, figureFromLocator, fireLocationChange, firePropertyChange, firePropertyChange, fireRelationChange, fireShapeChange, fireSizeChange, getLocation, intersects, intersects, isWithin, isWithin, locatorAt, move, relatedLocationListeners, removePropertyChangeListener, removeRelatedLocationListener, setBounds, setSize, setSize, translate
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractPaintable
getBottom, getRight, getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

string

protected java.lang.String string
The string which serves as the label.

font

protected java.awt.Font font
The font with which to paint the label.

textColor

protected java.awt.Color textColor
The color with which to paint the label.

locator

protected MovableLocator locator
The location of the label, the topLeft of where the string shows up.

renderer

protected transient StringRenderer renderer
The renderer used to actually display the label.

unset

protected static int unset
Since ints are not objects and zero could be valid for any cache, we need to come up with "unset" values for each. For width and height, -1 would be fine, but those might be valid for top/left, as could basically any other integer. However, Integer.MIN_VALUE seems to be as unlikely as anything to be practical. So, we use it.

width

protected int width
Used to cache the width value to calc bounds faster.

height

protected int height
Used to cache the height value to calc bounds faster.

left

protected int left
Used to cache the left value to calc bounds faster.

top

protected int top
Used to cache the top value to calc bounds faster.
Constructor Detail

TextLabel

public TextLabel()
Constructs a new instance of a label.

TextLabel

public TextLabel(java.awt.Color color)
Constructs and initializes a new instance of a label with the given Color.
Parameters:
color - the color with which to display the label

TextLabel

public TextLabel(java.awt.Font font)
Constructs and initializes a new instance of a label with the given Font.
Parameters:
font - the font with which to display the label.

TextLabel

public TextLabel(java.awt.Font font,
                 java.awt.Color color)
Constructs and initializes a new instance of a label with the given Font and Color.
Parameters:
font - the Font with which to display the label.
color - the Color with which to display the label.

TextLabel

public TextLabel(java.lang.String string)
Constructs and initializes a new instance of a label with the given String.
Parameters:
string - the String to display as the label.

TextLabel

public TextLabel(java.lang.String string,
                 java.awt.Font font)
Constructs and initializes a new instance of a label with the given String and Font.
Parameters:
string - the String to display as the label.
font - the Font with which to display the label.

TextLabel

public TextLabel(java.lang.String string,
                 java.awt.Font font,
                 java.awt.Color color)
Constructs and initializes a new instance of a label with the given String, Font, and Color.
Parameters:
string - the String to display as the label.
font - the Font with which to display the label.
color - the Color with which to display the label.
Method Detail

basicMove

protected void basicMove(Locator newLocator)
Moves the receiver to a new location.
Parameters:
newLocator - the Locator to base the figure's position
See Also:
getLocator(), move(com.rolemodelsoft.drawlet.Locator)

basicTranslate

protected void basicTranslate(int x,
                              int y)
Moves the receiver in the x and y direction. Subclasses should probably provide synchronized versions if they're modifying attributes of the receiver.
Overrides:
basicTranslate in class AbstractFigure
Parameters:
x - amount to move in the x direction
y - amount to move in the y direction
See Also:
getLocator()

defaultFont

protected java.awt.Font defaultFont()
Answer the default/initial value for the Font.
Returns:
the default/initial Font.

defaultLocator

protected MovableLocator defaultLocator()
Answer the default/initial value for the Locator.
Returns:
the default/initial MovableLocator.

defaultString

protected java.lang.String defaultString()
Answer the default/initial value for the String.
Returns:
the default/initial String.

defaultTextColor

protected java.awt.Color defaultTextColor()
Answer the default/initial value for the color to paint the text.
Returns:
the default/initial Color for painting text.

duplicateIn

public java.lang.Object duplicateIn(java.util.Hashtable duplicates)
Duplicates the receiver and places the duplicate in the given Hashtable.
Overrides:
duplicateIn in class AbstractFigure
Parameters:
duplicates - the Hashtable to put the duplicate in.
Returns:
the duplicate.

editTool

public Handle editTool(int x,
                       int y)
Answers a Handle that will provide editing capabilities on the receiver.
Overrides:
editTool in class AbstractFigure
Parameters:
x - the x coordinate to potentially begin editing.
y - the y coordinate to potentially begin editing.

freeFromFigure

protected void freeFromFigure(Figure figure)
Remove any dependence on the Figure.
Parameters:
figure - the Figure to disassociate.

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of the receiver.
Overrides:
getBounds in class AbstractFigure
Returns:
a Rectangle representing the current bounds.

getFont

public java.awt.Font getFont()
Answer the Font with which the receiver paints.
Returns:
the Font in use.

getHandles

public Handle[] getHandles()
Answer the Handles associated with the receiver.
Overrides:
getHandles in class AbstractFigure
Returns:
an array of Handles.

getHeight

public int getHeight()
Returns the height of the receiver.
Overrides:
getHeight in class AbstractPaintable
Returns:
an integer representing the height of the receiver.

getLabelBounds

public java.awt.Rectangle getLabelBounds()
Returns the current bounds of the label.
Specified by:
getLabelBounds in interface LabelHolder
Returns:
an integer representing the bounds of the label.

getLabelHeight

protected int getLabelHeight()
Returns the height of the label of this figure.
Returns:
an integer representing the height of the label.

getLabelLeft

protected int getLabelLeft()
Returns the leftmost coordinate of the label of this figure.
Returns:
an integer representing the leftmost coordinate of the label.

getLabelTop

protected int getLabelTop()
Returns the topmost coordinate of the label of this figure.
Returns:
an integer representing the topmost coordinate of the label.

getLabelWidth

protected int getLabelWidth()
Returns the width of the label of this figure.
Returns:
an integer representing the width of the label.

getLeft

public int getLeft()
Returns the leftmost coordinate of the receiver.
Overrides:
getLeft in class AbstractPaintable
Returns:
an integer representing the leftmost coordinate of the receiver.

getLocator

public Locator getLocator()
Returns the current locator of the receiver. Answer a duplicate for security.
Overrides:
getLocator in class AbstractFigure
Returns:
a duplicate of the current Locator of the receiver.

getRenderer

protected StringRenderer getRenderer()
Answer the renderer to use to display the label.
Returns:
the StringRenderer used to display the label.

getString

public java.lang.String getString()
Answer the String the receiver paints.
Returns:
the String the receiver paints.

getStyle

public DrawingStyle getStyle()
Answer the DrawingStyle which defines how to paint the receiver.
Overrides:
getStyle in class AbstractFigure
Returns:
the DrawingStyle defining how to paint the receiver.

getTextColor

public java.awt.Color getTextColor()
Answer the Color to use when drawing text.
Returns:
the Color to use when drawing text.

getTop

public int getTop()
Returns the topmost coordinate of the receiver.
Overrides:
getTop in class AbstractPaintable
Returns:
an integer representing the topmost coordinate of the receiver.

getWidth

public int getWidth()
Returns the width of the receiver.
Overrides:
getWidth in class AbstractPaintable
Returns:
an integer representing the width of the receiver.

isListening

protected boolean isListening(Figure figure)
Answers whether the receiver is listening to the figure directly or indirectly (via chain of listeners).
Parameters:
figure - the Figure to test.
Returns:
a boolean value of true if we are listening; false otherwise.

isObsolete

public boolean isObsolete()
Answers whether the receiver is obsolete True if some event has happened that makes this a meaningless object.
Overrides:
isObsolete in class AbstractFigure
Returns:
boolean value of true if the receiver is obselete; false otherwise.

locationChanged

public void locationChanged(java.beans.PropertyChangeEvent event)
Called when the location of something the receiver is listening to has changed.
Specified by:
locationChanged in interface RelatedLocationListener
Parameters:
event - the event describing the change.

move

public void move(Locator locator)
Moves the receiver to a new location. This is a TemplateMethod with hooks: resetLocationCache() basicMove() changedLocation()
Overrides:
move in class AbstractFigure
Parameters:
locator - the Locator which identifies the desired x, y coordinates.
See Also:
getLocator(), basicMove(com.rolemodelsoft.drawlet.Locator)

paint

public void paint(java.awt.Graphics g)
Paints the receiver.
Overrides:
paint in class AbstractFigure
Parameters:
g - the specified Graphics window.

postDuplicate

public void postDuplicate(java.util.Hashtable duplicates)
After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile. In this case, remove any dependency on any figures defining original points. If there is an available duplicate corresponding to the original, use it as the original was used. If not, convert it to a non-Figure- dependent point. Copy remaining points as they are.
Overrides:
postDuplicate in class AbstractFigure
Parameters:
duplicates - a Hashtable with originals as keys and duplicates as elements.

relationChanged

public void relationChanged(java.beans.PropertyChangeEvent event)
Called when the relation of something the receiver is listening to has changed.
Specified by:
relationChanged in interface RelatedLocationListener
Parameters:
event - the event describing the change.

requestConnection

public Locator requestConnection(Figure requestor,
                                 int x,
                                 int y)
Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the requesting Figure.
Overrides:
requestConnection in class AbstractFigure
Parameters:
x - the x coordinate of the requested locator
y - the y coordinate of the requested locator

resetBoundsCache

protected void resetBoundsCache()
Flush caches with respect to determining bounds.

resetLocationCache

protected void resetLocationCache()
Flush caches with respect to determining location
Overrides:
resetLocationCache in class AbstractFigure

resetSizeCache

protected void resetSizeCache()
Flush caches with respect to determining size

setFont

public void setFont(java.awt.Font newFont)
Set the Font with which to paint text This is a TemplateMethod with hooks: resetBoundsCache() changedShape()
Parameters:
newFont - the Font to use for text.

setString

public void setString(java.lang.String newString)
Set the string the figure paints. This is a TemplateMethod with hooks: resetSizeCache() changedSize()
Parameters:
newString - the string to paint.

setStyle

public void setStyle(DrawingStyle style)
Set the style defining how to paint the figure.
Overrides:
setStyle in class AbstractFigure
Parameters:
style - the specified DrawingStyle.

setTextColor

public void setTextColor(java.awt.Color color)
Set the Color to use when drawing text.
Parameters:
color - the Color.

shapeChanged

public void shapeChanged(java.beans.PropertyChangeEvent event)
Called when the shape of something the receiver is listening to has changed.
Specified by:
shapeChanged in interface RelatedLocationListener
Parameters:
event - the event describing the change.

sizeChanged

public void sizeChanged(java.beans.PropertyChangeEvent event)
Called when the size of something the receiver is listening to has changed.
Specified by:
sizeChanged in interface RelatedLocationListener
Parameters:
event - the event describing the change.

updateLocation

protected void updateLocation()
The Figure has notified the receiver of a change. Assume our location has changed due to some movement/reshaping of the Figure.

xMargin

protected int xMargin()
Answer the margin to use in the x direction.
Returns:
an integer representing the margin to use in the x direction.