ymsg.support
Class MutableMessageElement

Object
  extended byMessageElement
      extended byMutableMessageElement
All Implemented Interfaces:
Collection, Emoticons, List

public class MutableMessageElement
extends MessageElement
implements List

A mutable object model element which can be output as a Yahoo IM or chat encoded message. This object is akin to a DOM element, acting as a container in the case of style types like bold, colours and fades; and a leaf in the case of texts.


	Root
	 |
	 +--Bold
	 |   |
	 |   +--Text ("Hello ")
	 |
	 +--Text ("world!")
	

The above four node'd tree, for example, would represent "Hello world!"

This class implements the interface java.util.List and contains all its list manipulation methods. Use these to add and remove MutableMessageElement nodes to form a tree.

Please do not include classes other than MutableMessageElement (or a subclass) as nodes when building a tree. Future implementations may employ Java 1.5's generics to enforce this restriction.

Note: Yahoo appears to be in the process of changing over its escape based encoding scheme to something a little like XML tags. So far examples of the new scheme have only been seen on chatrooms. At some point this class should be modified to allow the switching between 'old' and 'new' encoding styles...

Name Old New
Bold [esc]1m <b>
Italic [esc]2m <i>
Colour (enum) [esc]3?m <'colour name'>
Colour (abs) [esc]3#RRGGBBm <#RRGGBB>
Font   <font ... >
Fade   <fade ... >
Alt   <alt ... >

Note: Yahoo's colour escape codes do not work as containers - that is to say they do not have a close 'code' which undoes their effect. For as long as Yahoo uses escape codes rather than proper SGML-style containers (<abc>...</abc>) this code offers overloaded methods to 'fake' containers via a stack of colours, so that 'pseudo' end codes can be added by simply repeating the colour code above the 'closing' element in the stack.

Since:
1.0

Field Summary
 
Fields inherited from class MessageElement
ALT, BOLD, COLOUR_ABS, COLOUR_INDEX, COLOUR_NAME, FADE, FONT, ITALIC, NULL, ROOT, TEXT, UNDERLINE
 
Fields inherited from interface Emoticons
ALIEN, ANGEL, ANGER, APPLAUSE, BEAT_UP, BLUSH, BRING_IT_ON, BROKEN_HEART, BUG, CHATTERBOX, CHICKEN, CLOWN, COFFEE, CONFUSED, COOL, COW, COWBOY, CRYING, DANCING, DEVILISH, DOH, DROOLING, EMOTICONS, EYEBROW, EYELASHES, FLAG, FRUSTRATED, GO_ON, GOOD_LUCK, GRIN, HUGS, HYPNOTIZED, IDEA, KISS, LAUGHING, LIAR_LIAR, LOSER, LOVE_STRUCK, MONEY_EYES, MONKEY, NAIL_BITING, NERD, NOT_TALKING, NOT_WORTHY, PARTY, PEACE, PHBBBBT, PIG, PRAYING, PUMPKIN, ROFL, ROLLING_EYES, ROSE, SAD, SHAME_ON_YOU, SHHH, SHOCK, SICK, SIGH, SILLY, SKULL, SLEEP, SMILE, SMUG, STAR, STRAIGHT_FACE, TALK_TO_HAND, TEE_HEE, THINKING, TIRED, TONGUE, WAITING, WHEW, WHISTLING, WINK, WORRIED
 
Constructor Summary
MutableMessageElement()
           
 
Method Summary
static MutableMessageElement createAbsoluteColour(Color c)
          Creates a new MutableMessageElement defined as a colour element.
static MutableMessageElement createAlt(Color[] c)
          Creates a new MutableMessageElement defined as a alt element.
static MutableMessageElement createBold()
          Creates a new MutableMessageElement defined as a bold element.
static MutableMessageElement createFade(Color[] c)
          Creates a new MutableMessageElement defined as a fade element.
static MutableMessageElement createFont(Font f)
          Creates a new MutableMessageElement defined as a font element.
static MutableMessageElement createIndexedColour(int idx)
          Creates a new MutableMessageElement defined as a colour element.
static MutableMessageElement createItalic()
          Creates a new MutableMessageElement defined as a italic element.
static MutableMessageElement createNamedColour(String n)
          Creates a new MutableMessageElement defined as a colour element.
static MutableMessageElement createRoot()
          Creates a new MutableMessageElement defined as a root element.
static MutableMessageElement createText(String text)
          Creates a new MutableMessageElement defined as a text element.
static MutableMessageElement createUnderline()
          Creates a new MutableMessageElement defined as a underline element.
 Color getAbsoluteColour()
          Returns the content from an absolute colour element.
 Font getFont()
          Returns the content from a font element.
 int getIndexedColour()
          Returns the content from an index colour element.
 String getNamedColour()
          Returns the content from a named colour element.
 String getText()
          Returns the content from a text element.
 Color[] getTransition()
          Returns the content from a fade or alt element.
 int getType()
          Returns the type of this element.
 void setAbsoluteColour(Color c)
          Sets content in an absolute colour element.
 void setFont(Font f)
          Sets content in a font element.
 void setIndexedColour(int i)
          Sets content in an indexed colour element.
 void setNamedColour(String n)
          Sets content in a named colour element.
 void setText(String t)
          Sets content in a text element.
 void setTransition(Color[] c)
          Sets content in a fade or alt element.
 String toYahooChat()
          Translates this message structure (from this node down) into a Yahoo chat message.
 String toYahooChat(boolean fc)
          Translates this message structure (from this node down) into a Yahoo chat message.
 String toYahooIM()
          Translates this message structure (from this node down) into a Yahoo instant message.
 String toYahooIM(boolean fc)
          Translates this message structure (from this node down) into a Yahoo instant message.
 
Methods inherited from class MessageElement
appendToDocument, toHTML, toString, toText
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
 

Constructor Detail

MutableMessageElement

public MutableMessageElement()
Method Detail

createRoot

public static MutableMessageElement createRoot()
Creates a new MutableMessageElement defined as a root element.

Returns:
root container
Since:
1.0

createText

public static MutableMessageElement createText(String text)
Creates a new MutableMessageElement defined as a text element.

Parameters:
text - text content
Returns:
text element
Since:
1.0

createBold

public static MutableMessageElement createBold()
Creates a new MutableMessageElement defined as a bold element.

Returns:
bold container
Since:
1.0

createItalic

public static MutableMessageElement createItalic()
Creates a new MutableMessageElement defined as a italic element.

Returns:
italic container
Since:
1.0

createIndexedColour

public static MutableMessageElement createIndexedColour(int idx)
Creates a new MutableMessageElement defined as a colour element.

Parameters:
idx - Yahoo colour index
Returns:
colour container
Since:
1.0

createNamedColour

public static MutableMessageElement createNamedColour(String n)
Creates a new MutableMessageElement defined as a colour element.

Parameters:
n - Yahoo colour name
Returns:
colour container
Since:
1.0

createAbsoluteColour

public static MutableMessageElement createAbsoluteColour(Color c)
Creates a new MutableMessageElement defined as a colour element.

Parameters:
c - absolute colour as AWT Color
Returns:
colour container
Since:
1.0

createUnderline

public static MutableMessageElement createUnderline()
Creates a new MutableMessageElement defined as a underline element.

Returns:
underline container
Since:
1.0

createFont

public static MutableMessageElement createFont(Font f)
Creates a new MutableMessageElement defined as a font element.

Parameters:
f - AWT font object
Returns:
font container
Since:
1.0

createFade

public static MutableMessageElement createFade(Color[] c)
Creates a new MutableMessageElement defined as a fade element.

Parameters:
c - array of AWT Color objects
Returns:
fade container
Since:
1.0

createAlt

public static MutableMessageElement createAlt(Color[] c)
Creates a new MutableMessageElement defined as a alt element.

Parameters:
c - array of AWT Color objects
Returns:
alt container
Since:
1.0

getType

public int getType()
Returns the type of this element. See the public data members in this class's parent, MessageElement, for a list of possible return values.

Returns:
element type
Since:
1.0

getText

public String getText()
                         throws IllegalStateException
Returns the content from a text element.

Returns:
content text
Throws:
IllegalStateException - if not a text element
Since:
1.0

setText

public void setText(String t)
             throws IllegalStateException
Sets content in a text element.

Parameters:
t - content text
Throws:
IllegalStateException - if not a text element
Since:
1.0

getIndexedColour

public int getIndexedColour()
                     throws IllegalStateException
Returns the content from an index colour element.

Returns:
content index
Throws:
IllegalStateException - if not an index colour element
Since:
1.0

setIndexedColour

public void setIndexedColour(int i)
                      throws IllegalStateException
Sets content in an indexed colour element.

Parameters:
i - content index
Throws:
IllegalStateException - if not an index colour element
Since:
1.0

getNamedColour

public String getNamedColour()
                                throws IllegalStateException
Returns the content from a named colour element.

Returns:
content name
Throws:
IllegalStateException - if not a named colour element
Since:
1.0

setNamedColour

public void setNamedColour(String n)
                    throws IllegalStateException
Sets content in a named colour element.

Parameters:
n - content name
Throws:
IllegalStateException - if not a named colour element
Since:
1.0

getAbsoluteColour

public Color getAbsoluteColour()
                                 throws IllegalStateException
Returns the content from an absolute colour element.

Returns:
content AWT Color
Throws:
IllegalStateException - if not an absolute colour element
Since:
1.0

setAbsoluteColour

public void setAbsoluteColour(Color c)
                       throws IllegalStateException
Sets content in an absolute colour element.

Parameters:
c - content AWT Color
Throws:
IllegalStateException - if not an absolute colour element
Since:
1.0

getFont

public Font getFont()
                      throws IllegalStateException
Returns the content from a font element.

Returns:
content AWT Font
Throws:
IllegalStateException - if not a font element
Since:
1.0

setFont

public void setFont(Font f)
             throws IllegalStateException
Sets content in a font element.

Parameters:
f - content AWT Font
Throws:
IllegalStateException - if not a font element
Since:
1.0

getTransition

public Color[] getTransition()
                               throws IllegalStateException
Returns the content from a fade or alt element.

Returns:
content AWT Color array
Throws:
IllegalStateException - if not a fade or alt element
Since:
1.0

setTransition

public void setTransition(Color[] c)
                   throws IllegalStateException
Sets content in a fade or alt element.

Parameters:
c - content AWT Color array
Throws:
IllegalStateException - if not a fade or alt element
Since:
1.0

toYahooIM

public String toYahooIM()
Translates this message structure (from this node down) into a Yahoo instant message. Uncloseable containers are left open.

Returns:
message text
Since:
1.0

toYahooIM

public String toYahooIM(boolean fc)
Translates this message structure (from this node down) into a Yahoo instant message. Uncloseable containers may be faked closed.

Old Yahoo colour encodings use escape codes, not SGML-style containers, and as such there is no closing 'tag' to revert to the enclosing colour. But the effect of a closing tag can be 'faked' by simply re-including the parent escape code as a pseudo closing tag, to set the colour back to the parent.

Note: when Yahoo moves entirely to SGML-style message encoding, and drops support from escape codes, it may be possible to deprecate this method.

Parameters:
fc - true will force containers closed
Returns:
message text
Since:
1.0

toYahooChat

public String toYahooChat()
Translates this message structure (from this node down) into a Yahoo chat message. Uncloseable containers are left open.

Returns:
message text
Since:
1.0

toYahooChat

public String toYahooChat(boolean fc)
Translates this message structure (from this node down) into a Yahoo chat message. Uncloseable containers may be faked closed.

Old Yahoo colour encodings use escape codes, not SGML-style containers, and as such there is no closing 'tag' to revert to the enclosing colour. But the effect of a closing tag can be 'faked' by simply re-including the parent escape code as a pseudo closing tag, to set the colour back to the parent.

Note: when Yahoo moves entirely to SGML-style message encoding, and drops support from escape codes, it may be possible to deprecate this method.

Parameters:
fc - true will force containers closed
Returns:
message text
Since:
1.0