## org.j3d.geom.overlay
Class LabelOverlay

public class LabelOverlay
extends org.j3d.geom.overlay.OverlayBase

  An overlay that renders a text label.

  The text alignment relative to the label may be controlled in both the horizontal and vertical alignment.

  By default, the font is Helvetica, Plain, 14 point, and the text colour is white. Alignment of the text is set to the top-left of the overlay.

Version:
  $Revision: 1.6 $
Author:
  Justin Couch

Field Detail

### DEFAULT_FONT

    private static final java.awt.Font DEFAULT_FONT

  If the user doesn't supply a font, use this one

### DEFAULT_COLOR

    private static final java.awt.Color DEFAULT_COLOR

  If the user does not supply a colour, use this one

### LEFT_ALIGN

    public static final int LEFT_ALIGN

  The value for the LEFT horizontal alignment

### RIGHT_ALIGN

    public static final int RIGHT_ALIGN

  The value for the RIGHT horizontal alignment

### CENTER_ALIGN

    public static final int CENTER_ALIGN

  The value for the CENTER horizontal and vertical alignments

### TOP_ALIGN

    public static final int TOP_ALIGN

  The value for the TOP vertical alignment

### BOTTOM_ALIGN

    public static final int BOTTOM_ALIGN

  The value for the BOTTOM vertical alignment

### BAD_ALIGN_MSG

    private static final java.lang.String BAD_ALIGN_MSG

  Message when the alignment value provided is incorrect

### text

    private java.lang.String text

  The string we are using to draw the text with

### renderedText

    private java.lang.String renderedText

  The rendered string, trimmed if needed to the right length

### visibleLength

    private int visibleLength

  The number of characters the user wants to be painted

### font

    private java.awt.Font font

  The font to render the text in

### color

    private java.awt.Color color

  The colour to use to render the font with

### verticalAlignment

    private int verticalAlignment

  The vertical alignment direction

### horizontalAlignment

    private int horizontalAlignment

  The horizontal alignment direction

### textX

    private int textX

  The current X position to render the text in

### textY

    private int textY

  The current Y position to render the text in

### textChanged

    private boolean textChanged

  Flag to say the text string has changed and the coordinates should be recalculated during the next paint cycle.

Constructor Detail

### LabelOverlay

    public LabelOverlay(javax.media.j3d.Canvas3D canvas,
                        java.awt.Dimension size)

  Create a new, simple label overlay that does not contain any text. The default colour and font is used and it is aligned to the top-left of the overlay.

Parameters:
  `canvas` - The canvas for this overlay to live on
  `size` - The size of the overlay in pixels

### LabelOverlay

    public LabelOverlay(javax.media.j3d.Canvas3D canvas,
                        java.awt.Dimension size,
                        java.lang.String str)

  Create a label overlay that displays the given text on the given screen space. The default colour and font is used and it is aligned to the top-left of the overlay. A null string will not be rendered.

Parameters:
  `canvas` - The canvas for this overlay to live on
  `size` - The size of the overlay in pixels
  `str` - The string to render or null

### LabelOverlay

    public LabelOverlay(javax.media.j3d.Canvas3D canvas,
                        java.awt.Dimension size,
                        java.lang.String str,
                        java.awt.Font font,
                        java.awt.Color color,
                        int hAlign,
                        int vAlign)

  Create a customised label overlay that uses the given attributes of font and colour styles. If the font or colour values are null then the defaults are used.

Parameters:
  `canvas` - The canvas for this overlay to live on
  `size` - The size of the overlay in pixels
  `str` - The string to render or null
  `font` - The font to use
  `color` - the color to render the text in
  `hAlign` - The horizontal alignment (LEFT, RIGHT, CENTER)
  `vAlign` - The vertical alignment (TOP, BOTTOM, CENTER)
Throws:
  `IllegalArguementException` - The alignment value given is not valid.

### LabelOverlay

    public LabelOverlay(javax.media.j3d.Canvas3D canvas,
                        java.awt.Dimension size,
                        java.lang.String str,
                        java.awt.Font font,
                        java.awt.Color color,
                        int hAlign,
                        int vAlign,
                        org.j3d.geom.overlay.UpdateManager manager)

  Create a customised label overlay that includes a specialised update manager to control when items are updated.

Parameters:
  `canvas` - The canvas for this overlay to live on
  `size` - The size of the overlay in pixels
  `str` - The string to render or null
  `font` - The font to use
  `color` - the color to render the text in
  `hAlign` - The horizontal alignment (LEFT, RIGHT, CENTER)
  `vAlign` - The vertical alignment (TOP, BOTTOM, CENTER)
  `manager` - The manger to use to control updates
Throws:
  `IllegalArguementException` - The alignment value given is not valid.

Method Detail

### paint

    public void paint(java.awt.Graphics2D g)

  Repaint the overlay now. Overrides the base class to provide text rendering.

Parameters:
  `g` - The graphics context to paint with

### setVerticalAlignment

    public void setVerticalAlignment(int align)

  Set the vertical alignment of the text in this overlay.

Parameters:
  `align` - One of TOP, BOTTOM, CENTER
Throws:
  `IllegalArguementException` - The alignment value given is not valid.

### getVerticalAlignment

    public int getVerticalAlignment()

  Fetch the current vertical alignment setting.

Returns:
  One of TOP, BOTTOM, CENTER

### setHorizontalAlignment

    public void setHorizontalAlignment(int align)

  Set the horizontal alignment of the text in this overlay.

Parameters:
  `align` - One of LEFT, RIGHT, CENTER
Throws:
  `IllegalArguementException` - The alignment value given is not valid.

### getHorizontalAlignment

    public int getHorizontalAlignment()

  Fetch the current horizontal alignment setting.

Returns:
  One of LEFT, RIGHT, CENTER

### setColor

    public void setColor(java.awt.Color c)

  Change the rendering color of the text to be rendered.

Parameters:
  `c` - The new colour to use

### setFont

    public void setFont(java.awt.Font f)

  Change the font used by the text to be rendered.

Parameters:
  `f` - The new font to use

### setText

    public void setText(java.lang.String str)

  Set the text to the new string. The visible length does not change so if you want to change the length, you should reset the visible length too

Parameters:
  `str` - The new string to use

### getVisibleLength

    public int getVisibleLength()

  Get the number of characters that are rendered from the given string. If the value is -1 the entire string is printed.

Returns:
  The current number of visble characters

### setVisibleLength

    public void setVisibleLength(int length)

  Set the number of visible characters to the given size. A size of zero effectively stops the string being rendered. If the value is -1 the entire string is printed.

Parameters:
  `length` - The number of characters to be shown