de.enough.polish.util
Class WrappedText

java.lang.Object
  extended by de.enough.polish.util.WrappedText
All Implemented Interfaces:
Externalizable, Serializable

public class WrappedText
extends Object
implements Externalizable

Contains wrapped text and additional meta information about it.

Copyright Enough Software 2010

Author:
Robert Virkus, j2mepolish@enough.de

Constructor Summary
WrappedText()
          Creates a new wrapped text object
WrappedText(WrappedText original)
          Creates a new wrapped text object by copying values from the given one
 
Method Summary
 void addAll(WrappedText original)
          Adds all content from the given wrapped text
 void addLine(String line, int width)
          Adds a wrapped line
 void clear()
          Clears this list.
 String getLine(int index)
          Retrieves the line at the specified index
 String[] getLines()
          Retrieves the lines of this wrapped text
 Object[] getLinesInternalArray()
          Retrieves the lines of this wrapped text
 int getLineWidth(int index)
          Retrieves the line width at the specified index
 int[] getLineWidths()
          Retrieves the widths of the lines of this wrapped text
 int[] getLineWidthsInternalArray()
          Retrieves the widths of lines of this wrapped text.
 int getMaxLineWidth()
          Retrieves the maximum line width
 void read(DataInputStream in)
          Restores the internal instance fields from the given input stream.
 void removeLine(int index)
          Removes the specified line
 void setLine(int index, String line)
          Sets a line without changing it's width
 void setLine(int index, String line, int width)
          Sets a line
 void setMaxLineWidth(int width)
          Sets a the width of the widest line within this wrapped text.
 int size()
          Retrieves the number of text lines in this wrapped text
 void write(DataOutputStream out)
          Stores the internal instance fields to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappedText

public WrappedText()
Creates a new wrapped text object


WrappedText

public WrappedText(WrappedText original)
Creates a new wrapped text object by copying values from the given one

Parameters:
original - the wrapped text that should be copied
Method Detail

addAll

public void addAll(WrappedText original)
Adds all content from the given wrapped text

Parameters:
original - the wrapped text that should be copied into this one

addLine

public void addLine(String line,
                    int width)
Adds a wrapped line

Parameters:
line - the line
width - the width of the line

setLine

public void setLine(int index,
                    String line)
Sets a line without changing it's width

Parameters:
index - index of the line
line - the line

setLine

public void setLine(int index,
                    String line,
                    int width)
Sets a line

Parameters:
index - index of the line
line - the line
width - the width of the line

clear

public void clear()
Clears this list.


getLines

public String[] getLines()
Retrieves the lines of this wrapped text

Returns:
an array of the lines, can be empty but not null

getLinesInternalArray

public Object[] getLinesInternalArray()
Retrieves the lines of this wrapped text

Returns:
an array of the lines which may include null values
See Also:
size()

getLineWidths

public int[] getLineWidths()
Retrieves the widths of the lines of this wrapped text

Returns:
an array of the line-widths, can be empty but not null

getLineWidthsInternalArray

public int[] getLineWidthsInternalArray()
Retrieves the widths of lines of this wrapped text.

Returns:
an array of the lines which may include unused values
See Also:
size()

size

public int size()
Retrieves the number of text lines in this wrapped text

Returns:
the number of lines

getLine

public String getLine(int index)
Retrieves the line at the specified index

Parameters:
index - the index, [0..size()[
Returns:
the line at the specified index

getLineWidth

public int getLineWidth(int index)
Retrieves the line width at the specified index

Parameters:
index - the index, [0..size()[
Returns:
the line width at the specified index

getMaxLineWidth

public int getMaxLineWidth()
Retrieves the maximum line width

Returns:
the width of widest line

setMaxLineWidth

public void setMaxLineWidth(int width)
Sets a the width of the widest line within this wrapped text.

Parameters:
width - the width

removeLine

public void removeLine(int index)
Removes the specified line

Parameters:
index - the index of the line

write

public void write(DataOutputStream out)
           throws IOException
Description copied from interface: Externalizable
Stores the internal instance fields to the output stream.

Specified by:
write in interface Externalizable
Parameters:
out - the output stream to which instance fields should be written
Throws:
IOException - when writing fails

read

public void read(DataInputStream in)
          throws IOException
Description copied from interface: Externalizable
Restores the internal instance fields from the given input stream.

Specified by:
read in interface Externalizable
Parameters:
in - the input stream from which the data is loaded
Throws:
IOException - when reading fails