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

java.lang.Object
  extended by edu.northwestern.at.utils.swing.styledtext.StyledStringUtils

public class StyledStringUtils
extends java.lang.Object

Styled text utilities.

This static class provides various utility methods for manipulating styled strings, including reading and writing styled strings to files.


Constructor Summary
StyledStringUtils()
           
 
Method Summary
static StyledString emboldenText(java.lang.String s)
          Create bold string.
static StyledString getStyledStringFromRTFTransferable(java.awt.datatransfer.Transferable transferable)
          Get styled string from transferable containing RTF.
static StyledString italicizeText(java.lang.String s)
          Create italicized string.
static StyledString makeStyledText(java.lang.String s, int styleType)
          Create styled text string.
static StyledString makeStyledText(java.lang.String s, int[][] styleTypes)
          Create multiply styled text string.
static StyledString readFile(java.io.File file)
          Reads styled text from a file.
static StyledString readFile(java.lang.String fileName)
          Reads styled text from a file.
static java.lang.String toHTML(StyledString styledString)
          Convert string containing styled text to HTML.
static java.lang.String toRTF(StyledString styledString)
          Convert string containing styled text to RTF.
static StyledString underlineText(java.lang.String s)
          Create underline string.
static boolean writeFile(java.io.File file, StyledString styledString)
          Writes styled text to a file.
static boolean writeFile(java.lang.String fileName, StyledString styledString)
          Writes styled text to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyledStringUtils

public StyledStringUtils()
Method Detail

makeStyledText

public static StyledString makeStyledText(java.lang.String s,
                                          int styleType)
Create styled text string.

Parameters:
s - Text to which to apply style.
styleType - Type of style to apply. The available style types are defined in StyleRun.
Returns:
The styled text as a StyledString.

makeStyledText

public static StyledString makeStyledText(java.lang.String s,
                                          int[][] styleTypes)
Create multiply styled text string.

Parameters:
s - Text to which to apply style.
styleTypes - Integer array of styles to apply. The available style types are defined in StyleRun.
Returns:
The styled text as a StyledString.

emboldenText

public static StyledString emboldenText(java.lang.String s)
Create bold string.

Parameters:
s - Text to embolden.
Returns:
The emboldened text as a StyledString.

italicizeText

public static StyledString italicizeText(java.lang.String s)
Create italicized string.

Parameters:
s - Text to italicize.
Returns:
The italicized text as a StyledString.

underlineText

public static StyledString underlineText(java.lang.String s)
Create underline string.

Parameters:
s - Text to underline
Returns:
The underlined text as a StyledString.

getStyledStringFromRTFTransferable

public static StyledString getStyledStringFromRTFTransferable(java.awt.datatransfer.Transferable transferable)
Get styled string from transferable containing RTF.

Parameters:
transferable - The transferable with RTF text.
Returns:
The RTF text as a StyledString.

toRTF

public static java.lang.String toRTF(StyledString styledString)
Convert string containing styled text to RTF.

Parameters:
styledString - The styled string.
Returns:
RTF text of object.

toHTML

public static java.lang.String toHTML(StyledString styledString)
Convert string containing styled text to HTML.

Parameters:
styledString - The styled string.
Returns:
HTML text of object.

writeFile

public static boolean writeFile(java.io.File file,
                                StyledString styledString)
Writes styled text to a file.

Parameters:
file - The file to which to write the styled text. The styled string is written as a series of bytes to the specified file.
styledString - The styled string.
Returns:
True if the file was written successfully, false otherwise.

The file format is a byte stream with the following consecutive entries.

Header marker Four bytes containing "s", "t", "x", "t".
Version number Integer containing version number of Styled String file format.
Plain text in UTF-8 format String containing the plain unstyled text.
Style Information StyleInfo encoded as series of StyleRun entries, preceded by the number of entries.

writeFile

public static boolean writeFile(java.lang.String fileName,
                                StyledString styledString)
Writes styled text to a file.

Parameters:
fileName - The file to which to write the styled text. The styled string is written as an object stream to the specified file.
Returns:
True if the file was written successfully, false otherwise.

readFile

public static StyledString readFile(java.lang.String fileName)
Reads styled text from a file.

Parameters:
fileName - The file to read from.
Returns:
The styled string containing the contents of the file. Null if not a valid styled text file.

readFile

public static StyledString readFile(java.io.File file)
Reads styled text from a file.

Parameters:
file - The file to read from.
Returns:
The styled string containing the contents of the file. Null if not a valid styled text file.