diva.util.java2d
Class PaintedString

java.lang.Object
  extended by diva.util.java2d.PaintedString
All Implemented Interfaces:
PaintedObject

public class PaintedString
extends java.lang.Object
implements PaintedObject

A utility class that paints a string. This is a low-level class which is designed to simplify the construction of drawn graphics. It contains enough font and painting information to be useful in many cases where fonts are needed for labels and so on in graphic diagrams.

Version:
$Id: PaintedString.java 38836 2005-07-11 17:25:39Z cxh $
Author:
Michael Shilman, John Reekie, Steve Neuendorffer

Field Summary
private  java.awt.geom.Rectangle2D _bounds
          The bounds
private static java.awt.Font _defaultFont
          The default font.
private  java.awt.Paint _fillPaint
          The fill paint of the string.
private  java.awt.Font _font
          The font.
private  java.util.List _shapes
          The shape of the label
private  java.lang.String _string
          The string that gets painted.
private  java.awt.geom.AffineTransform _transform
          The transform of the label
 
Constructor Summary
PaintedString()
          Construct an empty label figure.
PaintedString(java.lang.String s)
          Construct a label figure displaying the given string, using the default font.
PaintedString(java.lang.String s, java.awt.Font f)
          Construct a label figure displaying the given string in the given font.
PaintedString(java.lang.String s, java.lang.String face, int style, int size)
          Construct a label figure displaying the given string in the given face, style, and size.
 
Method Summary
private  void _update()
          Update internal variables after changing the transform or font or string.
 java.awt.geom.Rectangle2D getBounds()
          Get the bounds of this string
 java.awt.Paint getFillPaint()
          Get the fill paint for this label.
 java.awt.Font getFont()
          Get the font that this label is drawn in.
 java.lang.String getFontName()
          Get the font name.
 java.awt.Shape getShape()
          Get the shape of this label figure.
 int getSize()
          Get the font size.
 java.lang.String getString()
          Get the string of this label.
 int getStyle()
          Get the font style.
 void paint(java.awt.Graphics2D g)
          Paint the label.
 void setFillPaint(java.awt.Paint p)
          Set the fill paint that this shape is drawn with.
 void setFont(java.awt.Font f)
          Set the font.
 void setFontName(java.lang.String s)
          Set the font family by name.
 void setSize(int size)
          Set the font size.
 void setString(java.lang.String s)
          Set the string.
 void setStyle(int style)
          Set the font style.
 void setTransform(java.awt.geom.AffineTransform at)
          Change the transform of this label.
 void transform(java.awt.geom.AffineTransform at)
          Transform the label with the given transform.
 void translate(double x, double y)
          Translate the label the given distance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_string

private java.lang.String _string
The string that gets painted.


_defaultFont

private static java.awt.Font _defaultFont
The default font.


_font

private java.awt.Font _font
The font.


_fillPaint

private java.awt.Paint _fillPaint
The fill paint of the string.


_transform

private java.awt.geom.AffineTransform _transform
The transform of the label


_shapes

private java.util.List _shapes
The shape of the label


_bounds

private java.awt.geom.Rectangle2D _bounds
The bounds

Constructor Detail

PaintedString

public PaintedString()
Construct an empty label figure.


PaintedString

public PaintedString(java.lang.String s)
Construct a label figure displaying the given string, using the default font.


PaintedString

public PaintedString(java.lang.String s,
                     java.awt.Font f)
Construct a label figure displaying the given string in the given font. This is the best constructor to use if you are creating a lot of labels in a font other than the default, as a single instance of Font can then be shared by many labels.


PaintedString

public PaintedString(java.lang.String s,
                     java.lang.String face,
                     int style,
                     int size)
Construct a label figure displaying the given string in the given face, style, and size. A new Font object representing the face, style, and size is created for this label.

Method Detail

getBounds

public java.awt.geom.Rectangle2D getBounds()
Get the bounds of this string

Specified by:
getBounds in interface PaintedObject

getFont

public java.awt.Font getFont()
Get the font that this label is drawn in.


getFillPaint

public java.awt.Paint getFillPaint()
Get the fill paint for this label.


getFontName

public java.lang.String getFontName()
Get the font name.


getStyle

public int getStyle()
Get the font style.


getSize

public int getSize()
Get the font size.


getShape

public java.awt.Shape getShape()
Get the shape of this label figure. This just returns the bounds, since hit-testing on the actual filled latter shapes is way slow (and not that useful, since usually you want to treat the whole label as a single object anyway, and not have to click on an actual filled pixel).


getString

public java.lang.String getString()
Get the string of this label.


paint

public void paint(java.awt.Graphics2D g)
Paint the label.

Specified by:
paint in interface PaintedObject

setFillPaint

public void setFillPaint(java.awt.Paint p)
Set the fill paint that this shape is drawn with.


setFont

public void setFont(java.awt.Font f)
Set the font.


setFontName

public void setFontName(java.lang.String s)
Set the font family by name.


setStyle

public void setStyle(int style)
Set the font style.


setSize

public void setSize(int size)
Set the font size.


setString

public void setString(java.lang.String s)
Set the string.


setTransform

public void setTransform(java.awt.geom.AffineTransform at)
Change the transform of this label. Note that the anchor of the figure will appear to move -- use translateTo() to move it back again if this method being called to (for example) rotate the label.


transform

public void transform(java.awt.geom.AffineTransform at)
Transform the label with the given transform. Note that the anchor of the figure will appear to nmove -- use translateTo() to move it back again if this method being called to (for example) rotate the label.


translate

public void translate(double x,
                      double y)
Translate the label the given distance.


_update

private void _update()
Update internal variables after changing the transform or font or string. In the current implementation, we get a new outline shape and bounds using the current transform and cache them, since this is probably the fastest thing to do. Note that though there is a drawGlyphVector() method in Graphics2D, when we tried to use it, it appears to perform the translation TWICE. After screwing around with it for a while, I gave up [johnr].