Package com.reportmill.text
Class RMXString
- java.lang.Object
- 
- com.reportmill.base.RMObject
- 
- com.reportmill.text.RMXString
 
 
- 
- All Implemented Interfaces:
- RMArchiver.Archiving,- java.lang.Cloneable
 
 public class RMXString extends RMObject 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 disect or render strings, might iterate over the runs like this: for(int i=0; i- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classRMXString.OutlineThe Outline inner class represents the attributes of outlined text: strokeWidth and fillColor.
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringCHAR_SPACING_KEYstatic java.lang.StringCOLOR_KEYstatic java.lang.StringFONT_KEYstatic java.lang.StringFONT_SCALE_KEYstatic java.lang.StringFORMAT_KEYstatic java.lang.StringOUTLINE_KEYstatic java.lang.StringPARAGRAPH_KEYstatic java.lang.StringSCRIPTING_KEYstatic java.lang.StringUNDERLINE_KEY
 - 
Constructor SummaryConstructors Constructor Description RMXString()Creates an empty RMXString.RMXString(java.lang.String aString)Creates an RMXString intialized with the given String and no attributes.RMXString(java.lang.String aString, java.lang.Object anAttr)Creates an RMXString initialized with the given String with all characters set to the given attribute (should be a common attribute type like RMFont, RMColor, RMFormat, etc.).RMXString(java.lang.String aString, java.lang.Object[] attrs)Creates an RMXString initialized with the given String with all characters set to the given attributes objects in object array (should be common attribute types like RMFont, RMColor, RMFormat, etc.).RMXString(java.lang.String aString, java.util.Map attrs)Creates an RMXString initialized with the given String with all characters set to the given attributes.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(RMXString xString)Appends the given XString to the end of this String.voidadd(RMXString xString, int anIndex)Appends the given XString to this XString, at the given index.voidadd(java.lang.String aString)Appends the given String to the end of this XString.voidadd(java.lang.String aString, int anIndex)Appends the given String to this XString, at the given index.voidadd(java.lang.String aString, java.util.Map attrs)Appends the given string to the end of this XString, with the given attributes.voidadd(java.lang.String aString, java.util.Map attrs, int anIndex)Appends the given String to this XString, with the given attributes, at the given index.voidaddAttribute(java.lang.Object attr)Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).voidaddAttribute(java.lang.Object attr, int start, int end)Applies the given attribute to the given character range, assuming it's a basic attr type (font, color, etc.).voidaddAttribute(java.lang.String aKey, java.lang.Object object)Adds a given attribute of given type to the whole string.voidaddAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end)Adds a given attribute of given type to the given range of the string.voidaddAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end, boolean ifAbsent)Adds a given attribute of given type to the given range of the string, only if specified type is missing.voidaddAttributes(java.util.Map attrs, int start, int end)Adds the attributes in the given map to the specified character range.voidaddAttributes(java.util.Map attrs, int start, int end, boolean ifAbsent)Adds the attributes in the given map to the specified character range.voidalignCenter()Aligns the xstring center.voidalignLeft()Aligns the xstring left.voidalignRight()Aligns the xstring right.RMXStringblend(RMXString aString, float fraction)Returns a blended version of the receiver and the given string (0 is receiver, 1 is given string).charcharAt(int anIndex)Returns the character at the given index.java.lang.Objectclone()Returns a clone of the receiver.voidcoalesceNewlines()Replaces any occurrance of consecutive newlines with a single newline.voiddelete(int start, int end)Deletes the chars in the given range.voiddidChange()Notifies string that something significant changed.booleanequals(java.lang.Object anObj)Standard Object equals implementation.java.lang.ObjectfromXML(RXArchiver anArchiver, RXElement anElement)XML unarchival.bytegetAlign()Returns the horizontal alignment of the first paragraph of the xstring.java.lang.ObjectgetAttributeAt(java.lang.String aKey, int anIndex)Returns the value for the given attribute key at the given character index.java.util.MapgetAttributes(int anIndex)Returns the attributes Map for the run at the given index.java.util.MapgetAttributesAt(int anIndex)Returns the attributes Map for the run at the given character index.RMColorgetColorAtIndex(int index)Returns the current color at the given character index.RMFontgetFontAtIndex(int index)Returns the current font at the given character index.floatgetFontScale()Returns the value that should be multipied times all font sizes in this string (defaults to 1).RMFormatgetFormatAtIndex(int index)Returns the current format at the given character index.RMParagraphgetParagraphAtIndex(int index)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(int anIndex)Returns the specific Run at the given index in this XString.RMXStringRungetRunAt(int anIndex)Returns the XString run at the given index.RMXStringRungetRunAtExactly(int anIndex)Returns an XString run for the given character index, potentially splitting an existing run to ensure that new run starts at the given index.intgetRunCount()Returns the number of runs in this XString.intgetRunIndexAt(int anIndex)Returns the XString run index for the given character index.intgetRunIndexAtExactly(int anIndex)Returns an XString segement index for the given character index, potentially splitting an existing run to ensure that new run starts at the given index.RMXStringRungetRunLast()Returns the last run in this XString (convenience).intgetVersion()Returns the version of this xstring.static RMXStringgetXStringForHTML(java.lang.String html, RMFont aFont)Creates and returns an XString from a given HTML String.static RMXStringgetXStringForRTF(java.lang.String rtf, RMFont aFont)Creates and returns an XString from a given RTF String.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 start)Returns the index within this string of first occurrence of given substring, starting at given index.java.lang.ObjectinitWithArchiver(RMArchiver anArchiver)Legacy archival.intlength()Returns the number of characters associated with this RMXString.voidremoveAttribute(java.lang.String aKey, int start, int end)Removes any attribute of the specified type from the specified range of the string.voidreplace(int start, int end, RMXString xString)Replaces the chars in given range, with given XString.voidreplace(int start, int end, java.lang.String aString)Replaces chars in given range, with given String.voidreplace(int start, int end, java.lang.String aString, java.util.Map attrs)Replaces chars in given range, with given String, using the given attributes.voidreplace(java.lang.String aString)Replaces all chars of this XString with given String.RMXStringrpgClone(ReportMill aReportMill, java.lang.Object userInfo, RMShape aShape)Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.java.util.Vectorseparate(java.lang.String aSeparator)Returns a List of XString substrings of this XString that are separated by the given separator String.voidsetAlign(int align)Sets the horizontal alignment of the xstring.voidsetFontScale(float aScale)Sets a value to that should be multiplied times all font sizes in this string.voidsetOutlined(boolean flag)Sets the xstring to be outlined.voidsetParagraph(RMParagraph ps, int start)Sets the paragraph at the given character index.voidsetParagraph(RMParagraph ps, int start, int end)Sets the paragraph for the given character index range.voidsetUnderlined(boolean flag)Sets the xstring to be underlined.java.lang.Stringstring()Returns the plain String associated with this RMXString.RMXStringsubstring(int index)Returns the substring from the given index to end of XString.RMXStringsubstring(int start, int end)Returns the substring from the given start index to the given end index.java.lang.StringtoString()Returns the String associated with this XString.java.lang.StringtoStringXML()Returns an XML style string representation of the attributes and string runs in this XString.RXElementtoXML(RXArchiver anArchiver)XML archival.- 
Methods inherited from class com.reportmill.base.RMObjectcopy, didChange, didUndo, getAnimAttribute, getClassNameShort, undoClone, undoCopy, undoEquals
 
- 
 
- 
 - 
- 
Field Detail- 
FONT_KEYpublic static final java.lang.String FONT_KEY - See Also:
- Constant Field Values
 
 - 
COLOR_KEYpublic static final java.lang.String COLOR_KEY - See Also:
- Constant Field Values
 
 - 
FORMAT_KEYpublic static final java.lang.String FORMAT_KEY - See Also:
- Constant Field Values
 
 - 
UNDERLINE_KEYpublic static final java.lang.String UNDERLINE_KEY - See Also:
- Constant Field Values
 
 - 
OUTLINE_KEYpublic static final java.lang.String OUTLINE_KEY - See Also:
- Constant Field Values
 
 - 
PARAGRAPH_KEYpublic static final java.lang.String PARAGRAPH_KEY - See Also:
- Constant Field Values
 
 - 
FONT_SCALE_KEYpublic static final java.lang.String FONT_SCALE_KEY - See Also:
- Constant Field Values
 
 - 
SCRIPTING_KEYpublic static final java.lang.String SCRIPTING_KEY - See Also:
- Constant Field Values
 
 - 
CHAR_SPACING_KEYpublic static final java.lang.String CHAR_SPACING_KEY - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
RMXStringpublic RMXString() Creates an empty RMXString.
 - 
RMXStringpublic RMXString(java.lang.String aString) Creates an RMXString intialized with the given String and no attributes.
 - 
RMXStringpublic RMXString(java.lang.String aString, java.util.Map attrs)Creates an RMXString initialized with the given String with all characters set to the given attributes.
 - 
RMXStringpublic RMXString(java.lang.String aString, java.lang.Object anAttr)Creates an RMXString initialized with the given String with all characters set to the given attribute (should be a common attribute type like RMFont, RMColor, RMFormat, etc.).
 - 
RMXStringpublic RMXString(java.lang.String aString, java.lang.Object[] attrs)Creates an RMXString initialized with the given String with all characters set to the given attributes objects in object array (should be common attribute types like RMFont, RMColor, RMFormat, etc.).
 
- 
 - 
Method Detail- 
stringpublic java.lang.String string() Returns the plain String associated with this RMXString.
 - 
lengthpublic int length() Returns the number of characters associated with this RMXString.
 - 
indexOfpublic int indexOf(java.lang.String aString) Returns the index within this string of the first occurrence of the given substring.
 - 
indexOfpublic int indexOf(java.lang.String aString, int start)Returns the index within this string of first occurrence of given substring, starting at given index.
 - 
charAtpublic char charAt(int anIndex) Returns the character at the given index.
 - 
getRunCountpublic int getRunCount() Returns the number of runs in this XString.
 - 
getRunpublic RMXStringRun getRun(int anIndex) Returns the specific Run at the given index in this XString.
 - 
getRunLastpublic RMXStringRun getRunLast() Returns the last run in this XString (convenience).
 - 
getAttributespublic java.util.Map getAttributes(int anIndex) Returns the attributes Map for the run at the given index.
 - 
getAttributeAtpublic java.lang.Object getAttributeAt(java.lang.String aKey, int anIndex)Returns the value for the given attribute key at the given character index.
 - 
getAttributesAtpublic java.util.Map getAttributesAt(int anIndex) Returns the attributes Map for the run at the given character index.
 - 
addAttributespublic void addAttributes(java.util.Map attrs, int start, int end)Adds the attributes in the given map to the specified character range.
 - 
addAttributespublic void addAttributes(java.util.Map attrs, int start, int end, boolean ifAbsent)Adds the attributes in the given map to the specified character range. Provides an option to only apply each individual attribute if it isn't already specified for that character range.
 - 
addAttributepublic void addAttribute(java.lang.String aKey, java.lang.Object object)Adds a given attribute of given type to the whole string.
 - 
addAttributepublic void addAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end)Adds a given attribute of given type to the given range of the string.
 - 
addAttributepublic void addAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end, boolean ifAbsent)Adds a given attribute of given type to the given range of the string, only if specified type is missing.
 - 
removeAttributepublic void removeAttribute(java.lang.String aKey, int start, int end)Removes any attribute of the specified type from the specified range of the string.
 - 
getFontAtIndexpublic RMFont getFontAtIndex(int index) Returns the current font at the given character index.
 - 
getColorAtIndexpublic RMColor getColorAtIndex(int index) Returns the current color at the given character index.
 - 
getFormatAtIndexpublic RMFormat getFormatAtIndex(int index) Returns the current format at the given character index.
 - 
getParagraphAtIndexpublic RMParagraph getParagraphAtIndex(int index) Returns the current paragraph at the given character index.
 - 
setParagraphpublic void setParagraph(RMParagraph ps, int start) Sets the paragraph at the given character index.
 - 
setParagraphpublic void setParagraph(RMParagraph ps, int start, int end) Sets the paragraph for the given character index range.
 - 
addAttributepublic void addAttribute(java.lang.Object attr) Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).
 - 
addAttributepublic void addAttribute(java.lang.Object attr, int start, int end)Applies the given attribute to the given character range, assuming it's a basic attr type (font, color, etc.).
 - 
getFontScalepublic float getFontScale() Returns the value that should be multipied times all font sizes in this string (defaults to 1).
 - 
setFontScalepublic void setFontScale(float aScale) Sets a value to that should be multiplied times all font sizes in this string.
 - 
addpublic void add(java.lang.String aString) Appends the given String to the end of this XString.
 - 
addpublic void add(java.lang.String aString, int anIndex)Appends the given String to this XString, at the given index.
 - 
addpublic void add(RMXString xString) Appends the given XString to the end of this String.
 - 
addpublic void add(RMXString xString, int anIndex) Appends the given XString to this XString, at the given index.
 - 
addpublic void add(java.lang.String aString, java.util.Map attrs)Appends the given string to the end of this XString, with the given attributes.
 - 
addpublic void add(java.lang.String aString, java.util.Map attrs, int anIndex)Appends the given String to this XString, with the given attributes, at the given index.
 - 
replacepublic void replace(java.lang.String aString) Replaces all chars of this XString with given String.
 - 
replacepublic void replace(int start, int end, java.lang.String aString)Replaces chars in given range, with given String.
 - 
replacepublic void replace(int start, int end, java.lang.String aString, java.util.Map attrs)Replaces chars in given range, with given String, using the given attributes.
 - 
replacepublic void replace(int start, int end, RMXString xString)Replaces the chars in given range, with given XString.
 - 
deletepublic void delete(int start, int end)Deletes the chars in the given range.
 - 
substringpublic RMXString substring(int index) Returns the substring from the given index to end of XString.
 - 
substringpublic RMXString substring(int start, int end) Returns the substring from the given start index to the given end index.
 - 
separatepublic java.util.Vector separate(java.lang.String aSeparator) Returns a List of XString substrings of this XString that are separated by the given separator String.
 - 
coalesceNewlinespublic void coalesceNewlines() Replaces any occurrance of consecutive newlines with a single newline.
 - 
getXStringForHTMLpublic static RMXString getXStringForHTML(java.lang.String html, RMFont aFont) Creates and returns an XString from a given HTML String.
 - 
getXStringForRTFpublic static RMXString getXStringForRTF(java.lang.String rtf, RMFont aFont) Creates and returns an XString from a given RTF String.
 - 
getRunAtpublic RMXStringRun getRunAt(int anIndex) Returns the XString run at the given index.
 - 
getRunIndexAtpublic int getRunIndexAt(int anIndex) Returns the XString run index for the given character index.
 - 
getRunAtExactlypublic RMXStringRun getRunAtExactly(int anIndex) Returns an XString run for the given character index, potentially splitting an existing run to ensure that new run starts at the given index.
 - 
getRunIndexAtExactlypublic int getRunIndexAtExactly(int anIndex) Returns an XString segement index for the given character index, potentially splitting an existing run to ensure that new run starts at the given index.
 - 
didChangepublic void didChange() Notifies string that something significant changed. It's mostly for internal use (it's called automatically by most of XStrings modification methods).
 - 
setUnderlinedpublic void setUnderlined(boolean flag) Sets the xstring to be underlined.
 - 
setOutlinedpublic void setOutlined(boolean flag) Sets the xstring to be outlined.
 - 
getAlignpublic byte getAlign() Returns the horizontal alignment of the first paragraph of the xstring.
 - 
setAlignpublic void setAlign(int align) Sets the horizontal alignment of the xstring.
 - 
alignLeftpublic void alignLeft() Aligns the xstring left.
 - 
alignRightpublic void alignRight() Aligns the xstring right.
 - 
alignCenterpublic void alignCenter() Aligns the xstring center.
 - 
getVersionpublic int getVersion() Returns the version of this xstring.
 - 
getRepresentableStringpublic 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).
 - 
clonepublic java.lang.Object clone() Returns a clone of the receiver.
 - 
equalspublic boolean equals(java.lang.Object anObj) Standard Object equals implementation.- Overrides:
- equalsin class- java.lang.Object
 
 - 
rpgClonepublic RMXString rpgClone(ReportMill aReportMill, java.lang.Object userInfo, RMShape aShape) Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.
 - 
blendpublic RMXString blend(RMXString aString, float fraction) Returns a blended version of the receiver and the given string (0 is receiver, 1 is given string). The current implementation actually only blends text color.
 - 
initWithArchiverpublic java.lang.Object initWithArchiver(RMArchiver anArchiver) Legacy archival.- Specified by:
- initWithArchiverin interface- RMArchiver.Archiving
- Overrides:
- initWithArchiverin class- RMObject
 
 - 
toXMLpublic RXElement toXML(RXArchiver anArchiver) XML archival.
 - 
fromXMLpublic java.lang.Object fromXML(RXArchiver anArchiver, RXElement anElement) XML unarchival.
 - 
toStringpublic java.lang.String toString() Returns the String associated with this XString.- Overrides:
- toStringin class- java.lang.Object
 
 - 
toStringXMLpublic java.lang.String toStringXML() Returns an XML style string representation of the attributes and string runs in this XString.
 
- 
 
-