|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer java.io.FilterWriter org.sadun.util.JustifierWriter
A Writer to justify text.
This writer right-justifies the characters sent to it to a given line length. It interprets the characters as a stream of space-separated words and when a word doesn't fit in the given length, the line is justified and sent to the wrapped writer.
Field Summary |
Fields inherited from class java.io.FilterWriter |
out |
Fields inherited from class java.io.Writer |
lock |
Constructor Summary | |
JustifierWriter(java.io.Writer out)
Create a justifier wrapping the given writer with the default linge length |
|
JustifierWriter(java.io.Writer out,
int lineLenght)
Create a justifier wraping the given writer and using the given line length |
Method Summary | |
int |
getLineLength()
Return the line length currently employed by this writer. |
boolean |
isAutoFlush()
Return true if the writer automatically flushes the wrapped writer when a line is written. |
boolean |
isJustifyOnNewLine()
Return true if the writer applies justification on explicit newlines. |
boolean |
isPadOnNewLine()
Return true if the writer pads output with space on a new line. |
boolean |
isPreserveInitialSpaces()
Return true if the writer preserves intial spaces. |
static java.lang.String |
justify(java.lang.String s,
int lineLength)
Return the given string, right-justified to the given line length, without preserving initial spaces. |
static java.lang.String |
justify(java.lang.String s,
int lineLength,
boolean preserveInitialSpaces)
Return the given string, right-justified to the given line length, optionally preserving initial spaces. |
static void |
main(java.lang.String[] args)
|
void |
setAutoFlush(boolean autoFlush)
Set whether or not the writer automatically flushes the wrapped writer when a line is written. |
void |
setJustifyOnNewLine(boolean justifyOnNewLine)
Set whether or not the writer applies justification on explicit newlines. |
void |
setLineLength(int lineLength)
Set the line length currently employed by this writer. |
void |
setPadOnNewLine(boolean padOnNewLine)
Set whether or not the writer pads output with spaces on a new line. |
void |
setPreserveInitialSpaces(boolean preserveInitialSpaces)
Set whether or not the writer preserves intial spaces. |
void |
write(char[] cbuf,
int off,
int len)
Write the given characters. |
void |
write(java.lang.String str,
int off,
int len)
Write the given string. |
Methods inherited from class java.io.FilterWriter |
close, flush, write |
Methods inherited from class java.io.Writer |
write, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JustifierWriter(java.io.Writer out)
out
- the wrapped writerpublic JustifierWriter(java.io.Writer out, int lineLenght)
out
- the wrapped writerlineLenght
- the desired line lengthMethod Detail |
public void write(char[] cbuf, int off, int len) throws java.io.IOException
justifyOnNewLine
is true
and the embedded writer will be flushed if autoFlush
is true.
If the words exceed the given line lenght
the line is justified
and sent to wrapped writer.
java.io.IOException
public void write(java.lang.String str, int off, int len) throws java.io.IOException
justifyOnNewLine
is true
and the embedded writer will be flushed if autoFlush
is true.
If the words exceed the given line lenght
the line is justified
and sent to wrapped writer.
java.io.IOException
public static java.lang.String justify(java.lang.String s, int lineLength)
s
- the string to justifiedlineLength
- the desired line lenght.
public static java.lang.String justify(java.lang.String s, int lineLength, boolean preserveInitialSpaces)
s
- the string to justifiedlineLength
- the desired line lenght.preserveInitialSpaces
- if true, initial spaces will be preserved
public int getLineLength()
public void setLineLength(int lineLength)
lineLength
- the new line lengthpublic boolean isJustifyOnNewLine()
public void setJustifyOnNewLine(boolean justifyOnNewLine)
justifyOnNewLine
- if true, the writer applies justification on explicit newlines.public boolean isPreserveInitialSpaces()
public void setPreserveInitialSpaces(boolean preserveInitialSpaces)
preserveInitialSpaces
- if true, the writer preserves intial spaces.public boolean isPadOnNewLine()
public void setPadOnNewLine(boolean padOnNewLine)
padOnNewLine
- if true, the writer pads output with spaces on a new line.public boolean isAutoFlush()
public void setAutoFlush(boolean autoFlush)
autoFlush
- if true, the writer automatically flushes the wrapped writer when a line is written.public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |