|
sharkysoft.com | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.sharkysoft.printf.engine.StringFormatter
Justifies text in field.
Details: A StringFormatter formats arbitrary length
strings into a fixed-
To justify a string in a field, create an instance of
StringFormatter, configure the formatting properties, and then
process the string through the justifier using
format.
Example: Output the contents of vasNames, an array of
strings, with one element per line, right-
String[] vasNames = {"apple", "banana", "cherry"};
StringFormatter vpJustifier = new StringFormatter();
vpJustifier.setFieldWidth(50);
vpJustifier.setAlignment(AlignmentMode.gpRight);
vpJustifier.setPadChar('_');
for (int vnI = 0; vnI < vasNames.length; ++ i)
System.out.println(vpJustifier.format(vasNames[i]));
The output of this code is:
_____________________________________________apple ____________________________________________banana ____________________________________________cherry
| Field Summary | |
protected char |
mcPadChar
Padding character. |
protected int |
mnAlignment
Alignment mode. |
protected int |
mnCropping
Cropping mode. |
protected int |
mnFieldWidth
Field width. |
| Constructor Summary | |
StringFormatter()
Default constructor. |
|
| Method Summary | |
java.lang.String |
format(java.lang.String isText)
Justifies text. |
java.lang.String |
format(java.lang.String isPrefix,
java.lang.String isSuffix)
Justifies text. |
AlignmentMode |
getAlignment()
Retrieves Alignment property. |
CroppingMode |
getCropping()
Retrieves Cropping property. |
int |
getFieldWidth()
Retrieves FieldWidth property. |
char |
getPadChar()
Retrieves PadChar property. |
void |
setAlignment(AlignmentMode ipAlignment)
Updates Alignment property. |
void |
setCropping(CroppingMode ipCropping)
Updates Cropping property. |
void |
setFieldWidth(int inFieldWidth)
Updates FieldWidth property. |
void |
setPadChar(char icPadChar)
Updates PadChar property. |
java.lang.String |
toString()
Generates debug output. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected int mnFieldWidth
Details:
PropertyFieldWidth is the width of the
field into which text will be formatted.
Default value: 0.
getFieldWidth(),
setFieldWidth(int)protected int mnAlignment
Details: Property Alignment controls the positioning
of text within the field. Available alignment options include left
justification, right justification, full justification, and centering.
Default value:
AlignmentMode.gpLeft.
getAlignment(),
setAlignment(AlignmentMode)protected char mcPadChar
Details: Property PadChar is the character used to
fill the unused portion of the field when the text is shorter than the
field.
Default value: ' ' (space character).
getPadChar(),
setPadChar(char)protected int mnCropping
Details: Property Cropping controls whether and how
text is compressed if it is larger than the field into which it is
formatted. The head, tail, or center portion of the text may be cropped to
ensure that the formatted text fits within the field. Or, cropping may be
prohibited, so that long text actually overflows the field.
Default value:
CroppingMode.gpNone.
getCropping(),
setCropping(CroppingMode)| Constructor Detail |
public StringFormatter()
| Method Detail |
public int getFieldWidth()
mnFieldWidthpublic void setFieldWidth(int inFieldWidth)
inFieldWidth - new valuemnFieldWidthpublic AlignmentMode getAlignment()
mnAlignmentpublic void setAlignment(AlignmentMode ipAlignment)
ipAlignment - new valuemnAlignmentpublic char getPadChar()
mcPadCharpublic void setPadChar(char icPadChar)
icPadChar - new valuemcPadCharpublic CroppingMode getCropping()
mnCroppingpublic void setCropping(CroppingMode ipCropping)
ipCropping - new valuemnCroppingpublic final java.lang.String format(java.lang.String isText)
Details: format formats the supplied string
according to currently configured properties.
If Alignment is set to FULL, then the
split-format(String, String)) should be
used instead. This is because the format method with only one string
parameter does not know where the filler characters should be inserted.
Eventually, this method may be upgraded to support automatic expansion of
whitespace characters within the string for full justification.
isText - the text to justify
public final java.lang.String format(java.lang.String isPrefix,
java.lang.String isSuffix)
Details: format justifies a split string according
to the currently configured properties. If Alignment is set
to FULL, then the prefix is left-format(String).
isPrefix - the left portion of the stringisSuffix - the right portion of the string
public java.lang.String toString()
Details: toString generates a string representation
of this instance and its properties. This output is useful only for
debugging.
|
sharkysoft.com | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
Copyright © 1997-2004 Sharkysoft (sharkysoft.com). All rights reserved.