edu.umd.cs.jazz.component
Class ZLabel

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZVisualComponent
              |
              +--edu.umd.cs.jazz.component.ZLabel
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZAppearance, ZPenColor, ZSerializable

public class ZLabel
extends ZVisualComponent
implements ZPenColor, java.io.Serializable

ZLabel creates a lightweight visual component to support a label containing one line of text. The label object is positioned so that its upper-left corner is at the origin, but this position can be altered with the setTranslate() methods.

Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

See Also:
Serialized Form

Field Summary
protected  java.awt.Color backgroundColor
          Background color for label.
protected  boolean boundsBug
          jdk version <= 1.2.1 has a bug: font.getStringBounds() gives the bounds of a space " " as zero.
protected static java.awt.Color DEFAULT_BACKGROUND_COLOR
          Default background color for label.
protected static java.awt.Font DEFAULT_FONT
          Default font for text.
protected static java.lang.String DEFAULT_FONT_NAME
          Default font name of text.
protected static int DEFAULT_FONT_SIZE
          Default font size for text.
protected static int DEFAULT_FONT_STYLE
          Default font style for text.
protected static java.awt.Color DEFAULT_PEN_COLOR
          Default color for text.
protected static java.lang.String DEFAULT_TEXT
          Default text when new text area is created.
protected  java.awt.Font font
          Current text font.
protected static java.awt.font.FontRenderContext HIGH_QUALITY_FONT_CONTEXT
          The high quality graphic2D render context: AntiAliased, and uses FractionalMetrics.
protected  java.lang.String line
          A label can hold one line of text.
protected static java.awt.font.FontRenderContext LOW_QUALITY_FONT_CONTEXT
          The low quality graphic2D render context: not antiAliased, and does not use FractionalMetrics.
protected  java.awt.Color penColor
          Current pen color.
protected  double translateX
          Translation offset X.
protected  double translateY
          Translation offset Y.
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, inTransaction, invalidBounds, invalidVolatileBounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZLabel()
          Default constructor for ZLabel.
ZLabel(java.lang.String str)
          ZLabel constructor with initial text.
ZLabel(java.lang.String str, java.awt.Font font)
          ZLabel constructor with initial text and font.
 
Method Summary
protected  void computeBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
protected  java.lang.Object duplicateObject()
          Returns a clone of this object.
 java.awt.Color getBackgroundColor()
          Returns the current background color.
 java.awt.Font getFont()
          Returns the current font.
 java.awt.Color getPenColor()
          Returns the current pen color.
 java.lang.String getText()
          Return the text within this label component.
 double getTranslateX()
          Get the X offset translation.
 double getTranslateY()
          Get the Y offset translation.
 java.awt.geom.Point2D getTranslation()
          Get the text translation offset.
 void render(ZRenderContext renderContext)
          Renders the label object
 void setBackgroundColor(java.awt.Color color)
          Sets the current background color.
 void setFont(java.awt.Font aFont)
          Sets the font for the text.
 void setPenColor(java.awt.Color color)
          Sets the current pen color.
 void setState(java.lang.String fieldType, java.lang.String fieldName, java.lang.Object fieldValue)
          Set some state of this object as it gets read back in.
 void setText(java.lang.String str)
          Sets the text of this visual component to str.
 void setTranslateX(double x)
          Set label translation offset X.
 void setTranslateY(double y)
          Set label translation offset Y.
 void setTranslation(double x, double y)
          Set the label translation offset to the specified position.
 void setTranslation(java.awt.geom.Point2D p)
          Set the label translation offset to point p.
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 
Methods inherited from class edu.umd.cs.jazz.ZVisualComponent
addParent, getNumParents, getParents, getParentsReference, getRoot, paint, pick, pickBounds, removeParent, repaint, repaint, trimToSize, updateBounds, updateObjectReferences, updateVolatility, writeObjectRecurse
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addClientProperty, addMouseListener, addMouseMotionListener, clone, computeVolatileBounds, dump, endTransaction, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getClientProperty, getHandles, getListenerList, getVolatileBounds, hasLisenerOfType, hasListenerOfType, hasMouseListener, markInTransaction, markNotInTransaction, processMouseEvent, putClientProperty, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds, startTransaction
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOW_QUALITY_FONT_CONTEXT

protected static final java.awt.font.FontRenderContext LOW_QUALITY_FONT_CONTEXT
The low quality graphic2D render context: not antiAliased, and does not use FractionalMetrics.


HIGH_QUALITY_FONT_CONTEXT

protected static final java.awt.font.FontRenderContext HIGH_QUALITY_FONT_CONTEXT
The high quality graphic2D render context: AntiAliased, and uses FractionalMetrics.


DEFAULT_FONT_NAME

protected static final java.lang.String DEFAULT_FONT_NAME
Default font name of text.

See Also:
Constant Field Values

DEFAULT_FONT_STYLE

protected static final int DEFAULT_FONT_STYLE
Default font style for text.

See Also:
Constant Field Values

DEFAULT_FONT_SIZE

protected static final int DEFAULT_FONT_SIZE
Default font size for text.

See Also:
Constant Field Values

DEFAULT_FONT

protected static final java.awt.Font DEFAULT_FONT
Default font for text.


DEFAULT_PEN_COLOR

protected static final java.awt.Color DEFAULT_PEN_COLOR
Default color for text.


DEFAULT_BACKGROUND_COLOR

protected static final java.awt.Color DEFAULT_BACKGROUND_COLOR
Default background color for label.


DEFAULT_TEXT

protected static final java.lang.String DEFAULT_TEXT
Default text when new text area is created.

See Also:
Constant Field Values

penColor

protected java.awt.Color penColor
Current pen color.


backgroundColor

protected java.awt.Color backgroundColor
Background color for label.


font

protected java.awt.Font font
Current text font.


line

protected java.lang.String line
A label can hold one line of text.


boundsBug

protected boolean boundsBug
jdk version <= 1.2.1 has a bug: font.getStringBounds() gives the bounds of a space " " as zero.


translateX

protected double translateX
Translation offset X.


translateY

protected double translateY
Translation offset Y.

Constructor Detail

ZLabel

public ZLabel()
Default constructor for ZLabel.


ZLabel

public ZLabel(java.lang.String str)
ZLabel constructor with initial text.


ZLabel

public ZLabel(java.lang.String str,
              java.awt.Font font)
ZLabel constructor with initial text and font.

Method Detail

duplicateObject

protected java.lang.Object duplicateObject()
Returns a clone of this object.

Overrides:
duplicateObject in class ZVisualComponent
See Also:
ZSceneGraphObject.duplicateObject()

getPenColor

public java.awt.Color getPenColor()
Returns the current pen color.

Specified by:
getPenColor in interface ZPenColor
Returns:
the pen color, or null if none.

setPenColor

public void setPenColor(java.awt.Color color)
Sets the current pen color.

Specified by:
setPenColor in interface ZPenColor
Parameters:
color - the pen color, or null if none.

getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the current background color.


setBackgroundColor

public void setBackgroundColor(java.awt.Color color)
Sets the current background color.


getFont

public java.awt.Font getFont()
Returns the current font.


getText

public java.lang.String getText()
Return the text within this label component.


setFont

public void setFont(java.awt.Font aFont)
Sets the font for the text.

Warning: Java has a serious bug in that it does not support very small fonts. In particular, fonts that are less than about a pixel high just don't work. Since in Jazz, it is common to create objects of arbitrary sizes, and then scale them, an application can easily create a text object with a very small font by accident. The workaround for this bug is to create a larger font for the text object, and then scale the node down correspondingly.


setText

public void setText(java.lang.String str)
Sets the text of this visual component to str.


setTranslateX

public void setTranslateX(double x)
Set label translation offset X.

Parameters:
x - the X translation.

getTranslateX

public double getTranslateX()
Get the X offset translation.

Returns:
the X translation.

setTranslateY

public void setTranslateY(double y)
Set label translation offset Y.

Parameters:
y - the Y translation.

getTranslateY

public double getTranslateY()
Get the Y offset translation.

Returns:
the Y translation.

setTranslation

public void setTranslation(double x,
                           double y)
Set the label translation offset to the specified position.

Parameters:
x - the X-coord of translation
y - the Y-coord of translation

setTranslation

public void setTranslation(java.awt.geom.Point2D p)
Set the label translation offset to point p.

Parameters:
p - The translation offset.

getTranslation

public java.awt.geom.Point2D getTranslation()
Get the text translation offset.

Returns:
The translation offset.

render

public void render(ZRenderContext renderContext)
Renders the label object

The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Jazz. This object should set those things if they are used, but they do not need to be restored.

Overrides:
render in class ZVisualComponent
Parameters:
renderContext - The graphics context to use for rendering.
See Also:
ZVisualComponent.paint(Graphics2D)

computeBounds

protected void computeBounds()
Notifies this object that it has changed and that it should update its notion of its bounding box.

Overrides:
computeBounds in class ZSceneGraphObject

setState

public void setState(java.lang.String fieldType,
                     java.lang.String fieldName,
                     java.lang.Object fieldValue)
Set some state of this object as it gets read back in. After the object is created with its default no-arg constructor, this method will be called on the object once for each bit of state that was written out through calls to ZObjectOutputStream.writeState() within the writeObject method.

Specified by:
setState in interface ZSerializable
Overrides:
setState in class ZVisualComponent
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.

Specified by:
writeObject in interface ZSerializable
Overrides:
writeObject in class ZVisualComponent
Parameters:
out - The stream that this object writes into
java.io.IOException


Copyright � 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.