net.sourceforge.olduvai.accordiondrawer
Class FontWrapper

java.lang.Object
  extended by net.sourceforge.olduvai.accordiondrawer.FontWrapper

public class FontWrapper
extends java.lang.Object

This is a wrapper to the jFTGL library intended to present an interface compatible with the older BitmapFont library. Once the jFTGL library API has stabilized, this class may disappear in favor of direct calls. It also caches generated font types & sizes so they don't need to be regenerated.

Author:
Peter McLachlan

Field Summary
private  AccordionDrawer ad
          Accordion drawer that uses this font wrapper.
private  java.util.HashMap<java.awt.Font,com.sun.opengl.util.j2d.TextRenderer> fontTable
          Table to cache font information; previously created font rendering objects (TextRenderer) are stored according to their Font object.
 
Constructor Summary
FontWrapper(AccordionDrawer ad)
          Font wrapper constructor.
 
Method Summary
private  com.sun.opengl.util.j2d.TextRenderer checkCreateFont(java.awt.Font font)
          Create a font renderer.
 void drawString(javax.media.opengl.GL gl, java.awt.geom.Point2D pos, double zPlane, java.lang.String text, java.awt.Font font, java.awt.Color color)
          Draw the text string at the given location.
 int getDescent(java.lang.String text, java.awt.Font f)
          Get the descent (number of pixels below the baseline) of the string in pixels.
 int stringHeight(java.lang.String text, java.awt.Font font)
          Get the height of the string in pixels.
 int stringWidth(java.lang.String text, java.awt.Font font)
          Get the width of the string in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fontTable

private java.util.HashMap<java.awt.Font,com.sun.opengl.util.j2d.TextRenderer> fontTable
Table to cache font information; previously created font rendering objects (TextRenderer) are stored according to their Font object. TODO: check the Font comparison technique, are we checking objects or font properties?


ad

private AccordionDrawer ad
Accordion drawer that uses this font wrapper. Each drawer should have its own.

Constructor Detail

FontWrapper

public FontWrapper(AccordionDrawer ad)
Font wrapper constructor. Sets the drawer.

Parameters:
ad - Drawer that is associated with this font wrapper.
Method Detail

checkCreateFont

private com.sun.opengl.util.j2d.TextRenderer checkCreateFont(java.awt.Font font)
Create a font renderer. If the renderer already exists in the cache, use it instead of making a new one.

Parameters:
font - Font to check or create.
Returns:
Retrieved renderer from the cache or a new renderer created from the input that has just been stored.

stringWidth

public int stringWidth(java.lang.String text,
                       java.awt.Font font)
Get the width of the string in pixels. Used to compute bounding boxes and object label positions/overlaps.

Parameters:
text - Series of characters to get width.
font - Font the characters are drawn in.
Returns:
The number of pixels wide for the given string.

stringHeight

public int stringHeight(java.lang.String text,
                        java.awt.Font font)
Get the height of the string in pixels. Used to compute bounding boxes and object label positions/overlaps.

Parameters:
text - Series of characters to get height.
font - Font the characters are drawn in.
Returns:
The number of pixels high for the given string.

getDescent

public int getDescent(java.lang.String text,
                      java.awt.Font f)
Get the descent (number of pixels below the baseline) of the string in pixels. Used to compute bounding boxes and object label positions/overlaps.

Parameters:
text - Series of characters to get descent.
f - Font the characters are drawn in.
Returns:
The number of pixels descended for the given string.

drawString

public void drawString(javax.media.opengl.GL gl,
                       java.awt.geom.Point2D pos,
                       double zPlane,
                       java.lang.String text,
                       java.awt.Font font,
                       java.awt.Color color)
Draw the text string at the given location.

Parameters:
gl - GL context
pos - 2D Location to place the text in world coordinates
text - Text to be rendered
zPlane - Vertical plane to use for this font (determines visibility, should be over all drawn objects)
font - Font object to use
color - Color for this string