j3d.org Code

org.j3d.renderer.java3d.overlay
Class LabelOverlay

java.lang.Object
  extended byorg.j3d.renderer.java3d.overlay.OverlayBase
      extended byorg.j3d.renderer.java3d.overlay.LabelOverlay
All Implemented Interfaces:
java.awt.event.ComponentListener, java.util.EventListener, Overlay, ScreenComponent, UpdatableEntity

public class LabelOverlay
extends 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.2 $
Author:
Justin Couch

Field Summary
static int BOTTOM_ALIGN
          The value for the BOTTOM vertical alignment
static int CENTER_ALIGN
          The value for the CENTER horizontal and vertical alignments
static int LEFT_ALIGN
          The value for the LEFT horizontal alignment
static int RIGHT_ALIGN
          The value for the RIGHT horizontal alignment
static int TOP_ALIGN
          The value for the TOP vertical alignment
 
Fields inherited from class org.j3d.renderer.java3d.overlay.OverlayBase
activeBuffer, backgroundColor, backgroundMode, bottomInset, canvas, componentSize, consoleBG, consoleTG, DEFAULT_INSET, DIRTY_ACTIVE_BUFFER, DIRTY_POSITION, DIRTY_SIZE, DIRTY_VISIBLE, fieldOfView, fixedSize, leftInset, overlayBounds, overlayTexGrp, rightInset, subOverlay, topInset
 
Fields inherited from interface org.j3d.renderer.java3d.overlay.Overlay
BACKGROUND_COPY, BACKGROUND_NONE
 
Constructor Summary
LabelOverlay(javax.media.j3d.Canvas3D canvas, java.awt.Dimension size)
          Create a new, simple label overlay that does not contain any text.
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.
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.
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, UpdateManager manager)
          Create a customised label overlay that includes a specialised update manager to control when items are updated.
 
Method Summary
 int getHorizontalAlignment()
          Fetch the current horizontal alignment setting.
 int getVerticalAlignment()
          Fetch the current vertical alignment setting.
 int getVisibleLength()
          Get the number of characters that are rendered from the given string.
 void paint(java.awt.Graphics2D g)
          Repaint the overlay now.
 void setColor(java.awt.Color c)
          Change the rendering color of the text to be rendered.
 void setFont(java.awt.Font f)
          Change the font used by the text to be rendered.
 void setHorizontalAlignment(int align)
          Set the horizontal alignment of the text in this overlay.
 void setInsets(int left, int top, int right, int bottom)
          Set the insets for this overlay.
 void setText(java.lang.String str)
          Set the text to the new string.
 void setVerticalAlignment(int align)
          Set the vertical alignment of the text in this overlay.
 void setVisibleLength(int length)
          Set the number of visible characters to the given size.
 
Methods inherited from class org.j3d.renderer.java3d.overlay.OverlayBase
componentHidden, componentMoved, componentResized, componentShown, contains, dirty, getBackgroundImage, getBounds, getGraphics, getRoot, getUpdateManager, initialize, isAntialiased, isVisible, repaint, setActiveBuffer, setAntialiased, setBackgroundColor, setBackgroundImage, setBackgroundMode, setComponentDetails, setInsets, setLocation, setSize, setUpdateManager, setVisible, update, updateBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_ALIGN

public static final int LEFT_ALIGN
The value for the LEFT horizontal alignment

See Also:
Constant Field Values

RIGHT_ALIGN

public static final int RIGHT_ALIGN
The value for the RIGHT horizontal alignment

See Also:
Constant Field Values

CENTER_ALIGN

public static final int CENTER_ALIGN
The value for the CENTER horizontal and vertical alignments

See Also:
Constant Field Values

TOP_ALIGN

public static final int TOP_ALIGN
The value for the TOP vertical alignment

See Also:
Constant Field Values

BOTTOM_ALIGN

public static final int BOTTOM_ALIGN
The value for the BOTTOM vertical alignment

See Also:
Constant Field Values
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,
                    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.

Overrides:
paint in class OverlayBase
Parameters:
g - The graphics context to paint with

setInsets

public void setInsets(int left,
                      int top,
                      int right,
                      int bottom)
Set the insets for this overlay. Note that this will not force a dirty condition. A derived class will need to override this method and make any size recalculations and dirty bit handling if this is needed.

Overrides:
setInsets in class OverlayBase

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

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org