|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.umd.cs.jazz.ZSceneGraphObject | +--edu.umd.cs.jazz.ZVisualComponent | +--edu.umd.cs.jazz.component.ZText
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. The text object is positioned so that its upper-left corner is at the origin, though this can be changed with the translate 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.
Field Summary | |
protected java.awt.Color |
backgroundColor
Background color for text. |
protected boolean |
boundsBug
jdk version <= 1.2.1 has a bug: font.getStringBounds() gives the bounds of a space " " as zero. |
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 double |
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 double |
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.ArrayList |
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). |
protected double |
translateX
Translation offset X. |
protected double |
translateY
Translation offset Y. |
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject |
bounds, listenerList, volatileBounds, volatileBounds_DEFAULT |
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. |
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. |
protected void |
computeBounds()
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. |
protected java.lang.Object |
duplicateObject()
Returns a clone of this object. |
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. |
double |
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. |
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 |
keyPressed(java.awt.event.KeyEvent e)
Processes keyboard events. |
void |
paintAsGreek(ZRenderContext renderContext)
Paints this object as greek. |
void |
paintAsText(ZRenderContext renderContext)
Paints this object normally (show it's text). |
void |
render(ZRenderContext renderContext)
Renders the text object |
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(double 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 |
setTranslateX(double x)
Set text translation offset X. |
void |
setTranslateY(double y)
Set text translation offset Y. |
void |
setTranslation(double x,
double y)
Set the text translation offset to the specified position. |
void |
setTranslation(java.awt.geom.Point2D p)
Set the text 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, updateParentBounds, updateVolatility, writeObjectRecurse |
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject |
addMouseListener, addMouseMotionListener, clone, dump, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getListenerList, getVolatileBounds, hasLisenerOfType, hasMouseListener, processMouseEvent, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.awt.font.FontRenderContext LOW_QUALITY_FONT_CONTEXT
protected static final java.awt.font.FontRenderContext HIGH_QUALITY_FONT_CONTEXT
protected static final double DEFAULT_GREEK_THRESHOLD
protected static final java.awt.Color DEFAULT_GREEK_COLOR
protected static final java.lang.String DEFAULT_FONT_NAME
protected static final int DEFAULT_FONT_STYLE
protected static final int DEFAULT_FONT_SIZE
protected static final java.awt.Font DEFAULT_FONT
protected static final java.awt.Color DEFAULT_PEN_COLOR
protected static final java.awt.Color DEFAULT_BACKGROUND_COLOR
protected static final java.awt.Color DEFAULT_CARET_COLOR
protected static final boolean DEFAULT_EDITABLE
protected static final java.lang.String DEFAULT_TEXT
protected double greekThreshold
protected java.awt.Color greekColor
protected java.awt.Color penColor
protected java.awt.Color backgroundColor
protected java.awt.Color caretColor
protected int caretPos
protected int caretLine
protected double caretX
protected double caretY
protected transient java.awt.geom.Line2D caretShape
protected java.awt.Font font
protected java.util.ArrayList lines
protected boolean editable
protected transient java.awt.font.FontRenderContext prevFRC
protected boolean boundsBug
protected double translateX
protected double translateY
Constructor Detail |
public ZText()
public ZText(java.lang.String str)
str
- The initial text.public ZText(java.lang.String str, java.awt.Font font)
str
- The initial text.font
- The font for this ZText component.Method Detail |
protected java.lang.Object duplicateObject()
duplicateObject
in class ZVisualComponent
ZSceneGraphObject.duplicateObject()
public java.awt.Color getPenColor()
getPenColor
in interface ZPenColor
edu.umd.cs.jazz.component.ZPenColor
public void setPenColor(java.awt.Color color)
setPenColor
in interface ZPenColor
color
- use this color.public java.awt.Color getBackgroundColor()
public void setBackgroundColor(java.awt.Color color)
color
- use this color.public java.awt.Color getCaretColor()
public void setCaretColor(java.awt.Color color)
color
- use this color.public double getGreekThreshold()
public void setGreekThreshold(double threshold)
threshold
- compared to renderContext magnification.public boolean getEditable()
public void setEditable(boolean editable)
editable
- true or false.public java.awt.Font getFont()
public java.lang.String getText()
public int getCaretPos()
public int getCaretLine()
public void setFont(java.awt.Font aFont)
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.
aFont
- use this font.public void setText(java.lang.String str)
str
- use this string.public void addChar(char c)
c
Character
- to add.public void addEnterChar()
public void deleteChar()
public void deleteCharBeforeCaret()
public void deleteToEndOfLine()
public void setCaretLine(int line)
line
Line
- number to use. Count starts
with zero.public void setCaretPos(int cp)
cp
Character
- position to use, starts with zero.public void setCaretPos(java.awt.geom.Point2D pt)
pt
- object coordinates of a mouse click.public void setTranslateX(double x)
x
- the X translation.public double getTranslateX()
public void setTranslateY(double y)
y
- the Y translation.public double getTranslateY()
public void setTranslation(double x, double y)
x
- the X-coord of translationy
- the Y-coord of translationpublic void setTranslation(java.awt.geom.Point2D p)
p
- The translation offset.public java.awt.geom.Point2D getTranslation()
public void keyPressed(java.awt.event.KeyEvent e)
e
- keyboard event object.public void render(ZRenderContext renderContext)
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.
render
in class ZVisualComponent
renderContext
- Contains information about current render.public void paintAsGreek(ZRenderContext renderContext)
renderContext
- The graphics context to paint into.public void paintAsText(ZRenderContext renderContext)
renderContext
- The graphics context to paint into.protected void computeBounds()
computeBounds
in class ZSceneGraphObject
public void setState(java.lang.String fieldType, java.lang.String fieldName, java.lang.Object fieldValue)
setState
in class ZVisualComponent
fieldType
- The fully qualified type of the fieldfieldName
- The name of the fieldfieldValue
- The value of the fieldpublic void writeObject(ZObjectOutputStream out) throws java.io.IOException
writeObject
in class ZVisualComponent
out
- The stream that this object writes into
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |