org.das2.util
Class GrannyTextRenderer

java.lang.Object
  extended by org.das2.util.GrannyTextRenderer

public class GrannyTextRenderer
extends java.lang.Object

Renders Grandle and Nystrom strings, like "E=mc!e2"


Field Summary
static int CENTER_ALIGNMENT
           
static int LEFT_ALIGNMENT
           
static int RIGHT_ALIGNMENT
           
 
Constructor Summary
GrannyTextRenderer()
           
 
Method Summary
 void draw(java.awt.Graphics ig, float ix, float iy)
          draw the current string.
 int getAlignment()
          returns the current alignment, by default LEFT_ALIGNMENT.
 double getAscent()
          return the amount that the bounding box will go above the baseline.
 java.awt.Rectangle getBounds()
          returns the bounds of the current string.
 double getDescent()
          return the amount that the bounding box will go below the baseline.
 double getHeight()
          returns the hieght of the calculated bounding box.
 double getLineOneWidth()
          returns the width in pixels of the first line.
 double getWidth()
          returns the width of the bounding box, in pixels.
 void setAlignment(int a)
          set the alignment for rendering, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.
 void setString(java.awt.Component c, java.lang.String str)
          Deprecated. use setString( Graphics g, String str ) instead.
 void setString(java.awt.Font font, java.lang.String label)
          reset the current string for the GTR to draw, calculating the boundaries of the string.
 void setString(java.awt.Graphics g, java.lang.String str)
          reset the current string for the GTR to draw, calculating the boundaries of the string.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT_ALIGNMENT

public static final int LEFT_ALIGNMENT
See Also:
Constant Field Values

CENTER_ALIGNMENT

public static final int CENTER_ALIGNMENT
See Also:
Constant Field Values

RIGHT_ALIGNMENT

public static final int RIGHT_ALIGNMENT
See Also:
Constant Field Values
Constructor Detail

GrannyTextRenderer

public GrannyTextRenderer()
Method Detail

getBounds

public java.awt.Rectangle getBounds()
returns the bounds of the current string. The lower-left corner of the first character will be roughly (0,0), to be compatible with FontMetrics.getStringBounds().

Returns:
a Rectangle indicating the text boundaries.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

getWidth

public double getWidth()
returns the width of the bounding box, in pixels.

Returns:
the width of the bounding box, in pixels.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

getLineOneWidth

public double getLineOneWidth()
returns the width in pixels of the first line.

Returns:
the width in pixels of the first line.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

getHeight

public double getHeight()
returns the hieght of the calculated bounding box.

Returns:
the height of the bounding box, in pixels.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

getAscent

public double getAscent()
return the amount that the bounding box will go above the baseline. This is also the height of the first line.

Returns:
the amount that the bounding box will go above the baseline.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

getDescent

public double getDescent()
return the amount that the bounding box will go below the baseline.

Returns:
the amount that the bounding box will go below the baseline.
Throws:
java.lang.IllegalArgumentException - if the string has not been set.

setString

public void setString(java.awt.Component c,
                      java.lang.String str)
Deprecated. use setString( Graphics g, String str ) instead.

reset the current string for the GTR to draw, calculating the boundaries of the string. For greek and math symbols, unicode characters should be used. (See www.unicode.org).

Parameters:
c - the component which will provide the graphics.
str - the granny string, such as "E=mc!e2"

setString

public void setString(java.awt.Graphics g,
                      java.lang.String str)
reset the current string for the GTR to draw, calculating the boundaries of the string. For greek and math symbols, unicode characters should be used. (See www.unicode.org).

Parameters:
g - the graphics context which will supply the FontMetrics.
str - the granny string, such as "E=mc!e2"

setString

public void setString(java.awt.Font font,
                      java.lang.String label)
reset the current string for the GTR to draw, calculating the boundaries of the string. For greek and math symbols, unicode characters should be used. (See www.unicode.org).

Parameters:
Font - the font. This should be consistent with the Font used when drawing.
str - the granny string, such as "E=mc!e2"

getAlignment

public int getAlignment()
returns the current alignment, by default LEFT_ALIGNMENT.

Returns:
the current alignment.

setAlignment

public void setAlignment(int a)
set the alignment for rendering, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.

Parameters:
a - the alignment, one of LEFT_ALIGNMENT CENTER_ALIGNMENT or RIGHT_ALIGNMENT.

draw

public void draw(java.awt.Graphics ig,
                 float ix,
                 float iy)
draw the current string. Note the first line will be above iy, and following lines will be below iy. This is to be consistent with Graphics2D.drawString.

Parameters:
ig - Graphic object to use to render the text.
ix - The x position of the first character of text.
iy - The y position of the baseline of the first line of text.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object