com.nwoods.jgo
Class JGoText

java.lang.Object
  extended bycom.nwoods.jgo.JGoObject
      extended bycom.nwoods.jgo.JGoText
All Implemented Interfaces:
JGoXMLSaveRestore, java.io.Serializable
Direct Known Subclasses:
JGoLinkLabel

public class JGoText
extends JGoObject

JGoText displays a text string.

There are various properties to control the appearance of the text: FaceName, Size, Alignment, TextColor, BkColor, Transparent, Bold, Underline, StrikeThrough, Italic, Multiline, and Clipping.

There are also some properties that control the behavior: Editable, EditOnSingleClick, AutoResize, SelectBackground, and 2DScale.

The FaceName and Size properties control the font used to display the text. You can set these dynamically or in some of the constructors. For the other constructors, the default values for these properties is provided by the static methods getDefaultFontFaceName() and getDefaultFontSize().

The Alignment property governs whether the text is positioned on the left side, on the right side, or in the center of the bounding rectangle. For multiline text strings, this property applies to each line.

The TextColor and BkColor properties control the color of the glyphs and the color of the background. These default to black and white, respectively. If the Transparent property is true, the BkColor is not used because the background is not filled in at all. The default value for Transparent is false.

The Bold, Underline, Italic, and StrikeThrough properties are false, by default.

The Multiline property controls whether the text will be displayed in just one line or with potentially multiple lines. When the user edits a single line text string, the ENTER key finishes editing the value, whereas for Multiline objects it would just insert a newline into the string.

If this object is Editable, then clicking (or double-clicking, depending on the EditOnSingleClick property) will put the view in edit-text-in-place mode. It will create a JGoTextEdit in the view at the same position as the JGoText, and it will activate the JGoTextEdit so that an SWT Text Control is visible and has focus. User editing on single click only works when both the Editable and EditOnSingleClick properties are true, along with the Selectable property, because of the otherwise ambiguous nature of a single click.

The sizing of the JGoText instance, if not explicitly set by calling setBoundingRect() or setSize() or setHeight() or the like, is continually determined by the text string and the font size and other attributes, if isAutoResize() is true.

If the JGoText object is not Resizable, the text is not rescaled (by changing the point size) when the height (or width) of the text is changed. JGoText objects are not Resizable by default.

The SelectBackground property, when true, assumes the text's background is normally transparent. If the text is not resizable, we manifest the selection by making the text background opaque. When selection is lost, the background is made transparent again.

The Clipping property controls whether the text drawing is clipped by the bounding rectangle. This is normally useful only when Resizable is false, because then the text font size is not automatically changed to fit the line height. The default value is false, which permits faster display than when Clipping is turned on.

The AutoResize property controls whether to reset the bounding rectangle whenever the text object changes, such as a change to the text string, or to the font or size.

There is support for greeking, to speed up text object painting at small view scales. The paintGreek method is called by the paint method, and gets the opportunity to change the rendering method used depending on the view's scale. Two new static properties have been added to control the default greeking behavior.

We have added support for automatically wrapping text when the text is longer than the WrappingWidth property. Wrapping only occurs when isWrapping() and isMultiline() are both true.

See Also:
JGoTextEdit, Serialized Form

Field Summary
static int ALIGN_CENTER
          Align the text at the center
static int ALIGN_LEFT
          Align the text at the left side
static int ALIGN_RIGHT
          Align the text at the right side.
static int Changed2DScale
          a CHANGED event hint: changed whether the horizontal size can be used to control the resize
static int ChangedAlignment
          a CHANGED event hint: the alignment has changed
static int ChangedAutoResize
          a CHANGED event hint: changed whether it automatically resizes itself
static int ChangedBetterPainting
          a CHANGED event hint: changed whether the text should be drawn more carefully and accurately
static int ChangedBkColor
          a CHANGED event hint: the text background color has changed
static int ChangedBold
          a CHANGED event hint: the boldness has changed
static int ChangedClipping
          a CHANGED event hint: changed whether text is clipped by the bounding rectangle
static int ChangedEditable
          a CHANGED event hint: changed the user-editability of the text
static int ChangedEditOnSingleClick
          a CHANGED event hint: if editable, changed whether the text starts edit mode on a single or a double click
static int ChangedFaceName
          a CHANGED event hint: the font face name has changed
static int ChangedFontSize
          a CHANGED event hint: the font size has changed
static int ChangedItalic
          a CHANGED event hint: the italicization has changed
static int ChangedMultiline
          a CHANGED event hint: changed whether the text is only a single line or multiple lines
static int ChangedSelectBackground
          a CHANGED event hint: if editable, changed whether selection is shown using the text's transparency and background
static int ChangedStrikeThrough
          a CHANGED event hint: changed whether text is shown with a strike-through
static int ChangedText
          a CHANGED event hint: the text string has changed
static int ChangedTextColor
          a CHANGED event hint: the text color has changed
static int ChangedTransparent
          a CHANGED event hint: the transparency has changed
static int ChangedUnderline
          a CHANGED event hint: the underlinedness has changed
static int ChangedWrapping
          a CHANGED event hint: changed whether text is wrapped inside the bounding rectangle
static int ChangedWrappingWidth
          a CHANGED event hint: the wrapping width has changed
 
Fields inherited from class com.nwoods.jgo.JGoObject
Bottom, BottomCenter, BottomLeft, BottomMiddle, BottomRight, Center, CenterLeft, CenterRight, Changed4ResizeHandles, ChangedAutoRescale, ChangedBrush, ChangedDraggable, ChangedDragsNode, ChangedGeometry, ChangedGrabChildSelection, ChangedInitializing, ChangedPen, ChangedResizable, ChangedSelectable, ChangedUpdatePartner, ChangedVisible, ChangedZOrder, LastChangedHint, Left, LeftCenter, NoHandle, NoSpot, NumReservedHandles, RepaintAll, Right, RightCenter, SideLeft, SideRight, Top, TopCenter, TopLeft, TopMiddle, TopRight
 
Constructor Summary
JGoText()
          Create a text object with no text and no size.
JGoText(org.eclipse.swt.graphics.Point location, int fontSize, java.lang.String text, java.lang.String fontName, boolean bold, boolean underline, boolean italic, int alignment, boolean multiline, boolean editable)
          Create a text object with the given attributes.
JGoText(org.eclipse.swt.graphics.Point location, java.lang.String text)
          Create a left-aligned text object given an initial string value whose top-left point is the given location.
JGoText(java.lang.String text)
          Create a text object given an initial string value.
 
Method Summary
 void changeValue(JGoDocumentChangedEdit e, boolean undo)
          This method is called by the JGoDocumentChangedEdit.undo and redo methods to actually perform the property value change for a JGoObject.
 java.lang.String computeEdit(java.lang.String oldtext, java.lang.String newtext)
          Calculate a new string value for this object as a result of an edit.
 void copyNewValueForRedo(JGoDocumentChangedEdit e)
          This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed.
 JGoObject copyObject(JGoCopyEnvironment env)
          Create a new instance of this object with the same field values.
 boolean doEdit(JGoView view, java.lang.String oldtext, java.lang.String newtext)
          Called when a user tries to commit a text edit.
 void doEndEdit()
          Programmatically end the editing of the text for the user.
 boolean doMouseClick(int modifiers, org.eclipse.swt.graphics.Point dc, org.eclipse.swt.graphics.Point vc, JGoView view)
          The default behavior on single click is to start editing in-place if the document isModifiable is true, if isEditable is true, and if isEditOnSingleClick is true.
 boolean doMouseDblClick(int modifiers, org.eclipse.swt.graphics.Point dc, org.eclipse.swt.graphics.Point vc, JGoView view)
          The default behavior on double click is to start editing in-place if the document isModifiable is true, if isEditable is true, and if isEditOnSingleClick is false.
 void doStartEdit(JGoView view, org.eclipse.swt.graphics.Point vc)
          Programmatically start the editing of the text for the user.
 void expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
          Account for any likely text drawn beyond the bounding rectangle because of nonlinear text scaling
protected  void gainedSelection(JGoSelection selection)
          JGoText has different handles than most objects because the resizing is only supposed to depend on the height.
protected  void geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
          Called when the geometry of the text bounding box is changed.
 int getAlignment()
          Return how multiple lines will be aligned.
 org.eclipse.swt.graphics.RGB getBkColor()
          Return the color of the background behind the text.
static java.lang.String getDefaultFontFaceName()
          Return the default font face name for JGoText constructors that do not take an explicit font face name argument.
static int getDefaultFontSize()
          Return the default font size for JGoText constructors that do not take an explicit font size argument.
static double getDefaultPaintGreekScale()
          Return the view scale at which this text object should paint something simpler than real text.
static double getDefaultPaintNothingScale()
          Return the view scale at which a text object should not paint anything.
static int getDefaultWrappingWidth()
          Return the default wrapping width for JGoText constructors.
 java.lang.String getFaceName()
          Return the font face.
 int getFontSize()
          Return how big the font is.
 org.eclipse.swt.graphics.Point getLocation(org.eclipse.swt.graphics.Point result)
          Returns the TopLeft, TopMiddle or TopRight point, depending on the text alignment attribute
 java.lang.String getText()
          Return the text that is currently being displayed.
 org.eclipse.swt.graphics.RGB getTextColor()
          Return the color of the text.
 int getTextFlags()
          Return the current state of this JGoText object's flags.
 int getWrappingWidth()
          Return the maximum width for wrapped text.
 org.eclipse.swt.graphics.Rectangle handleResize(Graphics2D g, JGoView view, org.eclipse.swt.graphics.Rectangle prevRect, org.eclipse.swt.graphics.Point newPoint, int whichHandle, int event, int minWidth, int minHeight)
          If this JGoText object is resizable and if the font size is only dependent on the height of the bounding rectangle, we need to recalculate based on new height and whether there are multiple lines of text.
 boolean is2DScale()
          Return whether resizing text heeds both dimensions, rather than just the height.
 boolean isAutoResize()
          Return whether text's bounding rectangle is recomputed whenever the text string or any of the other visual attributes is changed.
 boolean isBetterPainting()
          Return whether text is drawn more carefully.
 boolean isBold()
          Return whether the text is bold.
 boolean isClipping()
          Return whether text display is limited to the bounding rectangle.
static boolean isDefaultBetterPainting()
          Return the default setting for JGoText's BetterPainting property.
 boolean isEditable()
          Return whether the text is editable by the end user.
 boolean isEditOnSingleClick()
          Return whether a user's single click starts editing the text, assuming the text is editable at all.
 boolean isItalic()
          Return whether the text is italic.
 boolean isMultiline()
          Return whether the text can be shown on multiple lines.
 boolean isSelectBackground()
          Return whether gainedSelection() uses the text's background color and the text's transparency to display the selection.
 boolean isStrikeThrough()
          Return whether the text is shown with a strike-through.
 boolean isTransparent()
          Return whether the text is transparent.
 boolean isUnderline()
          Return whether the text is underlined.
 boolean isWrapping()
          Return whether text is automatically wrapped to try to fit in the wrapping width.
protected  void lostSelection(JGoSelection selection)
          If isSelectBackground() is true, we assume the text is normally transparent, and that the background color will be the selection or highlight color.
 void paint(Graphics2D g, JGoView view)
          Called to draw the text on the screen.
 boolean paintGreek(Graphics2D g, JGoView view)
          This method is called by paint to allow optimizing drawing a lot of objects at small scales.
 void set2DScale(boolean bFlag)
          Change whether the resizing the text depends on both the width and the height, rather than just the height to determine the font size to use in displaying the string.
 void setAlignment(int align)
          Set how multiple lines are aligned.
 void setAutoResize(boolean bFlag)
          Control whether the bounding rectangle is changed whenever the text string or other visual attributes are changed.
 void setBetterPainting(boolean bFlag)
          Control whether text is drawn slower and more carefully.
 void setBkColor(org.eclipse.swt.graphics.RGB color)
          Set the color of the background behind the text.
 void setBold(boolean bFlag)
          Change the boldness of the text.
 void setClipping(boolean bFlag)
          Change whether the text is only drawn within the bounding rectangle.
static void setDefaultBetterPainting(boolean b)
          Change the default setting for the BetterPainting property for each new JGoText object.
static void setDefaultFontFaceName(java.lang.String name)
          Change the default font face to be used by JGoText constructors that do not take an explicit font face name argument.
static void setDefaultFontSize(int size)
          Change the default font size to be used by JGoText constructors that do not take an explicit font size argument.
static void setDefaultPaintGreekScale(double s)
          Change the scale at which text will paint very simply.
static void setDefaultPaintNothingScale(double s)
          Change the scale at which text will not paint.
static void setDefaultWrappingWidth(int w)
          Change the default text wrapping width to be used by JGoText constructors.
 void setEditable(boolean bFlag)
          Change whether the text is editable by the end user.
 void setEditOnSingleClick(boolean bFlag)
          If the text is editable, control whether the user can start editing with a double click or with a single click.
 void setFaceName(java.lang.String name)
          Sets the font face.
 void setFontSize(int size)
          Sets the font size to the size specified.
 void setItalic(boolean bFlag)
          Change whether the text is italic.
 void setLocation(int x, int y)
          Sets a new position for the TopLeft, TopMiddle or TopRight point.
 void setMultiline(boolean bFlag)
          Change whether the text is limited to a single line or may have multiple lines.
 void setSelectBackground(boolean bFlag)
          If the text background is transparent and the text is not resizable, control whether gainedSelection() makes the background opaque and whether lostSelection() makes the background transparent again.
 void setSizeKeepingLocation(int w, int h)
          Sets a new size for this object while maintaining the same Location.
 void setStrikeThrough(boolean bFlag)
          Change whether the text is shown with a strike-through.
 void setText(java.lang.String str)
          Set the text to be displayed.
 void setTextColor(org.eclipse.swt.graphics.RGB color)
          Set the color of the text.
 void setTextFlags(int f)
          Each JGoText keeps a set of flags for programmatic use by classes outside of the JGo package.
 void setTransparent(boolean bFlag)
          Set whether or not the text background is filled with the background color before drawing the text (opaque), or if only the text is drawn without hiding what's underneath the text (transparent).
 void setUnderline(boolean bFlag)
          Change whether the text is underlined.
 void setWrapping(boolean bFlag)
          Change whether longer text is broken into multiple lines to fit in the defined wrapping width of this object.
 void setWrappingWidth(int w)
          Change the width at which text will wrap, if isMultiline() and isWrapping() are true.
 void SVGReadAttributes(DomElement svgElement)
          This method will read attributes from standard SVG elements.
 DomNode SVGReadObject(DomDoc svgDoc, JGoDocument jGoDoc, DomElement svgElement, DomElement jGoChildElement)
          Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 void SVGWriteAttributes(DomElement svgElement)
          This method will add attributes to standard SVG elements.
 void SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)
          Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 
Methods inherited from class com.nwoods.jgo.JGoObject
canView, computeBoundingRect, computeMove, computeResize, copy, copyObjectDelayed, copyOldValueForUndo, copyRect, doUncapturedMouseMove, findCommonParent, foredate, geometryChangeChild, getBoundingRect, getDocument, getDraggingObject, getFlags, getHeight, getLayer, getLeft, getLocation, getNearestIntersectionPoint, getParent, getParentJGoNode, getParentNode, getPartner, getRectangleSpotLocation, getSize, getSize, getSpotLocation, getSpotLocation, getToolTipText, getTop, getTopLeft, getTopLeft, getTopLevelObject, getView, getWidth, growRect, handleMove, hideSelectionHandles, is4ResizeHandles, isAutoRescale, isBoundingRectInvalid, isChildOf, isDraggable, isDragsNode, isInitializing, isPointInObj, isResizable, isSelectable, isSkipsUndoManager, isSuspendUpdates, isTopLevel, isUpdatePartner, isVisible, ownerChange, partnerUpdate, pick, redirectSelection, remove, set4ResizeHandles, setAutoRescale, setBoundingRect, setBoundingRect, setBoundingRect, setBoundingRectInvalid, setBoundsRect, setDraggable, setDragsNode, setFlags, setHeight, setInitializing, setLeft, setLocation, setLocationOffset, setLocationOffset, setParent, setPartner, setRectangleSpotLocation, setResizable, setSelectable, setSize, setSize, setSkipsUndoManager, setSpotLocation, setSpotLocation, setSpotLocation, setSpotLocationOffset, setSuspendUpdates, setTop, setTopLeft, setTopLeft, setUpdatePartner, setVisible, setWidth, showSelectionHandles, spotOpposite, SVGUpdateReference, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIGN_LEFT

public static final int ALIGN_LEFT
Align the text at the left side

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Align the text at the center

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Align the text at the right side.

See Also:
Constant Field Values

ChangedText

public static final int ChangedText
a CHANGED event hint: the text string has changed

See Also:
Constant Field Values

ChangedAlignment

public static final int ChangedAlignment
a CHANGED event hint: the alignment has changed

See Also:
Constant Field Values

ChangedFontSize

public static final int ChangedFontSize
a CHANGED event hint: the font size has changed

See Also:
Constant Field Values

ChangedFaceName

public static final int ChangedFaceName
a CHANGED event hint: the font face name has changed

See Also:
Constant Field Values

ChangedTextColor

public static final int ChangedTextColor
a CHANGED event hint: the text color has changed

See Also:
Constant Field Values

ChangedBkColor

public static final int ChangedBkColor
a CHANGED event hint: the text background color has changed

See Also:
Constant Field Values

ChangedTransparent

public static final int ChangedTransparent
a CHANGED event hint: the transparency has changed

See Also:
Constant Field Values

ChangedBold

public static final int ChangedBold
a CHANGED event hint: the boldness has changed

See Also:
Constant Field Values

ChangedUnderline

public static final int ChangedUnderline
a CHANGED event hint: the underlinedness has changed

See Also:
Constant Field Values

ChangedItalic

public static final int ChangedItalic
a CHANGED event hint: the italicization has changed

See Also:
Constant Field Values

ChangedMultiline

public static final int ChangedMultiline
a CHANGED event hint: changed whether the text is only a single line or multiple lines

See Also:
Constant Field Values

ChangedEditable

public static final int ChangedEditable
a CHANGED event hint: changed the user-editability of the text

See Also:
Constant Field Values

ChangedEditOnSingleClick

public static final int ChangedEditOnSingleClick
a CHANGED event hint: if editable, changed whether the text starts edit mode on a single or a double click

See Also:
Constant Field Values

Changed2DScale

public static final int Changed2DScale
a CHANGED event hint: changed whether the horizontal size can be used to control the resize

See Also:
Constant Field Values

ChangedSelectBackground

public static final int ChangedSelectBackground
a CHANGED event hint: if editable, changed whether selection is shown using the text's transparency and background

See Also:
Constant Field Values

ChangedClipping

public static final int ChangedClipping
a CHANGED event hint: changed whether text is clipped by the bounding rectangle

See Also:
Constant Field Values

ChangedStrikeThrough

public static final int ChangedStrikeThrough
a CHANGED event hint: changed whether text is shown with a strike-through

See Also:
Constant Field Values

ChangedAutoResize

public static final int ChangedAutoResize
a CHANGED event hint: changed whether it automatically resizes itself

See Also:
Constant Field Values

ChangedWrapping

public static final int ChangedWrapping
a CHANGED event hint: changed whether text is wrapped inside the bounding rectangle

See Also:
Constant Field Values

ChangedWrappingWidth

public static final int ChangedWrappingWidth
a CHANGED event hint: the wrapping width has changed

See Also:
Constant Field Values

ChangedBetterPainting

public static final int ChangedBetterPainting
a CHANGED event hint: changed whether the text should be drawn more carefully and accurately

See Also:
Constant Field Values
Constructor Detail

JGoText

public JGoText()
Create a text object with no text and no size.


JGoText

public JGoText(java.lang.String text)
Create a text object given an initial string value.

Parameters:
text - the initial string

JGoText

public JGoText(org.eclipse.swt.graphics.Point location,
               java.lang.String text)
Create a left-aligned text object given an initial string value whose top-left point is the given location. The default font face name and size are used to determine the dimension of the resulting object.

Parameters:
location - the top-left point for the text, in document coordinates
text - the initial string

JGoText

public JGoText(org.eclipse.swt.graphics.Point location,
               int fontSize,
               java.lang.String text,
               java.lang.String fontName,
               boolean bold,
               boolean underline,
               boolean italic,
               int alignment,
               boolean multiline,
               boolean editable)
Create a text object with the given attributes. The bounding box will be set to be the smallest that surrounds the text.

Parameters:
location - the top-left, top-middle, or top-right corner of the text, depending on the alignment
fontSize - the size of the font to use
text - the text to display
fontName - the name of the font face to use
bold - display in bold if true
underline - display underline if true
italic - display in italic if true
alignment - the type of alignment
multiline - display more than one line of text if true
editable - permit in-place editing of text if true
Method Detail

copyObject

public JGoObject copyObject(JGoCopyEnvironment env)
Create a new instance of this object with the same field values.

Overrides:
copyObject in class JGoObject
Parameters:
env - the environment for the copy operation - keeps track of copied objects.
Returns:
a newly allocated copy of this object, or null

setText

public void setText(java.lang.String str)
Set the text to be displayed.

Parameters:
str - the text string to be displayed.

getText

public java.lang.String getText()
Return the text that is currently being displayed.

Returns:
the current text string.

setAlignment

public void setAlignment(int align)
Set how multiple lines are aligned. The following are possible alignment values:

This also controls the natural Location for the text object, even when only a single line.

Parameters:
align - one of the above alignment types

getAlignment

public int getAlignment()
Return how multiple lines will be aligned.

Returns:
how the text is aligned

setFontSize

public void setFontSize(int size)
Sets the font size to the size specified. Calling this method forces the font size to be what is given -- the bounding box will be changed to accomodate the new text.

Parameters:
size - the size to set the font to

getFontSize

public int getFontSize()
Return how big the font is.

Returns:
the size of the font

setFaceName

public void setFaceName(java.lang.String name)
Sets the font face. The face name must be one of the Java-recognized fonts. The bounding box will be changed to accomodate the new text appearance.

Parameters:
name - the name of the font face

getFaceName

public java.lang.String getFaceName()
Return the font face.

Returns:
the font face.

setTextColor

public void setTextColor(org.eclipse.swt.graphics.RGB color)
Set the color of the text.

Parameters:
color - the color of the text

getTextColor

public org.eclipse.swt.graphics.RGB getTextColor()
Return the color of the text.

Returns:
the color of the text

setBkColor

public void setBkColor(org.eclipse.swt.graphics.RGB color)
Set the color of the background behind the text.

Parameters:
color - the color of the background

getBkColor

public org.eclipse.swt.graphics.RGB getBkColor()
Return the color of the background behind the text.

Returns:
the color of the background

setTextFlags

public final void setTextFlags(int f)
Each JGoText keeps a set of flags for programmatic use by classes outside of the JGo package.

Setting the flags does not call update, because the need for update must be determined by the application and the flags being changed.

This property is now exclusively for the use of user-defined extension classes and applications. The flags that had been used by the implementation of JGoText has been moved to a different field. This is also independent of JGoObject's Flags property.

Parameters:
f - a new set of flag bits

getTextFlags

public final int getTextFlags()
Return the current state of this JGoText object's flags. Includes both private and public information.


setTransparent

public void setTransparent(boolean bFlag)
Set whether or not the text background is filled with the background color before drawing the text (opaque), or if only the text is drawn without hiding what's underneath the text (transparent).

Parameters:
bFlag - true if transparent, false if opaque

isTransparent

public boolean isTransparent()
Return whether the text is transparent.


setBold

public void setBold(boolean bFlag)
Change the boldness of the text. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag - true if bold, false if normal

isBold

public boolean isBold()
Return whether the text is bold.


setUnderline

public void setUnderline(boolean bFlag)
Change whether the text is underlined. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag - true if underlined, false if normal

isUnderline

public boolean isUnderline()
Return whether the text is underlined.


setStrikeThrough

public void setStrikeThrough(boolean bFlag)
Change whether the text is shown with a strike-through. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag - true if strike-through, false if normal

isStrikeThrough

public boolean isStrikeThrough()
Return whether the text is shown with a strike-through.


setItalic

public void setItalic(boolean bFlag)
Change whether the text is italic. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag - true if italic, false if normal

isItalic

public boolean isItalic()
Return whether the text is italic.


setMultiline

public void setMultiline(boolean bFlag)
Change whether the text is limited to a single line or may have multiple lines. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag - true if multiple lines, false if only a single line

isMultiline

public boolean isMultiline()
Return whether the text can be shown on multiple lines.


setEditable

public void setEditable(boolean bFlag)
Change whether the text is editable by the end user.

Parameters:
bFlag - true if user may edit, false if not

isEditable

public boolean isEditable()
Return whether the text is editable by the end user.


setEditOnSingleClick

public void setEditOnSingleClick(boolean bFlag)
If the text is editable, control whether the user can start editing with a double click or with a single click.

Note that the text object may not receive a single click event if it is a non-selectable part of an area. You can avoid this problem by overriding doMouseClick in the area. Look at most of the example node classes for how to do this.

Parameters:
bFlag - true if user starts editing with single click, false if a double click is required

isEditOnSingleClick

public boolean isEditOnSingleClick()
Return whether a user's single click starts editing the text, assuming the text is editable at all.


setSelectBackground

public void setSelectBackground(boolean bFlag)
If the text background is transparent and the text is not resizable, control whether gainedSelection() makes the background opaque and whether lostSelection() makes the background transparent again.

Parameters:
bFlag - true to show the background color when selected

isSelectBackground

public boolean isSelectBackground()
Return whether gainedSelection() uses the text's background color and the text's transparency to display the selection.


set2DScale

public void set2DScale(boolean bFlag)
Change whether the resizing the text depends on both the width and the height, rather than just the height to determine the font size to use in displaying the string.

This property is only used when the user interactively resizes this text object, or in other words, when isResizable() is true. This property is not used when this object's height or width changes programmatically.

Parameters:
bFlag - true if resizing should use both dimensions.

is2DScale

public boolean is2DScale()
Return whether resizing text heeds both dimensions, rather than just the height.

By default, this value is false.


setClipping

public void setClipping(boolean bFlag)
Change whether the text is only drawn within the bounding rectangle. If it is not clipped, the text may be displayed beyond the bounding rectangle. If it is clipped, the text will be truncated at (approximately) the bounding rectangle.

Parameters:
bFlag - true if the text should not be drawn beyond the bounding rectangle

isClipping

public boolean isClipping()
Return whether text display is limited to the bounding rectangle.


setAutoResize

public void setAutoResize(boolean bFlag)
Control whether the bounding rectangle is changed whenever the text string or other visual attributes are changed.

Parameters:
bFlag - true if this should resize itself when the text changes

isAutoResize

public boolean isAutoResize()
Return whether text's bounding rectangle is recomputed whenever the text string or any of the other visual attributes is changed.

By default, this is true.


setBetterPainting

public void setBetterPainting(boolean bFlag)
Control whether text is drawn slower and more carefully.

Parameters:
bFlag - true if slower but more accurately

isBetterPainting

public boolean isBetterPainting()
Return whether text is drawn more carefully.

By default, this value is true, unless the Java Version is earlier than 1.2.2.


setWrapping

public void setWrapping(boolean bFlag)
Change whether longer text is broken into multiple lines to fit in the defined wrapping width of this object. This property is only effective when isMultiline() is true. The bounding box will be changed to accomodate the new text appearance.

Parameters:
bFlag -

isWrapping

public boolean isWrapping()
Return whether text is automatically wrapped to try to fit in the wrapping width. This property is only effective when isMultiline() is true. By default this is false.


setWrappingWidth

public void setWrappingWidth(int w)
Change the width at which text will wrap, if isMultiline() and isWrapping() are true. This property is independent of the actual width of this object. The bounding box will be changed to accomodate the new text appearance.

Parameters:
w - the new wrapping width

getWrappingWidth

public int getWrappingWidth()
Return the maximum width for wrapped text. When isMultiline() and isWrapping() are true, the minimum of this value and the actual getWidth() of this object will determine the layout of the text.


expandRectByPenWidth

public void expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
Account for any likely text drawn beyond the bounding rectangle because of nonlinear text scaling

Overrides:
expandRectByPenWidth in class JGoObject
Parameters:
rect - the Rectangle to be modified

paintGreek

public boolean paintGreek(Graphics2D g,
                          JGoView view)
This method is called by paint to allow optimizing drawing a lot of objects at small scales. By default this will not draw anything at all for this text object when the scale is at or less than getDefaultPaintNothingScale(), and it will only draw a simple line when the scale is at or less than getDefaultPaintGreekScale().

Returns:
true if this method handled the painting, or false if it expects the normal painting to occur.

paint

public void paint(Graphics2D g,
                  JGoView view)
Called to draw the text on the screen.

Overrides:
paint in class JGoObject
Parameters:
g - the graphics context on which to draw
view - the view we're drawing in

gainedSelection

protected void gainedSelection(JGoSelection selection)
JGoText has different handles than most objects because the resizing is only supposed to depend on the height. Thus the side handles should not be filled in and enabled for resizing.

If isSelectBackground() is true, we assume the text is normally transparent, and that the background color will be the selection or highlight color. Selection is shown by just making the background visible instead of transparent.

If is2DScale() is true, the user can also resize by changing the width.

Overrides:
gainedSelection in class JGoObject
Parameters:
selection - the selection into which this object was added

lostSelection

protected void lostSelection(JGoSelection selection)
If isSelectBackground() is true, we assume the text is normally transparent, and that the background color will be the selection or highlight color. Lack of selection is shown by just making the background transparent again, instead of opaque.

Overrides:
lostSelection in class JGoObject
Parameters:
selection - the selection from which this object was removed

handleResize

public org.eclipse.swt.graphics.Rectangle handleResize(Graphics2D g,
                                                       JGoView view,
                                                       org.eclipse.swt.graphics.Rectangle prevRect,
                                                       org.eclipse.swt.graphics.Point newPoint,
                                                       int whichHandle,
                                                       int event,
                                                       int minWidth,
                                                       int minHeight)
If this JGoText object is resizable and if the font size is only dependent on the height of the bounding rectangle, we need to recalculate based on new height and whether there are multiple lines of text.

Overrides:
handleResize in class JGoObject
Parameters:
g - the graphics context to draw on
view - the view we're being resizing in
prevRect - the object's original bounding rectangle
newPoint - the location of the new point
whichHandle - the handle number of the point being moved
event - one of: JGoView.EventMouseUp, JGoView.EventMouseMove, JGoView.EventMouseDown
minWidth - the minimum width of the object (defaults to zero)
minHeight - the minimum height of the object (defaults to zero)

geometryChange

protected void geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
Called when the geometry of the text bounding box is changed. If the width or height changes and isResizable() is true, we scale the font.

Overrides:
geometryChange in class JGoObject
Parameters:
prevRect - the previous bounding rectangle

getLocation

public org.eclipse.swt.graphics.Point getLocation(org.eclipse.swt.graphics.Point result)
Returns the TopLeft, TopMiddle or TopRight point, depending on the text alignment attribute

Overrides:
getLocation in class JGoObject
Parameters:
result - a Point that will be modified to have the object's natural location in document coordinates; if result is null a Point will be allocated
Returns:
the location of the object, in document coordinates; this is the modified argument result or else a newly allocated Point

setLocation

public void setLocation(int x,
                        int y)
Sets a new position for the TopLeft, TopMiddle or TopRight point. Placement depends on the text alignment attribute.

Overrides:
setLocation in class JGoObject
Parameters:
x - the new X position for the object's location
y - the new Y position for the object's location

setSizeKeepingLocation

public void setSizeKeepingLocation(int w,
                                   int h)
Sets a new size for this object while maintaining the same Location. This is more efficient than remembering getLocation(), calling setSize(), and then calling setLocation() again.

Overrides:
setSizeKeepingLocation in class JGoObject
Parameters:
w - the new width for this object's bounding rectangle
h - the new height for this object's bounding rectangle

doMouseClick

public boolean doMouseClick(int modifiers,
                            org.eclipse.swt.graphics.Point dc,
                            org.eclipse.swt.graphics.Point vc,
                            JGoView view)
The default behavior on single click is to start editing in-place if the document isModifiable is true, if isEditable is true, and if isEditOnSingleClick is true.

Overrides:
doMouseClick in class JGoObject
Parameters:
modifiers - which keys are pressed, etc.
dc - the document coordinates.
vc - the view coordinates.
view - the view itself
Returns:
true if the click has been handled
See Also:
JGoView.doMouseDblClick(int, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Point)

doMouseDblClick

public boolean doMouseDblClick(int modifiers,
                               org.eclipse.swt.graphics.Point dc,
                               org.eclipse.swt.graphics.Point vc,
                               JGoView view)
The default behavior on double click is to start editing in-place if the document isModifiable is true, if isEditable is true, and if isEditOnSingleClick is false.

Overrides:
doMouseDblClick in class JGoObject
Parameters:
modifiers - which keys are pressed, etc.
dc - the document coordinates.
vc - the view coordinates.
view - the view itself
Returns:
true if the double click has been handled
See Also:
JGoView.doMouseDblClick(int, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Point)

doStartEdit

public void doStartEdit(JGoView view,
                        org.eclipse.swt.graphics.Point vc)
Programmatically start the editing of the text for the user. This will cause an SWT Text Control to appear.

This is responsible for starting a transaction.

Parameters:
view - the view in which the user will be editing
vc - the view coordinates where the user may have clicked

doEdit

public boolean doEdit(JGoView view,
                      java.lang.String oldtext,
                      java.lang.String newtext)
Called when a user tries to commit a text edit.

This actually sets the text string of this text object. You can override this method in order to validate any in-place text editing done by the user.

   // do some validation--don't allow integers larger than 1000
   public boolean doEdit(JGoView view, String oldtext, String newtext) {
     try {
       int i = Integer.parseInt(newtext);
       if (i > 1000) {
         view.doCancelMouse();
         MessageBox dlg = new MessageBox(view.getShell(), SWT.ICON_ERROR | SWT.OK);
         dlg.setText("Label Validation");
         dlg.setMessage(Integer.toString(i) + " is too big!");
         dlg.open();
         return false;
       }
     } catch (NumberFormatException ex) {
       // allow non-integers to pass validation
     }
     return super.doEdit(view, oldtext, newtext);
   }
 
By default this just calls setText(computeEdit(oldtext, newtext)) and returns true.

Parameters:
view - the JGoView that the user is editing in
oldtext - the old pre-edit string value of this text object
newtext - the proposed new string value for this text object
Returns:
true if the value was set; false if the editor (JGoTextEdit) should continue to remain editing

computeEdit

public java.lang.String computeEdit(java.lang.String oldtext,
                                    java.lang.String newtext)
Calculate a new string value for this object as a result of an edit.

This is called by doEdit, which is responsible for calling setText with the value returned by this method.

You can override this method in order to canonicalize the string values that the user enters.

Parameters:
oldtext - the old pre-edit string value of this text object
newtext - the proposed new string value for this text object
Returns:
by default, the newtext string

doEndEdit

public void doEndEdit()
Programmatically end the editing of the text for the user. The SWT Text Control, if still present, should disappear.

This is responsible for firing a JGoViewEvent.OBJECT_EDITED event and for ending a transaction.


copyNewValueForRedo

public void copyNewValueForRedo(JGoDocumentChangedEdit e)
Description copied from class: JGoObject
This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed. In order for the JGoDocumentChangedEdit to be able to perform a redo, it needs to remember the new property value or state. However, the JGoObject.update method does not provide such a new value. The value must be taken from this object and copied into the JGoDocumentChangedEdit by calling setNewValue and/or setNewValueInt.

Just as the previous/old value/state information is stored as one or both of an integer and an Object, the new value/state information may be stored as either or both of an integer or an Object.

The responsibility for copying rests with the document event listener rather than the code calling JGoObject.update for efficiency when there is no undo/redo manager.

Overrides:
copyNewValueForRedo in class JGoObject
Parameters:
e - the UndoableEdit that also remembers the kind of change and any appropriate new state that should be copied in

changeValue

public void changeValue(JGoDocumentChangedEdit e,
                        boolean undo)
Description copied from class: JGoObject
This method is called by the JGoDocumentChangedEdit.undo and redo methods to actually perform the property value change for a JGoObject.

You will want to override this method to handle changing the additional state of your object subclasses.

Overrides:
changeValue in class JGoObject
Parameters:
e - the UndoableEdit that also remembers the kind of change and any appropriate old and new state for performing an undo or redo
undo - if true, this method should restore the old state/value, otherwise this method should restore the new state/value

setDefaultFontFaceName

public static void setDefaultFontFaceName(java.lang.String name)
Change the default font face to be used by JGoText constructors that do not take an explicit font face name argument.

Parameters:
name - the new font face name

getDefaultFontFaceName

public static java.lang.String getDefaultFontFaceName()
Return the default font face name for JGoText constructors that do not take an explicit font face name argument.


setDefaultFontSize

public static void setDefaultFontSize(int size)
Change the default font size to be used by JGoText constructors that do not take an explicit font size argument.

Parameters:
size - the new font size

getDefaultFontSize

public static int getDefaultFontSize()
Return the default font size for JGoText constructors that do not take an explicit font size argument.


getDefaultPaintNothingScale

public static double getDefaultPaintNothingScale()
Return the view scale at which a text object should not paint anything. Thus when a JGoText object is painted on a view whose scale is less than or equal to this value, nothing actually appears.


setDefaultPaintNothingScale

public static void setDefaultPaintNothingScale(double s)
Change the scale at which text will not paint. Calling this method will not actually repaint any views or any JGoText objects.


getDefaultPaintGreekScale

public static double getDefaultPaintGreekScale()
Return the view scale at which this text object should paint something simpler than real text.


setDefaultPaintGreekScale

public static void setDefaultPaintGreekScale(double s)
Change the scale at which text will paint very simply. Calling this method will not actually repaint any views or any JGoText objects.


setDefaultWrappingWidth

public static void setDefaultWrappingWidth(int w)
Change the default text wrapping width to be used by JGoText constructors.

Parameters:
w - the new default wrap width

getDefaultWrappingWidth

public static int getDefaultWrappingWidth()
Return the default wrapping width for JGoText constructors.


setDefaultBetterPainting

public static void setDefaultBetterPainting(boolean b)
Change the default setting for the BetterPainting property for each new JGoText object.


isDefaultBetterPainting

public static boolean isDefaultBetterPainting()
Return the default setting for JGoText's BetterPainting property. This defaults to true for JDK/JRE 1.2.2 and later, but false for 1.2.0 and 1.2.1.


SVGWriteObject

public void SVGWriteObject(DomDoc svgDoc,
                           DomElement jGoElementGroup)
Description copied from interface: JGoXMLSaveRestore
Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGWriteDoc() for every JGoObject contained within a JGoDocument. The following example uses a JGoRectangle to illustrate the format of a generated SVG JGoObject:

<g>
<JGoClass class="com.nwoods.jgo.JGoRectangle"\>
<rect height="75" style="stroke:black;stroke-width:1;fill:rgb(255,0,0);" width="75" x="65" y="71"/>
<JGoClass class="com.nwoods.jgo.JGoDrawable" drawablebrush="jgoid1" drawablepen="jgoid2" embeddedpenbrush="false"/>
<JGoClass class="com.nwoods.jgo.JGoObject" obj_flags="1054"/>
</g>

Note that the entire JGoObject is enclosed in a group (<g>). Each subclass of the JGoObject is described by a <JGoClass> element, starting with the most specific class and moving to the more general. Each <JGoClass> element has a "class" attribute which defines the class name. Each <JGoClass> element may also have several other attributes which uniquely describe that state of that class. Following the <JGoClass> element, each class may also genereate any other elements that are required, including representations of contained objects and standard SVG elements such as the <rect> element shown in the above example. The generation of SVG elements in the output makes it possible for the output to be read by SVG viewers and other SVG aware applications. The information contained in the <JGoClass> elements allows us to accurately save and restore all the information in a particular JGoObject subclass.

If this class contains a reference to another object, call DomDoc.registerReferencingNode() to register that reference. This will cause the element representing the referenced object to be identified with a unique id attribute, and cause the element representing the referring object to have a user defined attribute containing a reference to that id. See DomDoc.registerReferencingNode() for more information.

Typically, an implementation of this method will generate a <JGoClass> element using the DomDoc.createJGoClassElement() method, adding whatever attributes are necessary to describe the class. It will then call its superclass so that the superclass can add its own <JGoClass> element and other information to jGoElementGroup within the DomDoc.

Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGWriteObject() and com.nwoods.jgo.examples.SimpleNode.SVGWriteObject() for examples using this method.

Refer to the file com.nwoods.jgo.svg\xsvg.dtd for a formal description of JGo extensions to the SVG document type.

Specified by:
SVGWriteObject in interface JGoXMLSaveRestore
Overrides:
SVGWriteObject in class JGoObject

SVGReadObject

public DomNode SVGReadObject(DomDoc svgDoc,
                             JGoDocument jGoDoc,
                             DomElement svgElement,
                             DomElement jGoChildElement)
Description copied from interface: JGoXMLSaveRestore
Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() for every <JGoClass> element encountered in a DomDoc. First, an object of the type specified by the class attribute will be created and then the SVGReadObject() method will be called on that newly created object. Refer to SVGWriteObject() for a description of the expected format of the SVG document.

This method may also be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() when reading any SVG document, including those not generated by JGo and therefore not containing any <JGoClass> elements. In such cases, the DefaultDocument.SVGReadElement() method may be subclassed to examine the SVG element and cause the appropriate JGoObject to be created to represent that element and call SVGReadObject() on that newly created object. By default, standard JGoObjects such as JGoRectangles, JGoStrokes, etc will be created to represent these objects.

If this class contains a reference to another object, call DomDoc.registerReferencingObject() to register that reference. This will cause the JGoObject.SVGUpdateReference() to be called on the referencing object after all the objects have been created, passing in the object befing referenced. See DomDoc.registerReferencingObject() for more information.

Typically, an implementation of this method starts by verifying that the element being read is a <JGoClass> element (which will be true if jGoChildElement is not null). This will always be true unless you have subclassed the DefaultDocument.SVGReadElement() method as described above. It will then read the expected attributes of the <JGoClass> element (as written by SVGReadObject()), call SVGReadObject() on its superclass, and finally return the next element by calling svgElement.getNextSibling().

Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGReadObject() and com.nwoods.jgo.examples.SimpleNode.SVGReadObject() for examples using this method.

Specified by:
SVGReadObject in interface JGoXMLSaveRestore
Overrides:
SVGReadObject in class JGoObject

SVGWriteAttributes

public void SVGWriteAttributes(DomElement svgElement)
Description copied from class: JGoObject
This method will add attributes to standard SVG elements.

Call this method from SVGWriteObject() if standard SVG elements are generated by this class or if this class may be subclassed and it should contribute arguments to SVG elements. For example, the JGoDrawable class implements this method to add standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to add all appropriate attributes to the <rect> element it generates. It is not necessary to implement this method if this class does not contribute any attributes to standard SVG elements. It is not necessary to call this method from SVGWriteObject() if this class does not generate any standard SVG elements.

Typically, an implementation of this method will first call the superclass and then call DomElement.setAttribute() to add attributes for this class.

Overrides:
SVGWriteAttributes in class JGoObject
Parameters:
svgElement - the DomElement to which to add attributes
See Also:
JGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement), JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement), JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement), JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement), JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object), DomDoc, DomNode, DomElement, DomText

SVGReadAttributes

public void SVGReadAttributes(DomElement svgElement)
Description copied from class: JGoObject
This method will read attributes from standard SVG elements.

Call this method from SVGReadObject() if standard SVG elements are being read by this class or if this class may be subclassed and it should read arguments from SVG elements. For example, the JGoDrawable class implements this method to read standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to read all appropriate attributes from the <rect> element it is reading. It is not necessary to implement this method if this class does not read any attributes from standard SVG elements. It is not necessary to call this method from SVGReadObject() if this class does not read any standard SVG elements.

Typically, an implementation of this method will first call the superclass and then call DomElement.getAttribute() to read the attributes for this class.

Overrides:
SVGReadAttributes in class JGoObject
Parameters:
svgElement - the DomElement from which to read attributes
See Also:
JGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement), JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement), JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement), JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement), JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object), DomDoc, DomNode, DomElement, DomText