edu.cmu.sun.components
Class Text2DView

java.lang.Object
  extended by Shape3D
      extended by edu.cmu.sun.components.Text2DView

public class Text2DView
extends Shape3D

Renders text in LG3D by mapping a bitmap onto a polygon. This class was heavily based off of code from Sun Microsystems. This class is used because LG3D does not yet have a text system. The Shape3D that is created is aligned on the lwoer left point at the decender line. Other text functions usuially place text at the baseline. Be careful of this distinction. (If this doesn't make sense, look for typography diagrams to show the parts of a font.)

Author:
Braden Kowitz, Jake Pierson, Jessica Smith, and Others

Field Summary
private  boolean bold
           
private static java.awt.FontMetrics fontMetrics
          Font metrics *
private static int fontQuality
          Font quality *
private  IndexedGeometryArray geometry
          Indexed geometry *
protected  float h
           
private  float height
          Height *
private static int HEIGHT_MARGIN
          Margin height *
private  float heightRatio
          Height ration *
static int MAX_FONT_QUALITY
          Max font quality *
static int MIN_FONT_QUALITY
          Min font quality *
private  float prevAdjustedWidth
           
private static java.awt.Color textColor
          Text color *
private static java.awt.Font textFont
          Text properties *
private  boolean vertical
           
protected  float w
           
private  float width
          Width *
private static int WIDTH_MARGIN
          Margin width *
private  float widthRatio
          Width ratio *
 
Constructor Summary
Text2DView(java.lang.String text, float size, int quality)
          Class constructor that create a 2D text object.
Text2DView(java.lang.String text, float size, int quality, boolean bold)
           
Text2DView(java.lang.String text, float size, int quality, java.awt.Color theColor)
          Constructor to create non-black 2D text object
Text2DView(java.lang.String text, float size, int quality, java.awt.Color color, float alpha)
          Class constructor that create a 2D text object with user specified color and alpha.
 
Method Summary
 java.awt.image.BufferedImage createMultilineImage(java.util.ArrayList<java.lang.String> textLines, int maxLineLength, int indentPixels)
           
 void createText2DColorTransp(java.lang.String text, float size, int quality, java.awt.Color color, float alpha)
          Create a 2D text object with a transperancy.
private  Texture createTexture(java.lang.String text)
          Create a texture for the text.
private  java.awt.image.BufferedImage createTextureImage(java.lang.String text)
          Create a buffered image from the text.
 float getHeight()
           
private  int getRoundUptoPow2(int n)
          Round up method.
 float getWidth()
           
private  void setFontQuality(int quality)
          Set the font quality between 12pt and 122pt
 void setWidth(float maxWidth)
          Sets the width of the text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WIDTH_MARGIN

private static final int WIDTH_MARGIN
Margin width *

See Also:
Constant Field Values

HEIGHT_MARGIN

private static final int HEIGHT_MARGIN
Margin height *

See Also:
Constant Field Values

MAX_FONT_QUALITY

public static final int MAX_FONT_QUALITY
Max font quality *

See Also:
Constant Field Values

MIN_FONT_QUALITY

public static final int MIN_FONT_QUALITY
Min font quality *

See Also:
Constant Field Values

textFont

private static java.awt.Font textFont
Text properties *


textColor

private static java.awt.Color textColor
Text color *


fontMetrics

private static java.awt.FontMetrics fontMetrics
Font metrics *


fontQuality

private static int fontQuality
Font quality *


width

private float width
Width *


height

private float height
Height *


w

protected float w

h

protected float h

geometry

private IndexedGeometryArray geometry
Indexed geometry *


widthRatio

private float widthRatio
Width ratio *


heightRatio

private float heightRatio
Height ration *


prevAdjustedWidth

private float prevAdjustedWidth

vertical

private boolean vertical

bold

private boolean bold
Constructor Detail

Text2DView

public Text2DView(java.lang.String text,
                  float size,
                  int quality,
                  boolean bold)

Text2DView

public Text2DView(java.lang.String text,
                  float size,
                  int quality)
Class constructor that create a 2D text object.

Parameters:
text - string to create
size - of the text object
quality - of the font used. Ranges from MAX_FONT_QUALITY = 10 to MIN_FONT_QUALITY = 1;

Text2DView

public Text2DView(java.lang.String text,
                  float size,
                  int quality,
                  java.awt.Color theColor)
Constructor to create non-black 2D text object


Text2DView

public Text2DView(java.lang.String text,
                  float size,
                  int quality,
                  java.awt.Color color,
                  float alpha)
Class constructor that create a 2D text object with user specified color and alpha.

Parameters:
text - string to create
size - of the text object
quality - of the font used. Ranges from MAX_FONT_QUALITY = 10 to MIN_FONT_QUALITY = 1
color - of the text
alpha - /transparency of the text
Method Detail

setWidth

public void setWidth(float maxWidth)
Sets the width of the text

Parameters:
maxWidth - of the text

createText2DColorTransp

public void createText2DColorTransp(java.lang.String text,
                                    float size,
                                    int quality,
                                    java.awt.Color color,
                                    float alpha)
Create a 2D text object with a transperancy. Ranges from MAX_FONT_QUALITY = 10 to MIN_FONT_QUALITY = 1.

Parameters:
text - string to create
size - of the text object
quality - of the font used.
color - of the text
alpha - /transparency of the text

setFontQuality

private void setFontQuality(int quality)
Set the font quality between 12pt and 122pt

Parameters:
quality - of the font of which to be set.

createMultilineImage

public java.awt.image.BufferedImage createMultilineImage(java.util.ArrayList<java.lang.String> textLines,
                                                         int maxLineLength,
                                                         int indentPixels)

createTextureImage

private java.awt.image.BufferedImage createTextureImage(java.lang.String text)
Create a buffered image from the text. This rasterized the text, making it suitable for display.

Parameters:
text - string to display.
Returns:
BufferedImage rasterized image to return.

getRoundUptoPow2

private int getRoundUptoPow2(int n)
Round up method.

Parameters:
n - is the number to round up.
Returns:
int number rounded up to the nearest power of 2.

createTexture

private Texture createTexture(java.lang.String text)
Create a texture for the text.

Parameters:
text - string to texture.
Returns:
Texture of the text.

getHeight

public float getHeight()

getWidth

public float getWidth()