edu.northwestern.at.utils.swing.styledtext
Class StyledString

java.lang.Object
  extended by edu.northwestern.at.utils.swing.styledtext.StyledString
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable, java.lang.Cloneable

public class StyledString
extends java.lang.Object
implements java.io.Serializable, java.awt.datatransfer.Transferable, java.lang.Cloneable

A styled string.

A styled string is a string plus style information. Styled strings are transferable objects with three flavors: plain text, styled text, and RTF.

See Also:
Serialized Form

Field Summary
static java.awt.datatransfer.DataFlavor RTF_FLAVOR
          Richtext format data flavor.
 java.lang.String str
          The string.
static java.awt.datatransfer.DataFlavor STYLED_STRING_FLAVOR
          Styled string data flavor.
 StyleInfo styleInfo
          The style information.
 
Constructor Summary
StyledString()
          Constructs a new empty styled string.
StyledString(java.lang.String str)
          Constructs a new plain text styled string.
StyledString(java.lang.StringBuffer strBuffer)
          Constructs a new plain text styled string.
StyledString(java.lang.String str, StyleInfo styleInfo)
          Constructs a new styled string.
 
Method Summary
 java.lang.Object clone()
          Returns a copy of the styled string.
 boolean equals(java.lang.Object obj)
          Compares this styled string to another styled string.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
          Gets the transfer data for a flavor.
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          Returns the supported data flavors.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
          Returns true if a data flavor is supported.
 int length()
          Returns the length of the string.
 java.lang.String toString()
          Returns a plain string representation.
 void trim()
          Trims leading and trailing whitespace.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STYLED_STRING_FLAVOR

public static final java.awt.datatransfer.DataFlavor STYLED_STRING_FLAVOR
Styled string data flavor.


RTF_FLAVOR

public static final java.awt.datatransfer.DataFlavor RTF_FLAVOR
Richtext format data flavor.


str

public java.lang.String str
The string.


styleInfo

public StyleInfo styleInfo
The style information.

Constructor Detail

StyledString

public StyledString()
Constructs a new empty styled string.


StyledString

public StyledString(java.lang.String str,
                    StyleInfo styleInfo)
Constructs a new styled string.

Parameters:
str - The string.
styleInfo - The style information.

StyledString

public StyledString(java.lang.String str)
Constructs a new plain text styled string.

Parameters:
str - The string.

StyledString

public StyledString(java.lang.StringBuffer strBuffer)
Constructs a new plain text styled string.

Parameters:
strBuffer - The string.
Method Detail

trim

public void trim()
Trims leading and trailing whitespace.


equals

public boolean equals(java.lang.Object obj)
Compares this styled string to another styled string.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The other styled string.
Returns:
True if the two styled strings are equal.

length

public int length()
Returns the length of the string.

Returns:
The length of the plain text.

toString

public java.lang.String toString()
Returns a plain string representation.

Overrides:
toString in class java.lang.Object
Returns:
The plain string.

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Returns the supported data flavors.

The supported data flavors are STYLED_STRING_FLAVOR (the full styled string), RTF_FLAVOR (the rich text format flavor), and DataFlavor.stringFlavor (the plain text string without the style information).

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable
Returns:
The array of supported data flavors.

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Returns true if a data flavor is supported.

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable
Parameters:
flavor - The data flavor.
Returns:
True if the flavor is supported.

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Gets the transfer data for a flavor.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Parameters:
flavor - The data flavor.
Returns:
The transfer data.
Throws:
java.awt.datatransfer.UnsupportedFlavorException - The flavor is unsupported.
java.io.IOException

clone

public java.lang.Object clone()
Returns a copy of the styled string.

Overrides:
clone in class java.lang.Object
Returns:
The copy.