ReportMill 7.0 API

com.reportmill.text
Class RMXString

java.lang.Object
  extended bycom.reportmill.foundation.RMObject
      extended bycom.reportmill.text.RMXString
All Implemented Interfaces:
java.lang.Cloneable, com.reportmill.foundation.RMArchiver.Archiving

public class RMXString
extends com.reportmill.foundation.RMObject

An RMXString is like a String that lets you apply attributes, like fonts and colors, to character ranges. These ranges are represented internally as the inner class Segments. 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 segments like this:

    for(int i=0; i


Nested Class Summary
static class RMXString.Outline
          The Outline inner class represents the attributes of outlined text: strokeWidth and fillColor.
static class RMXString.Segment
          The Segment inner class represents one of the list of character groups having common attributes in an XString.
 
Field Summary
static java.lang.String COLOR_KEY
           
static java.lang.String FONT_KEY
           
static java.lang.String FONT_SCALE_KEY
           
static java.lang.String FORMAT_KEY
           
static java.lang.String OUTLINE_KEY
           
static java.lang.String PARAGRAPH_KEY
           
static java.lang.String SCRIPTING_KEY
           
static java.lang.String UNDERLINE_KEY
           
 
Constructor Summary
RMXString()
          This constructor creates an empty RMXString.
RMXString(java.lang.String aString)
          This constructor creates an RMXString intialized with the given String and no attributes.
RMXString(java.lang.String aString, java.util.Map attrs)
          This constructor creates an RMXString initialized with the given String with all characters set to the given 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 anAttr1, java.lang.Object anAttr2)
          Creates an RMXString initialized with the given String with all characters set to the given two attributes (should be common attribute types like RMFont, RMColor, RMFormat, etc.).
RMXString(java.lang.String aString, java.lang.Object anAttr1, java.lang.Object anAttr2, java.lang.Object anAttr3)
          Creates an RMXString initialized with the given String with all characters set to the given three attributes (should be common attribute types like RMFont, RMColor, RMFormat, etc.).
 
Method Summary
 void add(RMXString xString)
          Appends the given XString to the end of this String.
 void add(RMXString xString, int anIndex)
          Appends the given XString to this XString, at the given index.
 void add(java.lang.String aString)
          Appends the given String to the end of this XString.
 void add(java.lang.String aString, int anIndex)
          Appends the given String to this XString, at the given index.
 void add(java.lang.String aString, java.util.Map attrs)
          Appends the given string to the end of this XString, with the given attributes.
 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.
 void addAttribute(java.lang.Object attr)
          Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).
 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.).
 void addAttribute(java.lang.String aKey, java.lang.Object object)
           
 void addAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end)
           
 void addAttribute(java.lang.String aKey, java.lang.Object attr, int start, int end, boolean ifAbsent)
           
 void addAttributes(java.util.Map attrs, int start, int end)
          Adds the attributes in the given map to the specified character range.
 void addAttributes(java.util.Map attrs, int start, int end, boolean ifAbsent)
          Adds the attributes in the given map to the specified character range.
 void alignCenter()
           
 void alignLeft()
           
 void alignRight()
           
 RMXString blend(RMXString aString, float fraction)
          Returns a blended version of the receiver and the given string (0 is receiver, 1 is given string).
 char charAt(int anIndex)
          Returns the character at the given index.
 java.lang.Object clone()
          Returns a clone of the receiver.
 void coalesceNewlines()
          Replaces any occurrance of consecutive newlines with a single newline.
 void delete(int start, int end)
          Deletes the chars in the given range.
 void didChange()
          This method notifies the string that something significant changed.
 boolean equals(java.lang.Object anObj)
          Standard Object equals implementation.
 java.lang.Object fromXML(com.ribs.RXArchiver anArchiver, com.ribs.RXElement anElement)
          XML unarchival.
 byte getAlign()
           
 java.lang.Object getAttributeAt(java.lang.String aKey, int anIndex)
          Returns the value for the given attribute key at the given character index.
 java.util.Map getAttributes(int anIndex)
          Returns the attributes Map for the segment at the given index.
 java.util.Map getAttributesAt(int anIndex)
          Returns the attributes Map for the segment at the given character index.
 RMColor getColorAtIndex(int index)
          Returns the current color at the given character index.
 RMFont getFontAtIndex(int index)
          Returns the current font at the given character index.
 float getFontScale()
          Returns the value that should be multipied times all font sizes in this string (defaults to 1).
 RMFormat getFormatAtIndex(int index)
          Returns the current format at the given character index.
 RMParagraph getParagraphAtIndex(int index)
          Returns the current paragraph at the given character index.
 RMXString.Segment getSegment(int anIndex)
          Returns the Segment at the given index in this XString.
 int getSegmentCount()
          Returns the number of segments in this XString.
 RMXString.Segment getSegmentLast()
          Returns the last segment in this XString (convenience).
static RMXString getXStringForHTML(java.lang.String html, RMFont aFont)
          Creates and returns an XString from a given HTML String.
static RMXString getXStringForRTF(java.lang.String rtf, RMFont aFont)
          Creates and returns an XString from a given RTF String.
 int indexOf(java.lang.String aString)
          Returns the index within this string of the first occurrence of the given substring.
 int indexOf(java.lang.String aString, int start)
          Returns the index within this string of the first occurrence of the given substring, starting at the given index.
 java.lang.Object initWithArchiver(com.reportmill.foundation.RMArchiver anArchiver)
          Legacy archival.
 int length()
          Returns the number of characters associated with this RMXString.
 void removeAttribute(java.lang.String aKey, int start, int end)
           
 void replace(int start, int end, RMXString xString)
          Replaces the chars in given range, with given XString.
 void replace(int start, int end, java.lang.String aString)
          Replaces chars in given range, with given String.
 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.
 void replace(java.lang.String aString)
          Replaces all chars of this XString with given String.
 RMXString representableString()
          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).
 RMXString representableString(boolean create)
          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).
 RMXString rpgClone(com.reportmill.foundation.ReportMill rm)
          Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.
 RMXString rpgClone(com.reportmill.foundation.ReportMill rm, java.lang.Object userInfo)
          Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.
 RMXString rpgClone(com.reportmill.foundation.ReportMill rm, java.lang.Object userInfo, RMShape aShape)
          Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.
 RMXString.Segment segmentAt(int anIndex)
          Returns the XString segment at the given index.
 RMXString.Segment segmentAtExactly(int anIndex)
          Returns an XString segment for the given character index, potentially splitting an existing segment to ensure that new segment starts at the given index.
 int segmentIndexAt(int anIndex)
          Returns the XString segment index for the given character index.
 int segmentIndexAtExactly(int anIndex)
          Returns an XString segement index for the given character index, potentially splitting an existing segment to ensure that new segment starts at the given index.
 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.
 void setAlign(int align)
           
 void setFontScale(float aScale)
          Sets a value to that should be multiplied times all font sizes in this string.
 void setOutlined(boolean flag)
           
 void setParagraph(RMParagraph ps, int start)
          Sets the paragraph at the given character index.
 void setParagraph(RMParagraph ps, int start, int end)
          Sets the paragraph for the given character index range.
 void setUnderlined(boolean flag)
           
 java.lang.String string()
          Returns the plain String associated with this RMXString.
 RMXString substring(int index)
          Returns the substring from the given index to end of XString.
 RMXString substring(int start, int end)
          Returns the substring from the given start index to the given end index.
 java.lang.String toString()
          Returns the String associated with this XString.
 java.lang.String toStringXML()
          Returns an XML style string representation of the attributes and string segments in this XString.
 com.ribs.RXElement toXML(com.ribs.RXArchiver anArchiver)
          XML archival.
 
Methods inherited from class com.reportmill.foundation.RMObject
archiverClassName, copy, didChange, didUndo, getAnimAttribute, getClassNameShort, undoClone, undoCopy, undoEquals
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FONT_KEY

public static final java.lang.String FONT_KEY
See Also:
Constant Field Values

COLOR_KEY

public static final java.lang.String COLOR_KEY
See Also:
Constant Field Values

FORMAT_KEY

public static final java.lang.String FORMAT_KEY
See Also:
Constant Field Values

UNDERLINE_KEY

public static final java.lang.String UNDERLINE_KEY
See Also:
Constant Field Values

OUTLINE_KEY

public static final java.lang.String OUTLINE_KEY
See Also:
Constant Field Values

PARAGRAPH_KEY

public static final java.lang.String PARAGRAPH_KEY
See Also:
Constant Field Values

FONT_SCALE_KEY

public static final java.lang.String FONT_SCALE_KEY
See Also:
Constant Field Values

SCRIPTING_KEY

public static final java.lang.String SCRIPTING_KEY
See Also:
Constant Field Values
Constructor Detail

RMXString

public RMXString()
This constructor creates an empty RMXString.


RMXString

public RMXString(java.lang.String aString)
This constructor creates an RMXString intialized with the given String and no attributes.


RMXString

public RMXString(java.lang.String aString,
                 java.util.Map attrs)
This constructor creates an RMXString initialized with the given String with all characters set to the given attributes.


RMXString

public 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

public RMXString(java.lang.String aString,
                 java.lang.Object anAttr1,
                 java.lang.Object anAttr2)
Creates an RMXString initialized with the given String with all characters set to the given two attributes (should be common attribute types like RMFont, RMColor, RMFormat, etc.).


RMXString

public RMXString(java.lang.String aString,
                 java.lang.Object anAttr1,
                 java.lang.Object anAttr2,
                 java.lang.Object anAttr3)
Creates an RMXString initialized with the given String with all characters set to the given three attributes (should be common attribute types like RMFont, RMColor, RMFormat, etc.).

Method Detail

string

public java.lang.String string()
Returns the plain String associated with this RMXString.


length

public int length()
Returns the number of characters associated with 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 start)
Returns the index within this string of the first occurrence of the given substring, starting at the given index.


charAt

public char charAt(int anIndex)
Returns the character at the given index.


getSegmentCount

public int getSegmentCount()
Returns the number of segments in this XString.


getSegment

public RMXString.Segment getSegment(int anIndex)
Returns the Segment at the given index in this XString.


getSegmentLast

public RMXString.Segment getSegmentLast()
Returns the last segment in this XString (convenience).


getAttributes

public java.util.Map getAttributes(int anIndex)
Returns the attributes Map for the segment at the given index.


getAttributeAt

public java.lang.Object getAttributeAt(java.lang.String aKey,
                                       int anIndex)
Returns the value for the given attribute key at the given character index.


getAttributesAt

public java.util.Map getAttributesAt(int anIndex)
Returns the attributes Map for the segment at the given character index.


addAttributes

public void addAttributes(java.util.Map attrs,
                          int start,
                          int end)
Adds the attributes in the given map to the specified character range.


addAttributes

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


addAttribute

public void addAttribute(java.lang.String aKey,
                         java.lang.Object object)

addAttribute

public void addAttribute(java.lang.String aKey,
                         java.lang.Object attr,
                         int start,
                         int end)

addAttribute

public void addAttribute(java.lang.String aKey,
                         java.lang.Object attr,
                         int start,
                         int end,
                         boolean ifAbsent)

removeAttribute

public void removeAttribute(java.lang.String aKey,
                            int start,
                            int end)

getFontAtIndex

public RMFont getFontAtIndex(int index)
Returns the current font at the given character index.


getColorAtIndex

public RMColor getColorAtIndex(int index)
Returns the current color at the given character index.


getFormatAtIndex

public RMFormat getFormatAtIndex(int index)
Returns the current format at the given character index.


getParagraphAtIndex

public RMParagraph getParagraphAtIndex(int index)
Returns the current paragraph at the given character index.


setParagraph

public void setParagraph(RMParagraph ps,
                         int start)
Sets the 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.


addAttribute

public void addAttribute(java.lang.Object attr)
Applies the given attribute to whole xstring, assuming it's a basic attr types (font, color, etc.).


addAttribute

public 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.).


getFontScale

public float getFontScale()
Returns the value that should be multipied times all font sizes in this string (defaults to 1).


setFontScale

public void setFontScale(float aScale)
Sets a value to that should be multiplied times all font sizes in this string.


add

public void add(java.lang.String aString)
Appends the given String to the end of this XString.


add

public void add(java.lang.String aString,
                int anIndex)
Appends the given String to this XString, at the given index.


add

public void add(RMXString xString)
Appends the given XString to the end of this String.


add

public void add(RMXString xString,
                int anIndex)
Appends the given XString to this XString, at the given index.


add

public void add(java.lang.String aString,
                java.util.Map attrs)
Appends the given string to the end of this XString, with the given attributes.


add

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


replace

public void replace(java.lang.String aString)
Replaces all chars of this XString with given String.


replace

public void replace(int start,
                    int end,
                    java.lang.String aString)
Replaces chars in given range, with given String.


replace

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


replace

public void replace(int start,
                    int end,
                    RMXString xString)
Replaces the chars in given range, with given XString.


delete

public void delete(int start,
                   int end)
Deletes the chars in the given range.


substring

public RMXString substring(int index)
Returns the substring from the given index to end of XString.


substring

public RMXString substring(int start,
                           int end)
Returns the substring from the given start index to the given end index.


separate

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


coalesceNewlines

public void coalesceNewlines()
Replaces any occurrance of consecutive newlines with a single newline.


getXStringForHTML

public static RMXString getXStringForHTML(java.lang.String html,
                                          RMFont aFont)
Creates and returns an XString from a given HTML String.


getXStringForRTF

public static RMXString getXStringForRTF(java.lang.String rtf,
                                         RMFont aFont)
Creates and returns an XString from a given RTF String.


segmentAt

public RMXString.Segment segmentAt(int anIndex)
Returns the XString segment at the given index.


segmentIndexAt

public int segmentIndexAt(int anIndex)
Returns the XString segment index for the given character index.


segmentAtExactly

public RMXString.Segment segmentAtExactly(int anIndex)
Returns an XString segment for the given character index, potentially splitting an existing segment to ensure that new segment starts at the given index.


segmentIndexAtExactly

public int segmentIndexAtExactly(int anIndex)
Returns an XString segement index for the given character index, potentially splitting an existing segment to ensure that new segment starts at the given index.


didChange

public void didChange()
This method notifies the string that something significant changed. It's mostly for internal use (it's called automatically by most of XStrings modification methods).


setUnderlined

public void setUnderlined(boolean flag)

setOutlined

public void setOutlined(boolean flag)

getAlign

public byte getAlign()

setAlign

public void setAlign(int align)

alignLeft

public void alignLeft()

alignRight

public void alignRight()

alignCenter

public void alignCenter()

representableString

public RMXString representableString()
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).


representableString

public RMXString representableString(boolean create)
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). The boolean option allows the developer to request the uncached value.


clone

public java.lang.Object clone()
Returns a clone of the receiver.


equals

public boolean equals(java.lang.Object anObj)
Standard Object equals implementation.


rpgClone

public RMXString rpgClone(com.reportmill.foundation.ReportMill rm)
Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.


rpgClone

public RMXString rpgClone(com.reportmill.foundation.ReportMill rm,
                          java.lang.Object userInfo)
Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.


rpgClone

public RMXString rpgClone(com.reportmill.foundation.ReportMill rm,
                          java.lang.Object userInfo,
                          RMShape aShape)
Creates a clone of the receiver, with substitution performed on @-sign deliniated keys.


blend

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


initWithArchiver

public java.lang.Object initWithArchiver(com.reportmill.foundation.RMArchiver anArchiver)
Legacy archival.


toXML

public com.ribs.RXElement toXML(com.ribs.RXArchiver anArchiver)
XML archival.


fromXML

public java.lang.Object fromXML(com.ribs.RXArchiver anArchiver,
                                com.ribs.RXElement anElement)
XML unarchival.


toString

public java.lang.String toString()
Returns the String associated with this XString.


toStringXML

public java.lang.String toStringXML()
Returns an XML style string representation of the attributes and string segments in this XString.


ReportMill 7.0 API