Package com.inductiveautomation.rm.text
Class RMXString
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMListenerList
-
- com.inductiveautomation.rm.base.RMObject
-
- com.inductiveautomation.rm.text.RMXString
-
- All Implemented Interfaces:
Archivable,RMPropertyChanger,RMTypes,RMTextTypes,java.lang.CharSequence,java.lang.Cloneable
public class RMXString extends RMObject implements java.lang.CharSequence, RMTextTypes, Archivable
An RMXString is like a String that lets you apply attributes, like fonts and colors, to character ranges. These character ranges with common attributes are represented internally as the inner class Run.You might use it like this:
RMXString xstring = new RMXString("Hello World", RMColor.red); xstring.addAttribute(RMFont.getFont("Arail Bold", 12), 0, 5); xstring.addAttribute(RMFont.getFont("Arial BoldItalic", 12), 6, xstring.length());Advanced applications, that need to dissect or render strings, might iterate over the runs like this:
for(int i=0; i<xstring.getRunCount(); i++) { RMXString.Run run = xstring.getRun(i); graphics.setFont(run.getFont().awt()); graphics.setColor(run.getColor().awt()); graphics.drawString(xstring.substring(run.start(), run.end())); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classRMXString.CharsChangeA property change event for addChars/removeChars.static classRMXString.OutlineThe Outline inner class represents the attributes of outlined text: strokeWidth and fillColor.classRMXString.StyleChangeA property change event for RMXStringRun.Style change.-
Nested classes/interfaces inherited from interface com.inductiveautomation.rm.text.RMTextTypes
RMTextTypes.TabType
-
Nested classes/interfaces inherited from interface com.inductiveautomation.rm.base.RMTypes
RMTypes.Align, RMTypes.AlignX, RMTypes.AlignY
-
-
Field Summary
-
Fields inherited from interface com.inductiveautomation.rm.text.RMTextTypes
TEXT_CHAR_SPACING, TEXT_COLOR, TEXT_EMBEDDED_SHAPE, TEXT_FONT, TEXT_FORMAT, TEXT_OUTLINE, TEXT_PARAGRAPH, TEXT_SCRIPTING, TEXT_UNDERLINE
-
-
Constructor Summary
Constructors Constructor Description RMXString()Creates an empty RMXString.RMXString(java.lang.CharSequence theChars)Creates an RMXString initialized with the given String and no attributes.RMXString(java.lang.CharSequence theChars, RMTextStyle aStyle)Creates an RMXString initialized with the given String with all characters set to the given style.RMXString(java.lang.CharSequence theChars, java.lang.Object... theAttrs)Creates an RMXString initialized with the given String with all characters set to the given attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChars(java.lang.CharSequence theChars)Appends the given String to the end of this XString.voidaddChars(java.lang.CharSequence theChars, int anIndex)Adds chars at index.voidaddChars(java.lang.CharSequence theChars, RMTextStyle aStyle, int anIndex)Appends the given string to this XString, with the given attributes, at the given index.voidaddChars(java.lang.CharSequence theChars, java.lang.Object... theAttrs)Appends the given chars with the given attribute(s).voidaddChars(java.lang.CharSequence theChars, java.util.Map theAttrs)Appends the given string to the end of this XString, with the given attributes.voidaddChars(java.lang.CharSequence theChars, java.util.Map theAttrs, int anIndex)Appends the given string to this XString, with the given attributes, at the given index.voidaddString(RMXString aString, int anIndex)Adds an XString to this string at given index.charcharAt(int anIndex)Returns the char at given index.RMXStringclone()Returns a clone of this x string.booleanequals(java.lang.Object anObj)Standard Object equals implementation.protected voidfirePropertyChange(java.beans.PropertyChangeEvent anEvent, java.lang.String aName, java.lang.Object oldVal, java.lang.Object newVal, int anIndex)Override so RMXStringRun can reach this and to reset representable string and version.RMXStringfromXML(RXArchiver anArchiver, RXElement anElement)XML unarchival.RMTypes.AlignXgetAlignX()Returns the horizontal alignment of the first paragraph of the xstring.RMDateFormatgetDateFormat()java.lang.ObjectgetDefaultAttribute(java.lang.String aKey)Returns the default for a given key.RMColorgetDefaultColor()Returns the default color for this string.RMFontgetDefaultFont()Returns the default font for this string.RMFormatgetDefaultFormat()Returns the default format for this string.RMParagraphgetDefaultParagraph()Returns the default paragraph for this string.RMFontgetFontAt(int anIndex)Returns the current font at the given character index.RMNumberFormatgetNumberFormat()RMParagraphgetParagraphAt(int anIndex)Returns the current paragraph at the given character index.RMXStringgetRepresentableString()Returns a version of this string that substitutes alternate fonts for any characters that cannot be displayed in their associated fonts (simply returns the receiver if all characters are valid).RMXStringRungetRun()Returns the XString head run.RMXStringRungetRun(int anIndex)Returns the specific Run at the given index in this XString.RMXStringRungetRunAt(int anIndex)Returns the XString run that contains or ends at given index.RMXStringRungetRunAt(int anIndex, boolean isInclusive)Returns the XString run that contains or ends (if given option is true) at given index.intgetRunCount()Returns the number of runs in this XString.RMXStringRungetRunLast()Returns the last run in this XString (convenience).RMTextStylegetStyleAt(int anIndex)Returns the text style for the run at the given character index.RMTextStylegetStyleAt(int anIndex, boolean isInclusive)Returns the text style for the run at the given character index.java.lang.StringgetText()Returns the simple String represented by this RMXString.booleanhasListeners()Override to return false if FirePropertyChangeEnabled is off.intindexOf(java.lang.String aString)Returns the index within this string of the first occurrence of the given substring.intindexOf(java.lang.String aString, int aStart)Returns the index within this string of first occurrence of given substring, starting at given index.intlength()The length.voidremoveChars(int aStart, int anEnd)Removes characters in given range.voidreplaceChars(java.lang.CharSequence theChars, int aStart, int anEnd)Replaces chars in given range, with given String.voidreplaceChars(java.lang.CharSequence theChars, RMTextStyle aStyle, int aStart, int anEnd)Replaces chars in given range, with given String, using the given attributes.voidreplaceString(RMXString xString, int aStart, int anEnd)Replaces the chars in given range, with given XString.RMXStringrpgClone(ReportOwner anRptOwner, java.lang.Object userInfo, RMShape aShape, boolean doCopy)Creates a clone of the receiver, with substitution performed on @-sign delineated keys.voidsetAlignX(RMTypes.AlignX anAlignX)Sets the horizontal alignment of the xstring.voidsetAttribute(java.lang.Object anAttr)Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).voidsetAttribute(java.lang.Object anAttr, int aStart, int anEnd)Applies the given attribute to the given character range, assuming it's a basic attr type (font, color, etc.).voidsetAttribute(java.lang.String aKey, java.lang.Object anAttr)Adds a given attribute of given type to the whole string.voidsetAttribute(java.lang.String aKey, java.lang.Object aValue, int aStart, int anEnd)Sets a given attribute to a given value for a given range.voidsetDateFormat(RMDateFormat dateFormat)voidsetDateFormat(java.lang.String dateFormatString)voidsetFirePropertyChangeEnabled(boolean aValue)Sets whether string fires property change events.voidsetFormat(RMFormat format)voidsetNumberFormat(RMNumberFormat numberFormat)voidsetNumberFormat(java.lang.String numberFormatString)voidsetParagraph(RMParagraph ps, int start, int end)Sets the paragraph for the given character index range.voidsetStyle(RMTextStyle aStyle, int aStart, int anEnd)Sets the text style for given range.voidsetText(java.lang.String aString)Sets the simple String represented by this RMXString.voidsetUnderlined(boolean aFlag)Sets the xstring to be underlined.java.lang.CharSequencesubSequence(int aStart, int anEnd)Returns a subsequence.RMXStringsubstring(int aStart)Returns an XString for given char range.RMXStringsubstring(int aStart, int anEnd)Returns an XString for given char range.java.lang.StringtoString()Standard toString implementation.RXElementtoXML(RXArchiver anArchiver)XML archival.-
Methods inherited from class com.inductiveautomation.rm.base.RMObject
addPropertyChangeListener, animUpdate, firePropertyChange, firePropertyChange, getPCEvent, removePropertyChangeListener, sendPropertyChange
-
Methods inherited from class com.inductiveautomation.rm.base.RMListenerList
addListener, getListener, getListenerCount, getListenerCount, getListenerList, getListeners, removeListener
-
-
-
-
Constructor Detail
-
RMXString
public RMXString()
Creates an empty RMXString.
-
RMXString
public RMXString(java.lang.CharSequence theChars)
Creates an RMXString initialized with the given String and no attributes.
-
RMXString
public RMXString(java.lang.CharSequence theChars, RMTextStyle aStyle)Creates an RMXString initialized with the given String with all characters set to the given style.
-
RMXString
public RMXString(java.lang.CharSequence theChars, java.lang.Object... theAttrs)Creates an RMXString initialized with the given String with all characters set to the given attributes.
-
-
Method Detail
-
getText
public java.lang.String getText()
Returns the simple String represented by this RMXString.
-
length
public int length()
The length.- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int anIndex)
Returns the char at given index.- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int aStart, int anEnd)Returns a subsequence.- Specified by:
subSequencein interfacejava.lang.CharSequence
-
setText
public void setText(java.lang.String aString)
Sets the simple String represented by this RMXString.
-
indexOf
public int indexOf(java.lang.String aString)
Returns the index within this string of the first occurrence of the given substring.
-
indexOf
public int indexOf(java.lang.String aString, int aStart)Returns the index within this string of first occurrence of given substring, starting at given index.
-
addChars
public void addChars(java.lang.CharSequence theChars)
Appends the given String to the end of this XString.
-
addChars
public void addChars(java.lang.CharSequence theChars, java.lang.Object... theAttrs)Appends the given chars with the given attribute(s).
-
addChars
public void addChars(java.lang.CharSequence theChars, java.util.Map theAttrs)Appends the given string to the end of this XString, with the given attributes.
-
addChars
public void addChars(java.lang.CharSequence theChars, int anIndex)Adds chars at index.
-
addChars
public void addChars(java.lang.CharSequence theChars, java.util.Map theAttrs, int anIndex)Appends the given string to this XString, with the given attributes, at the given index.
-
addChars
public void addChars(java.lang.CharSequence theChars, RMTextStyle aStyle, int anIndex)Appends the given string to this XString, with the given attributes, at the given index.
-
removeChars
public void removeChars(int aStart, int anEnd)Removes characters in given range.
-
replaceChars
public void replaceChars(java.lang.CharSequence theChars, int aStart, int anEnd)Replaces chars in given range, with given String.
-
replaceChars
public void replaceChars(java.lang.CharSequence theChars, RMTextStyle aStyle, int aStart, int anEnd)Replaces chars in given range, with given String, using the given attributes.
-
addString
public void addString(RMXString aString, int anIndex)
Adds an XString to this string at given index.
-
replaceString
public void replaceString(RMXString xString, int aStart, int anEnd)
Replaces the chars in given range, with given XString.
-
getRun
public RMXStringRun getRun()
Returns the XString head run.
-
getRunCount
public int getRunCount()
Returns the number of runs in this XString.
-
getRun
public RMXStringRun getRun(int anIndex)
Returns the specific Run at the given index in this XString.
-
getRunLast
public RMXStringRun getRunLast()
Returns the last run in this XString (convenience).
-
getRunAt
public final RMXStringRun getRunAt(int anIndex)
Returns the XString run that contains or ends at given index.
-
getRunAt
public RMXStringRun getRunAt(int anIndex, boolean isInclusive)
Returns the XString run that contains or ends (if given option is true) at given index.
-
getNumberFormat
@Nonnull public RMNumberFormat getNumberFormat()
-
setNumberFormat
public void setNumberFormat(@Nullable RMNumberFormat numberFormat)
-
setNumberFormat
public void setNumberFormat(@Nullable java.lang.String numberFormatString)
-
getDateFormat
@Nonnull public RMDateFormat getDateFormat()
-
setDateFormat
public void setDateFormat(@Nullable RMDateFormat dateFormat)
-
setDateFormat
public void setDateFormat(@Nullable java.lang.String dateFormatString)
-
setFormat
public void setFormat(@Nullable RMFormat format)
-
getStyleAt
public RMTextStyle getStyleAt(int anIndex)
Returns the text style for the run at the given character index.
-
getStyleAt
public RMTextStyle getStyleAt(int anIndex, boolean isInclusive)
Returns the text style for the run at the given character index.
-
setStyle
public void setStyle(RMTextStyle aStyle, int aStart, int anEnd)
Sets the text style for given range.
-
setAttribute
public void setAttribute(java.lang.Object anAttr)
Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).
-
setAttribute
public void setAttribute(java.lang.Object anAttr, int aStart, int anEnd)Applies the given attribute to the given character range, assuming it's a basic attr type (font, color, etc.).
-
setAttribute
public void setAttribute(java.lang.String aKey, java.lang.Object anAttr)Adds a given attribute of given type to the whole string.
-
setAttribute
public void setAttribute(java.lang.String aKey, java.lang.Object aValue, int aStart, int anEnd)Sets a given attribute to a given value for a given range.
-
getFontAt
public RMFont getFontAt(int anIndex)
Returns the current font at the given character index.
-
getParagraphAt
public RMParagraph getParagraphAt(int anIndex)
Returns the current paragraph at the given character index.
-
setParagraph
public void setParagraph(RMParagraph ps, int start, int end)
Sets the paragraph for the given character index range.
-
setUnderlined
public void setUnderlined(boolean aFlag)
Sets the xstring to be underlined.
-
getAlignX
public RMTypes.AlignX getAlignX()
Returns the horizontal alignment of the first paragraph of the xstring.
-
setAlignX
public void setAlignX(RMTypes.AlignX anAlignX)
Sets the horizontal alignment of the xstring.
-
getDefaultFont
public RMFont getDefaultFont()
Returns the default font for this string.
-
getDefaultColor
public RMColor getDefaultColor()
Returns the default color for this string.
-
getDefaultParagraph
public RMParagraph getDefaultParagraph()
Returns the default paragraph for this string.
-
getDefaultFormat
public RMFormat getDefaultFormat()
Returns the default format for this string.
-
getDefaultAttribute
public java.lang.Object getDefaultAttribute(java.lang.String aKey)
Returns the default for a given key.
-
getRepresentableString
public RMXString getRepresentableString()
Returns a version of this string that substitutes alternate fonts for any characters that cannot be displayed in their associated fonts (simply returns the receiver if all characters are valid).
-
substring
public RMXString substring(int aStart)
Returns an XString for given char range.
-
substring
public RMXString substring(int aStart, int anEnd)
Returns an XString for given char range.
-
rpgClone
public RMXString rpgClone(ReportOwner anRptOwner, java.lang.Object userInfo, RMShape aShape, boolean doCopy)
Creates a clone of the receiver, with substitution performed on @-sign delineated keys.
-
firePropertyChange
protected void firePropertyChange(java.beans.PropertyChangeEvent anEvent, java.lang.String aName, java.lang.Object oldVal, java.lang.Object newVal, int anIndex)Override so RMXStringRun can reach this and to reset representable string and version.- Overrides:
firePropertyChangein classRMObject
-
setFirePropertyChangeEnabled
public void setFirePropertyChangeEnabled(boolean aValue)
Sets whether string fires property change events.
-
hasListeners
public boolean hasListeners()
Override to return false if FirePropertyChangeEnabled is off.- Overrides:
hasListenersin classRMListenerList
-
toXML
public RXElement toXML(RXArchiver anArchiver)
XML archival.- Specified by:
toXMLin interfaceArchivable
-
fromXML
public RMXString fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.- Specified by:
fromXMLin interfaceArchivable
-
equals
public boolean equals(java.lang.Object anObj)
Standard Object equals implementation.- Overrides:
equalsin classjava.lang.Object
-
clone
@Nullable public RMXString clone()
Returns a clone of this x string.- Overrides:
clonein classRMListenerList
-
-