PenProfile 2.x

com.livescribe.display
Class AttributedText

java.lang.Object
  extended by com.livescribe.display.AttributedText

public class AttributedText
extends Object

AttributedText contains text that should be rendered with different attributes. The data encapsulated by this object can be viewed as pairs of values:

The method getCount() returns the number of the attribute/text pairs this AttributedText object contains. getAttribute(int) and getText(int) provide access to the attribute and the text, respectively.

The following sample code shows how to render "Attributed text" on the display.

Note: This class is not thread safe.

 AttributedText attrText = new AttributedText();
 Font boldFont = Font.getFont(face, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
 attrText.addText(boldFont, "Attributed ");
 Font italicFont = Font.getFont(face, Font.STYLE_ITALIC, Font.SIZE_MEDIUM);
 attrText.addText(italicFont, "text");
 ScrollLabel label;
 label.draw(attrText, true);
 

Since:
0.5
See Also:
parseEnriched(String, Font), ScrollLabel.draw(AttributedText, boolean)

Nested Class Summary
static class AttributedText.Attribute
          Attribute encapsulates the font attribute associated with the the text in an attribute/text pair.
 
Constructor Summary
AttributedText()
          Constructs an instance of AttributedText.
 
Method Summary
 void addText(AttributedText text)
          Appends the contents of another AttributedText object.
 void addText(Font font, String text)
          Adds the text that should be rendered using the font specified.
 void clear()
          Clears all the attributed text data in this AttributedText object.
 AttributedText.Attribute getAttribute(int index)
          Gets the attribute for the index specified.
 int getCount()
          Returns the number of attribute\text pairs that this AttributedText object contains.
 String getText(int index)
          Gets the text for the index specified.
 String getUnattributedText()
          Returns a string representation of this object.
 void insertText(int index, AttributedText text)
          Inserts the contents of another AttributedText object at the specified index.
 void insertText(int index, Font font, String text)
          Inserts text at the specified index.
static Object parseEnriched(String s, Font font)
          Parses enriched text and returns the string or a new AttributedText, as appropriate.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributedText

public AttributedText()
Constructs an instance of AttributedText.

Method Detail

addText

public void addText(Font font,
                    String text)
Adds the text that should be rendered using the font specified. The text is not added if either the font or the text is null.

Parameters:
font - a Font to be used for rendering the text.
text - the String text to which the attribute will be added.
See Also:
getUnattributedText(), addText(AttributedText)

addText

public void addText(AttributedText text)
Appends the contents of another AttributedText object. This does nothing if the text is null.

Parameters:
text - append the contents of this AttributedText object
Since:
2.5
See Also:
getUnattributedText(), addText(Font, String)

insertText

public void insertText(int index,
                       AttributedText text)
Inserts the contents of another AttributedText object at the specified index. All text at an index greater than or equal to the specified index is shifted to the next spot.

The index must be in the range 0–count, inclusive.

Parameters:
index - insert the text here
text - the attributed text to insert
Throws:
IndexOutOfBoundsException - if the index is not valid.
Since:
2.5
See Also:
getCount(), insertText(int, Font, String)

insertText

public void insertText(int index,
                       Font font,
                       String text)
Inserts text at the specified index. All text at an index greater than or equal to the specified index is shifted to the next spot.

The index must be in the range 0–count, inclusive.

Parameters:
index - insert the text here
font - the font
text - the text to insert
Throws:
IndexOutOfBoundsException - if the index is not valid.
Since:
2.5
See Also:
getCount(), insertText(int, AttributedText)

clear

public void clear()
Clears all the attributed text data in this AttributedText object.


getCount

public int getCount()
Returns the number of attribute\text pairs that this AttributedText object contains.

Returns:
the count.

getAttribute

public AttributedText.Attribute getAttribute(int index)
Gets the attribute for the index specified.

Parameters:
index - index of the attribute.
Returns:
the AttributedText.Attribute object at the index specified; or null if the index is invalid.

getText

public String getText(int index)
Gets the text for the index specified.

Parameters:
index - attribute index.
Returns:
the text at the index specified; or null if the index is invalid.

getUnattributedText

public String getUnattributedText()
Returns a string representation of this object. This returns a simple concatenation of all the text elements without attributes.

Returns:
a concatenation of all the unattributed text elements.
Since:
2.3
See Also:
addText(Font, String)

toString

public String toString()
Returns a string representation of this object. This currently returns the same thing as getUnattributedText(). Note that this behavior may change in the future.

Overrides:
toString in class Object
Returns:
a concatenation of all the unattributed text elements.

parseEnriched

public static Object parseEnriched(String s,
                                   Font font)
Parses enriched text and returns the string or a new AttributedText, as appropriate. If the string does not contain correct enriched text then this will just return the given string object.

If a null font is given, then the default will be used.

This currently supports bold with the <b></b> tags and italic with the <i></i> tags. Note that these are not necessarily supported by all fonts. In these cases, the plain version of the font may be used.

Parameters:
s - parse this string
font - the font, null for the default
Returns:
a String or AttributedText object after parsing the specified enriched text string.
Since:
2.3
See Also:
Font.getFont(int, int, int), Font.getFont(String, int, int), Font, RFC 1896 - The text/enriched MIME Content-type

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.