com.zion.jbuddy.richcontent
Class RichContent

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

public final class RichContent
extends Object
implements Serializable

Represents rich content, including styled text and hyperlinks. Methods in this class are used to create rich content.

Some methods return the RichContent object itself. Thus, calls to these methods may be chained together:

RichContent content = new RichContent(); content.setBold(true).append("This is bold. ").setBold(false); content.setItalic(true).append("This is italic. ").setItalic(false); content.setUnderline(true).append("This is underlined. ").setUnderline(false); content.setFont("Arial").setFontSize(12).append("This is Arial 12. ").resetAttributes(); content.setUrl("http://www.url.com").append("This is a hyperlink.").setUrl(null);

RichContent can be sent in an IMessage through an IClient or IConference (though not all protocols support each attribute). The content and attributes of rich content can be traversed using a RichContentTokenizer.

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

Since:
5.0
See Also:
IMessageFactory.factory(int type, com.zion.jbuddy.IClient client, String recipient, RichContent richContent), IMessageFactory.factory(int type, com.zion.jbuddy.conference.IConference conference, RichContent richContent), RichContentTokenizer, Serialized Form

Constructor Summary
RichContent()
          Creates a new RichContent object.
 
Method Summary
 RichContent append(RichContent content)
          Appends existing rich content to this content.
 RichContent append(String text)
          Appends text to this content.
 RichContent clear()
          Clears all existing content.
 Object clone()
          Returns a new RichContent object that is equal to this one.
 boolean equals(Object object)
          Returns true if the specified object is a RichContent object and contains the same text and attributes as this one.
 boolean isEmpty()
          Returns true if there is no content.
 int length()
          Returns the length of this content (in characters).
 void parseXml(String xml)
          Sets this RichContent's contents from the specified XML representation.
 RichContent resetAttributes()
          Resets all attributes.
 RichContent setBackgroundColor(int color)
          Sets the background color for new text.
 RichContent setBold(boolean isBold)
          Sets whether new text will be bold.
 RichContent setColor(int color)
          Sets the foreground color for new text.
 RichContent setFont(String font)
          Sets the font face for new text.
 RichContent setFontSize(int size)
          Sets the font size for new text.
 RichContent setItalic(boolean isItalic)
          Sets whether new text will be italic.
 RichContent setStrikeThrough(boolean isStrikeThrough)
          Sets whether new text will have a strike-through effect.
 RichContent setSubscript(boolean isSubscript)
          Sets whether new text will be subscript.
 RichContent setSuperscript(boolean isSuperscript)
          Sets whether new text will be superscript.
 RichContent setUnderline(boolean isUnderline)
          Sets whether new text will be underlined.
 RichContent setUrl(String url)
          Sets the hyperlink URL for new text.
 String toString()
          Returns the text contents of this RichContent object.
 String toXml()
          Returns an XML representation of this RichContent object.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RichContent

public RichContent()
Creates a new RichContent object.

Method Detail

setColor

public RichContent setColor(int color)
Sets the foreground color for new text. The color is represented by RGB hex. Bits 16-23 are red, 8-15 are green, and 0-7 are blue (0xRRGGBB). Specifying a negative value clears the foreground color.


setBackgroundColor

public RichContent setBackgroundColor(int color)
Sets the background color for new text. The color is represented by RGB hex. Bits 16-23 are red, 8-15 are green, and 0-7 are blue (0xRRGGBB). Specifying a negative value clears the background color.


setFont

public RichContent setFont(String font)
Sets the font face for new text. Specifying a null or empty value clears the font face.


setFontSize

public RichContent setFontSize(int size)
Sets the font size for new text. Specifying a negative value clears the font size.


setUrl

public RichContent setUrl(String url)
Sets the hyperlink URL for new text. Specifying a null or empty value clears the URL.


setBold

public RichContent setBold(boolean isBold)
Sets whether new text will be bold.


setItalic

public RichContent setItalic(boolean isItalic)
Sets whether new text will be italic.


setStrikeThrough

public RichContent setStrikeThrough(boolean isStrikeThrough)
Sets whether new text will have a strike-through effect. Strike-through text is displayed with a horizontal line through it.


setSubscript

public RichContent setSubscript(boolean isSubscript)
Sets whether new text will be subscript. Subscript is displayed slightly below the baseline of normal text.


setSuperscript

public RichContent setSuperscript(boolean isSuperscript)
Sets whether new text will be superscript. Superscript is displayed slightly above the baseline of normal text.


setUnderline

public RichContent setUnderline(boolean isUnderline)
Sets whether new text will be underlined.


append

public RichContent append(RichContent content)
Appends existing rich content to this content. The new content will retain its own attributes (and not inherit attributes which have been set on this RichContent object). This RichContent's attributes will remain unchanged.


append

public RichContent append(String text)
Appends text to this content. The text will inherit any attributes which have been set on this RichContent object, such as bold, italic, color, font, or font size.


length

public int length()
Returns the length of this content (in characters). All attributes and encoding are ignored.

Since:
6.0

isEmpty

public boolean isEmpty()
Returns true if there is no content.

Since:
6.0

parseXml

public void parseXml(String xml)
              throws Exception
Sets this RichContent's contents from the specified XML representation. Existing contents are first cleared and attributes are reset.

Throws:
Exception

toXml

public String toXml()
Returns an XML representation of this RichContent object.


resetAttributes

public RichContent resetAttributes()
Resets all attributes. New text will not have any attributes associated with it.


clear

public RichContent clear()
Clears all existing content. Any attributes which have been set will remain unchanged.


clone

public Object clone()
Returns a new RichContent object that is equal to this one.

Overrides:
clone in class Object

equals

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

Overrides:
equals in class Object

toString

public String toString()
Returns the text contents of this RichContent object. All attributes are ignored.

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.