edu.umd.cs.piccolox.swt
Class PSWTText

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolox.swt.PSWTText
All Implemented Interfaces:
java.awt.print.Printable, java.io.Serializable, java.lang.Cloneable

public class PSWTText
extends PNode

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

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
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 int DEFAULT_PADDING
          Default padding
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  java.awt.Color greekColor
          Color for greek text.
protected  double greekThreshold
          Below this magnification text is rendered as greek.
protected  java.util.ArrayList lines
          Each vector element is one line of text.
protected  int padding
          The amount of padding on each side of the text
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.piccolo.PNode
PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_CODE_BOUNDS, PROPERTY_CODE_CHILDREN, PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CODE_FULL_BOUNDS, PROPERTY_CODE_PAINT, PROPERTY_CODE_PARENT, PROPERTY_CODE_PICKABLE, PROPERTY_CODE_TRANSFORM, PROPERTY_CODE_TRANSPARENCY, PROPERTY_CODE_VISIBLE, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE, SCENE_GRAPH_DELEGATE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PSWTText()
          Default constructor for PSWTTest.
PSWTText(java.lang.String str)
          PSWTTest constructor with initial text.
PSWTText(java.lang.String str, java.awt.Font font)
          PSWTTest constructor with initial text and font.
 
Method Summary
 java.awt.Color getBackgroundColor()
          Returns the current background color.
 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.awt.Paint getPenPaint()
          Returns the current pen paint.
 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.
protected  void internalUpdateBounds(double x, double y, double width, double height)
          Gives nodes a chance to update their internal structure before bounds changed notifications are sent.
 void paint(PPaintContext ppc)
          Renders the text object.
 void paintAsGreek(PPaintContext ppc)
          Paints this object as greek.
 void paintAsText(PPaintContext ppc)
          Paints this object normally (show it's text).
protected  void recomputeBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
 void setBackgroundColor(java.awt.Color color)
          Sets the current background color.
 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 setPenPaint(java.awt.Paint aPaint)
          Sets the current pen paint.
 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.
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToTransform, animateToTransparency, animateTransformToBounds, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, endResizeBounds, findIntersectingNodes, fireChildPropertyChange, firePropertyChange, fullIntersects, fullPaint, fullPick, getAllNodes, getAllNodes, getAttribute, getAttribute, getBooleanAttribute, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperties, getClientProperty, getClientPropertyKeysEnumeration, getClientPropertyKeysIterator, getDoubleAttribute, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getPropertyChangeParentMask, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, intersects, invalidateFullBounds, invalidateLayout, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paintAfterChildren, paramString, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, pickAfterChildren, position, print, print, removeAllChildren, removeChild, removeChild, removeChildren, removeFromParent, removeInputEventListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaintFrom, reparent, replaceWith, resetBounds, rotate, rotateAboutPoint, rotateAboutPoint, rotateInPlace, scale, scaleAboutPoint, scaleAboutPoint, setBounds, setBounds, setBoundsChanged, setChildBoundsInvalid, setChildBoundsVolatile, setChildPaintInvalid, setChildrenPickable, setFullBoundsInvalid, setGlobalRotation, setGlobalScale, setGlobalTranslation, setHeight, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toString, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_GREEK_THRESHOLD

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

See Also:
Constant Field Values

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.

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_TEXT

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

See Also:
Constant Field Values

DEFAULT_PADDING

protected static final int DEFAULT_PADDING
Default padding

See Also:
Constant Field Values

greekThreshold

protected double 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.


font

protected java.awt.Font font
Current text font.


padding

protected int padding
The amount of padding on each side of the text


lines

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


translateX

protected double translateX
Translation offset X.


translateY

protected double translateY
Translation offset Y.

Constructor Detail

PSWTText

public PSWTText()
Default constructor for PSWTTest.


PSWTText

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

Parameters:
str - The initial text.

PSWTText

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

Parameters:
str - The initial text.
font - The font for this PSWTText component.
Method Detail

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.

getPenPaint

public java.awt.Paint getPenPaint()
Returns the current pen paint.


setPenPaint

public void setPenPaint(java.awt.Paint aPaint)
Sets the current pen paint.

Parameters:
aPaint - use this paint.

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.

getGreekThreshold

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


setGreekThreshold

public void setGreekThreshold(double threshold)
Sets the current greek threshold. Below this magnification text is rendered as 'greek'.

Parameters:
threshold - compared to renderContext magnification.

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.


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.

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.

setTranslateX

public void setTranslateX(double x)
Set text 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 text 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 text 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 text 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.

paint

public void paint(PPaintContext ppc)
Renders the text 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:
paint in class PNode
Parameters:
ppc - Contains information about current render.

paintAsGreek

public void paintAsGreek(PPaintContext ppc)
Paints this object as greek.

Parameters:
ppc - The graphics context to paint into.

paintAsText

public void paintAsText(PPaintContext ppc)
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:
ppc - The graphics context to paint into.

recomputeBounds

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


internalUpdateBounds

protected void internalUpdateBounds(double x,
                                    double y,
                                    double width,
                                    double height)
Description copied from class: PNode
Gives nodes a chance to update their internal structure before bounds changed notifications are sent. When this message is recived the nodes bounds field will contain the new value. See PPath for an example that uses this method.

Overrides:
internalUpdateBounds in class PNode


Copyright © 2008 by University of Maryland, College Park, MD 20742, USA All rights reserved.