edu.umd.cs.jazz.component
Class ZText

java.lang.Object
  |
  +--edu.umd.cs.jazz.scenegraph.ZVisualComponent
        |
        +--edu.umd.cs.jazz.component.ZText

public class ZText
extends ZVisualComponent

ZText creates a visual component to support text. Multiple lines can be entered, and basic editing is supported. A caret is drawn, and can be repositioned with mouse clicks.


Field Summary
protected  java.awt.Color backgroundColor
          Background color for text.
protected  java.awt.Color caretColor
          Current caret color.
protected  int caretLine
          Line number of caret - current line.
protected  int caretPos
          Character position of caret within the current line.
protected  java.awt.geom.Line2D caretShape
          Drawn shape of the caret.
protected  double caretX
          X coordinate of caret relative to its coordinate frame.
protected  double caretY
          Y coordinate of caret relative to its coordinate frame.
protected static java.awt.Color DEFAULT_BACKGROUND_COLOR
          Default background color for text.
protected static java.awt.Color DEFAULT_CARET_COLOR
          Default caret color for text.
protected static boolean DEFAULT_EDITABLE
          Default specifying if text is editable.
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_GREEK_COLOR
          Default color of text rendered as 'greek'.
protected static float DEFAULT_GREEK_THRESHOLD
          Below this magnification render text as 'greek'.
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  boolean editable
          Specifies if text is editable.
protected  java.awt.Font font
          Current text font.
protected  java.awt.Color greekColor
          Color for greek text.
protected  float greekThreshold
          Below this magnification text is rendered as greek.
protected static java.awt.font.FontRenderContext HIGH_QUALITY_FONT_CONTEXT
          The high quality graphic2D render context: AntiAliased, and uses FractionalMetrics.
protected  java.util.Vector lines
          Each vector element is 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  java.awt.font.FontRenderContext prevFRC
          The previously used font render context (i.e., from the last render).
 
Fields inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
cacheVolatile, findable, findable_DEFAULT, isVolatile, localBounds, localBoundsDirty, parent, pickable, pickable_DEFAULT, selected
 
Constructor Summary
ZText()
          Default constructor for ZText.
ZText(java.lang.String str)
          ZText constructor with initial text.
ZText(java.lang.String str, java.awt.Font font)
          ZText constructor with initial text and font.
ZText(ZText tf)
          Constructs a new ZText that is a copy of the specified component (i.e., a "copy constructor").
 
Method Summary
 void addChar(char c)
          Adds a character before the caret position.
 void addEnterChar()
          Creates a new line of text, splitting the current line at the caret position.
 java.lang.Object clone()
          Duplicates the current ZTextField by using the copy constructor.
protected  void computeLocalBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
 void deleteChar()
          Deletes the character after the caret position.
 void deleteCharBeforeCaret()
          Deletes the character before the caret position.
 void deleteToEndOfLine()
          Deletes from the caret position to the end of line.
 java.awt.Color getBackgroundColor()
          Returns the current background color.
 java.awt.Color getCaretColor()
          Returns the current caret color.
 int getCaretLine()
          Returns the current line.
 int getCaretPos()
          Returns the character position of the caret, within the current line.
 boolean getEditable()
          Determines if this text is editable.
 java.awt.Font getFont()
          Returns the current font.
 float getGreekThreshold()
          Returns the current greek threshold.
 java.awt.Color getPenColor()
          Returns the current pen color.
 java.lang.String getText()
          Return the text within this text component.
 void keyPressed(java.awt.event.KeyEvent e)
          Processes keyboard events.
 void paint(ZRenderContext renderContext)
          Determines if the text should be rendered as text or greek.
 void paintAsGreek(ZRenderContext renderContext)
          Paints this object as greek.
 void paintAsText(ZRenderContext renderContext)
          Paints this object normally (show it's text).
 void setBackgroundColor(java.awt.Color color)
          Sets the current background color.
 void setCaretColor(java.awt.Color color)
          Sets the current caret color.
 void setCaretLine(int line)
          Sets the caretLine to line, if it exists.
 void setCaretPos(int cp)
          Set the caret this character position in the current line.
 void setCaretPos(java.awt.geom.Point2D pt)
          Set caret position to character closest to specified point (in object coords)
 void setEditable(boolean editable)
          Specifies whether this text is editable.
 void setFont(java.awt.Font aFont)
          Sets the font for the text.
 void setGreekThreshold(float threshold)
          Sets the current greek threshold.
 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 writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 
Methods inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
damage, damage, findNode, findVisualComponent, getLocalBounds, getParent, isFindable, isPickable, isSelected, isVolatile, pick, pickBounds, select, select, setFindable, setParent, setPickable, setSelected, setVisualComponent, setVolatile, toString, unselect, updateBounds, updateChildBounds, updateLocalBounds, updateVolatility, writeObjectRecurse
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, 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_GREEK_THRESHOLD

protected static final float DEFAULT_GREEK_THRESHOLD
Below this magnification render text as 'greek'.

DEFAULT_GREEK_COLOR

protected static final java.awt.Color DEFAULT_GREEK_COLOR
Default color of text rendered as 'greek'.

DEFAULT_FONT_NAME

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

DEFAULT_FONT_STYLE

protected static final int DEFAULT_FONT_STYLE
Default font style for text.

DEFAULT_FONT_SIZE

protected static final int DEFAULT_FONT_SIZE
Default font size for text.

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 text.

DEFAULT_CARET_COLOR

protected static final java.awt.Color DEFAULT_CARET_COLOR
Default caret color for text.

DEFAULT_EDITABLE

protected static final boolean DEFAULT_EDITABLE
Default specifying if text is editable.

DEFAULT_TEXT

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

greekThreshold

protected float greekThreshold
Below this magnification text is rendered as greek.

greekColor

protected java.awt.Color greekColor
Color for greek text.

penColor

protected java.awt.Color penColor
Current pen color.

backgroundColor

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

caretColor

protected java.awt.Color caretColor
Current caret color.

caretPos

protected int caretPos
Character position of caret within the current line.

caretLine

protected int caretLine
Line number of caret - current line.

caretX

protected double caretX
X coordinate of caret relative to its coordinate frame.

caretY

protected double caretY
Y coordinate of caret relative to its coordinate frame.

caretShape

protected java.awt.geom.Line2D caretShape
Drawn shape of the caret.

font

protected java.awt.Font font
Current text font.

lines

protected java.util.Vector lines
Each vector element is one line of text.

editable

protected boolean editable
Specifies if text is editable.

prevFRC

protected java.awt.font.FontRenderContext prevFRC
The previously used font render context (i.e., from the last render).
Constructor Detail

ZText

public ZText()
Default constructor for ZText.

ZText

public ZText(java.lang.String str)
ZText constructor with initial text.
Parameters:
str - The initial text.

ZText

public ZText(java.lang.String str,
             java.awt.Font font)
ZText constructor with initial text and font.
Parameters:
str - The initial text.
font - The font for this ZText component.

ZText

public ZText(ZText tf)
Constructs a new ZText that is a copy of the specified component (i.e., a "copy constructor").
Parameters:
tf - The ZText object to make a deep copy of.
Method Detail

clone

public java.lang.Object clone()
Duplicates the current ZTextField by using the copy constructor. See the copy constructor comments for complete information about what is duplicated.
Overrides:
clone in class ZVisualComponent
See Also:
ZText(ZText)

getPenColor

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

setPenColor

public void setPenColor(java.awt.Color color)
Sets the current pen color.
Parameters:
color - use this color.

getBackgroundColor

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

setBackgroundColor

public void setBackgroundColor(java.awt.Color color)
Sets the current background color.
Parameters:
color - use this color.

getCaretColor

public java.awt.Color getCaretColor()
Returns the current caret color.

setCaretColor

public void setCaretColor(java.awt.Color color)
Sets the current caret color.
Parameters:
color - use this color.

getGreekThreshold

public float getGreekThreshold()
Returns the current greek threshold. Below this magnification text is rendered as 'greek'

setGreekThreshold

public void setGreekThreshold(float threshold)
Sets the current greek threshold. Below this magnification text is rendered as 'greek'
Parameters:
threshold - compared to renderContext magnification.

getEditable

public boolean getEditable()
Determines if this text is editable.

setEditable

public void setEditable(boolean editable)
Specifies whether this text is editable.
Parameters:
editable - true or false.

getFont

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

getText

public java.lang.String getText()
Return the text within this text component. Multline text is returned as a single string where each line is separated by a newline character. Single line text does not have any newline characters.

getCaretPos

public int getCaretPos()
Returns the character position of the caret, within the current line.

getCaretLine

public int getCaretLine()
Returns the current line.

setFont

public void setFont(java.awt.Font aFont)
Sets the font for the text.
Parameters:
aFont - use this font.

setText

public void setText(java.lang.String str)
Sets the text of this visual component to str. Multiple lines of text are separated by a newline character.
Parameters:
str - use this string.

addChar

public void addChar(char c)
Adds a character before the caret position.
Parameters:
cCharacter - to add.

addEnterChar

public void addEnterChar()
Creates a new line of text, splitting the current line at the caret position.

deleteChar

public void deleteChar()
Deletes the character after the caret position.

deleteCharBeforeCaret

public void deleteCharBeforeCaret()
Deletes the character before the caret position.

deleteToEndOfLine

public void deleteToEndOfLine()
Deletes from the caret position to the end of line. If caret is at the end of the line, joins current line to the next.

setCaretLine

public void setCaretLine(int line)
Sets the caretLine to line, if it exists.
Parameters:
lineLine - number to use. Count starts with zero.

setCaretPos

public void setCaretPos(int cp)
Set the caret this character position in the current line.
Parameters:
cpCharacter - position to use, starts with zero.

setCaretPos

public void setCaretPos(java.awt.geom.Point2D pt)
Set caret position to character closest to specified point (in object coords)
Parameters:
pt - object coordinates of a mouse click.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Processes keyboard events. Implements basic text editing and cursor movement.
Parameters:
e - keyboard event object.

paint

public void paint(ZRenderContext renderContext)
Determines if the text should be rendered as text or greek.
Parameters:
renderContext - Contains information about current render.
Overrides:
paint in class ZVisualComponent

paintAsGreek

public void paintAsGreek(ZRenderContext renderContext)
Paints this object as greek.
Parameters:
g2 - The graphics context to paint into.

paintAsText

public void paintAsText(ZRenderContext renderContext)
Paints this object normally (show it's text). Note that the entire text gets rendered so that it's upper left corner appears at the origin of this local object.
Parameters:
g2 - The graphics context to paint into.

computeLocalBounds

protected void computeLocalBounds()
Notifies this object that it has changed and that it should update its notion of its bounding box.
Overrides:
computeLocalBounds in class ZVisualComponent

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.
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field
Overrides:
setState in class ZVisualComponent

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.
Parameters:
out - The stream that this object writes into
Overrides:
writeObject in class ZVisualComponent