com.zion.jbuddy.richcontent
Class RichContentTokenizer

java.lang.Object
  extended by com.zion.jbuddy.richcontent.RichContentTokenizer
All Implemented Interfaces:
Serializable

public final class RichContentTokenizer
extends Object
implements Serializable

Traverses the content and attributes of RichContent.

Example usage:

RichContent content = ...; RichContentTokenizer tokenizer = new RichContentTokenizer(content); while (tokenizer.hasMoreTokens()) { int type = tokenizer.nextToken(); switch (type) { case RichContentTokenizer.FONT: // the font changed String font = tokenizer.getFont(); break; case RichContentTokenizer.COLOR: // the text color changed int color = tokenizer.getColor(); break; case RichContentTokenizer.BOLD: // the bold value changed boolean isBold = tokenizer.isBold(); break; case RichContentTokenizer.TEXT: // got some text String text = tokenizer.getText(); break; } }

All methods in this class are synchronized and thread-safe.

Since:
5.0
See Also:
RichContent, Serialized Form

Field Summary
static int BACKGROUND_COLOR
          A token type.
static int BOLD
          A token type.
static int COLOR
          A token type.
static int FONT
          A token type.
static int FONT_SIZE
          A token type.
static int ITALIC
          A token type.
static int STRIKE_THROUGH
          A token type.
static int SUBSCRIPT
          A token type.
static int SUPERSCRIPT
          A token type.
static int TEXT
          A token type.
static int UNDERLINE
          A token type.
static int URL
          A token type.
 
Constructor Summary
RichContentTokenizer(RichContent content)
          Creates a RichContentTokenizer that traverses over the specified content.
 
Method Summary
 int countTokens()
          Calculates the number of times that nextToken() can be called before it throws a NoSuchElementException.
 boolean equals(Object v)
          Returns true if the specified object is a RichContentTokenizer object and is traversing the same text and attributes as this one.
 int getBackgroundColor()
          Returns the current token's background color.
 int getColor()
          Returns the current token's color.
 String getFont()
          Returns the current token's font face.
 int getFontSize()
          Returns the current token's font size.
 String getText()
          Returns the current token's text.
 String getUrl()
          Returns the current token's hyperlink URL.
 boolean hasMoreTokens()
          Returns true if there are more tokens available.
 boolean isBold()
          Returns whether the current token is bold.
 boolean isItalic()
          Returns whether the current token is italic.
 boolean isStrikeThrough()
          Returns whether the current token has a strike-through effect.
 boolean isSubscript()
          Returns whether the current token is subscript.
 boolean isSuperscript()
          Returns whether the current token is superscript.
 boolean isUnderline()
          Returns whether the current token is underlined.
 int nextToken()
          Retrieves the next token and returns its type.
 String toString()
          Returns a string representation of this tokenizer.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT

public static final int TEXT
A token type. The current token is text content.

See Also:
getText(), nextToken(), Constant Field Values

COLOR

public static final int COLOR
A token type. The color has changed.

See Also:
getColor(), nextToken(), Constant Field Values

BACKGROUND_COLOR

public static final int BACKGROUND_COLOR
A token type. The background color has changed.

See Also:
getBackgroundColor(), nextToken(), Constant Field Values

FONT

public static final int FONT
A token type. The font has changed.

See Also:
getFont(), nextToken(), Constant Field Values

FONT_SIZE

public static final int FONT_SIZE
A token type. The font size has changed.

See Also:
getFontSize(), nextToken(), Constant Field Values

URL

public static final int URL
A token type. The hyperlink URL has changed.

See Also:
getUrl(), nextToken(), Constant Field Values

BOLD

public static final int BOLD
A token type. The bold value has changed.

See Also:
isBold(), nextToken(), Constant Field Values

ITALIC

public static final int ITALIC
A token type. The italic value has changed.

See Also:
isItalic(), nextToken(), Constant Field Values

STRIKE_THROUGH

public static final int STRIKE_THROUGH
A token type. The strike-through value has changed.

See Also:
isStrikeThrough(), nextToken(), Constant Field Values

SUBSCRIPT

public static final int SUBSCRIPT
A token type. The subscript value has changed.

See Also:
isSubscript(), nextToken(), Constant Field Values

SUPERSCRIPT

public static final int SUPERSCRIPT
A token type. The superscript value has changed.

See Also:
isSuperscript(), nextToken(), Constant Field Values

UNDERLINE

public static final int UNDERLINE
A token type. The underline value has changed.

See Also:
isUnderline(), nextToken(), Constant Field Values
Constructor Detail

RichContentTokenizer

public RichContentTokenizer(RichContent content)
Creates a RichContentTokenizer that traverses over the specified content.

Method Detail

nextToken

public int nextToken()
Retrieves the next token and returns its type. Use the appropriate method to retrieve the token's value according to its type. For example, if the token type is TEXT, call getText() to retrieve its value.

See the documentation for the static types in this class for more information.


hasMoreTokens

public boolean hasMoreTokens()
Returns true if there are more tokens available. If false, calling nextToken() will throw a NoSuchElementException.


countTokens

public int countTokens()
Calculates the number of times that nextToken() can be called before it throws a NoSuchElementException.


getText

public String getText()
Returns the current token's text.


getColor

public int getColor()
Returns the current token's color. The color is represented by RGB hex. Bits 16-23 are red, 8-15 are green, and 0-7 are blue (0xRRGGBB).

Returns:
the color, or -1 if there is no color

getBackgroundColor

public int getBackgroundColor()
Returns the current token's background color. The color is represented by RGB hex. Bits 16-23 are red, 8-15 are green, and 0-7 are blue (0xRRGGBB).

Returns:
the background color, or -1 if there is no background color

getFont

public String getFont()
Returns the current token's font face.

Returns:
the font face, or "" if there is no font face

getFontSize

public int getFontSize()
Returns the current token's font size.

Returns:
the font size, or -1 if there is no font size

getUrl

public String getUrl()
Returns the current token's hyperlink URL.

Returns:
the URL, or "" if there is no URL

isBold

public boolean isBold()
Returns whether the current token is bold.


isItalic

public boolean isItalic()
Returns whether the current token is italic.


isStrikeThrough

public boolean isStrikeThrough()
Returns whether the current token has a strike-through effect.


isSubscript

public boolean isSubscript()
Returns whether the current token is subscript.


isSuperscript

public boolean isSuperscript()
Returns whether the current token is superscript.


isUnderline

public boolean isUnderline()
Returns whether the current token is underlined.


equals

public boolean equals(Object v)
Returns true if the specified object is a RichContentTokenizer object and is traversing the same text and attributes as this one.

Overrides:
equals in class Object

toString

public String toString()
Returns a string representation of this tokenizer.

Overrides:
toString in class Object


JBuddy is a trademark of Zion Software, LLC in the US and other countries.
Copyright 2000-2012 Zion Software, LLC All Rights Reserved.