view
Class TextDraw

java.lang.Object
  extended by view.AbstractFilledShape
      extended by view.TextDraw
All Implemented Interfaces:
Centerable, FilledShape

public class TextDraw
extends AbstractFilledShape
implements Centerable

Drawing text in shapes is not recomended as the text size will change due to component size changes. Thus we provide here a basic class that combines all relevant information on drawing text to a shape canvas. Instances of this class can be added to the shape canvas by calls to JNormalizedCanvas#addText.


Field Summary
private  boolean filled
          If only the outline of the text should be drawn, this is false.
private  Font font
          The font to use for rendering.
private  float horjust
          The horizontal justification.
private  Point2D offset
          We need extra offset, as we never scale the string.
private  Point2D position
          The position of the text in a 0,0, 1x1 drawing area.
private  double rotation
          A rotational angle.
private  String text
          The text to draw.
private  float vertjust
          The vertical justification.
 
Constructor Summary
TextDraw(String note, Font render, Point2D where)
          Constructs a text-draw object additionally specifying a font.
TextDraw(String note, Font render, Point2D where, float vjus, float hjus, double rot)
          Constructs a rotated text-draw object with given justifications, but no extra offset.
TextDraw(String note, Font render, Point2D where, Point2D extra, float vjus, float hjus, double rot)
          Constructs a full text-draw object.
TextDraw(String note, Font render, Point2D where, Point2D extra, float vjus, float hjus, double rot, boolean fill)
          Constructs a full text-draw object.
TextDraw(String note, Point2D where)
          Construct a text draw object with the minimal information.
TextDraw(String note, Point2D where, float vjus, float hjus)
          Constructs a text-draw object with given justifications.
 
Method Summary
 boolean equals(Object that)
          Equal, if equal position, string rotation, font etc.
 Rectangle2D getBounds2D(Component c)
          Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero in the given component.
 Rectangle2D getBounds2D(Font def, FontRenderContext frt)
          Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero.
 Rectangle2D getBounds2D(GlyphVector gv)
          Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero.
 Point2D getCenter()
          Simplified center.
 Font getFont()
          Returns the font used to render this string.
 GlyphVector getGlyphVector(Font def, FontRenderContext frt)
          Returns the glyph vector to the text draw object.
 float getHorizontalJustification()
          Returns the horizontal justification.
 Point2D getOffset()
          Returns the absolute offset of the text in pixel coordinates.
 Point2D getPosition()
          Returns the position of the text in a 0,0 1x1 frame.
 Shape getRotated(GlyphVector gv)
          Transforms the glyph vector to a rotated instance.
 double getRotation()
          Returns the rotation angle.
 Shape getShape(Graphics2D g2d)
          Returns the zero-centered shape.
 String getText()
          Returns the text to draw.
 float getVerticalJustification()
          Returns the vertical justification.
 int hashCode()
          Hash code is the has code of the location.
 boolean isFilled()
          Returns the true, if text should be painted as filled (default).
 boolean isRotate()
          Returns true, if the text has to be transformed.
 
Methods inherited from class view.AbstractFilledShape
getUnique
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

text

private String text
The text to draw.


font

private Font font
The font to use for rendering. Null for default.


position

private Point2D position
The position of the text in a 0,0, 1x1 drawing area.


offset

private Point2D offset
We need extra offset, as we never scale the string.


vertjust

private float vertjust
The vertical justification.


horjust

private float horjust
The horizontal justification.


rotation

private double rotation
A rotational angle. Zero provides best results.


filled

private boolean filled
If only the outline of the text should be drawn, this is false.

Constructor Detail

TextDraw

public TextDraw(String note,
                Point2D where)
Construct a text draw object with the minimal information.


TextDraw

public TextDraw(String note,
                Font render,
                Point2D where)
Constructs a text-draw object additionally specifying a font.


TextDraw

public TextDraw(String note,
                Point2D where,
                float vjus,
                float hjus)
Constructs a text-draw object with given justifications.


TextDraw

public TextDraw(String note,
                Font render,
                Point2D where,
                float vjus,
                float hjus,
                double rot)
Constructs a rotated text-draw object with given justifications, but no extra offset.


TextDraw

public TextDraw(String note,
                Font render,
                Point2D where,
                Point2D extra,
                float vjus,
                float hjus,
                double rot)
Constructs a full text-draw object.


TextDraw

public TextDraw(String note,
                Font render,
                Point2D where,
                Point2D extra,
                float vjus,
                float hjus,
                double rot,
                boolean fill)
Constructs a full text-draw object.

Method Detail

getText

public String getText()
Returns the text to draw.


getFont

public Font getFont()
Returns the font used to render this string.


getPosition

public Point2D getPosition()
Returns the position of the text in a 0,0 1x1 frame. The actual drawing position will also depend on the justification value.


getOffset

public Point2D getOffset()
Returns the absolute offset of the text in pixel coordinates. This is required as strings are not entirely scaled (font stays constant).


getHorizontalJustification

public float getHorizontalJustification()
Returns the horizontal justification. Zero denotes left-justified, one is right-justified and 0.5 is centered.


getVerticalJustification

public float getVerticalJustification()
Returns the vertical justification. Zero denotes bottom-justified, one is top-justified and 0.5 is centered.


getRotation

public double getRotation()
Returns the rotation angle.


getGlyphVector

public GlyphVector getGlyphVector(Font def,
                                  FontRenderContext frt)
Returns the glyph vector to the text draw object. The default font is used only if no font was assigned to that text draw object.


isRotate

public boolean isRotate()
Returns true, if the text has to be transformed.


getBounds2D

public Rectangle2D getBounds2D(Component c)
Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero in the given component.


getBounds2D

public Rectangle2D getBounds2D(Font def,
                               FontRenderContext frt)
Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero.


getBounds2D

public Rectangle2D getBounds2D(GlyphVector gv)
Returns the bounding rectangle of this text draw object in screen coordinates, if positioned at zero,zero.


getRotated

public Shape getRotated(GlyphVector gv)
Transforms the glyph vector to a rotated instance.


isFilled

public boolean isFilled()
Returns the true, if text should be painted as filled (default).

Specified by:
isFilled in interface FilledShape

getShape

public Shape getShape(Graphics2D g2d)
Returns the zero-centered shape.

Specified by:
getShape in interface FilledShape

getCenter

public Point2D getCenter()
Simplified center.

Specified by:
getCenter in interface Centerable

hashCode

public int hashCode()
Hash code is the has code of the location.

Overrides:
hashCode in class AbstractFilledShape

equals

public boolean equals(Object that)
Equal, if equal position, string rotation, font etc.

Overrides:
equals in class AbstractFilledShape