All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.format.TextAlignment

java.lang.Object
   |
   +----com.roguewave.format.TextAlignment

public class TextAlignment
extends Object
A TextAlignment object allows text to be laid out left, center, or right justified. By nesting TextAlignment objects you can acheive arbitrary formats. Padding will be inserted evenly among the null fields or between left and center and center and right if no fields are null.

A TextAlignment object has three fields: left, center, and right. With one or more of these fields set, the TextAlignment object will provide padding to justify the text in a field of a given width.

The TextAlignment class has four constructors:

 public TextAlignment(String left, String center, String right, int width)
 public TextAlignment(String left, String center, String right)
 public TextAlignment(String string, int alignment, int width)
 public TextAlignment(String string, int alignment)
 
For the first two, each field is assigned either a string value (possibly the empty string "") or a null. Fields given a null value indicate where padding should occur. If no null fields are specified then padding will occur to either side of the center field. The next two constructors provide a simplified way to specify a layout with only one field. The first and third specify a width and are expected to be used with the toString() method, while the second and fourth do not, and are intended for use with the toString(int width) method. The alignment argument can have one of three values defined in the TextAlignment class: LEFT, CENTER, and RIGHT.

Here are the various permutations and the resulting output:

 |<------ width ------>|
 |left   center   right| (left, center, right, width)
 |leftcenter           | (left, center, null, width)
 |left                 | (left, null, null, width)
 |       center        | (null, center, null, width)|
 |          centerright| (null, center, right, width)
 |left            right| (left, null, right, width)
 |                right| (null, null, right, width)
 |leftcenterright        (left, center, right, i) i < "leftcenterright".length()
 
The TextAlignmentExample.java example program prints out something similar to the above.

Another example, TextAlignmentExample2.java, combines use of TextPicture and TextAlignment to produce this output:
 ----------------------------------------------------------------------------
 |   Attribute    |  Type   | Default |             Description             |
 |----------------|---------|---------|-------------------------------------|
 | decimalSymbol  | String  |    .    | what to print at the decimal point  |
 | width          |   int   |    0    | width to pad to                     |
 | leftPadChar    |  char   | <space> | char to use for left padding        |
 ----------------------------------------------------------------------------
 


Variable Index

 o CENTER
 o LEFT
 o RIGHT

Constructor Index

 o TextAlignment(String, int)
Create a layout of the specified alignment.
 o TextAlignment(String, int, int)
Create a layout of the specified alignment and width.
 o TextAlignment(String, String, String)
Create a layout without specifying a width, for use with toString(int width)
 o TextAlignment(String, String, String, int)
Create a layout with all three fields specified (some may be null) and a specified width.

Method Index

 o setPadChar(char)
Set the character to pad with.
 o setWidth(int)
Specify the width of the output string.
 o toString()
Return a string with padding as specified by self.
 o toString(int)
Return a string of the specified width with padding as specified by self.

Variables

 o LEFT
 public static final int LEFT
 o RIGHT
 public static final int RIGHT
 o CENTER
 public static final int CENTER

Constructors

 o TextAlignment
 public TextAlignment(String left,
                      String center,
                      String right,
                      int width)
Create a layout with all three fields specified (some may be null) and a specified width.

 o TextAlignment
 public TextAlignment(String left,
                      String center,
                      String right)
Create a layout without specifying a width, for use with toString(int width)

 o TextAlignment
 public TextAlignment(String string,
                      int alignment)
Create a layout of the specified alignment.

 o TextAlignment
 public TextAlignment(String string,
                      int alignment,
                      int width)
Create a layout of the specified alignment and width.

Methods

 o setPadChar
 public void setPadChar(char c)
Set the character to pad with.

 o toString
 public String toString()
Return a string with padding as specified by self.

Overrides:
toString in class Object
 o setWidth
 public void setWidth(int width)
Specify the width of the output string.

 o toString
 public String toString(int width)
Return a string of the specified width with padding as specified by self.


All Packages  Class Hierarchy  This Package  Previous  Next  Index