BreezyGUI
Class Format

java.lang.Object
  |
  +--BreezyGUI.Format

public class Format
extends java.lang.Object

The class Format contains methods to format data that are left-justified, right-justified, or centered within a given number of columns.


Constructor Summary
Format()
           
 
Method Summary
static java.lang.String justify(char leftRight, char ch, int width)
          Converts a character to a string and returns it formatted formatted according to the justification type and the specified width.
static java.lang.String justify(char leftRight, double x, int width, int precision)
          Converts a double to a string and returns it formatted according to the justification type and the specified width and precision.
static java.lang.String justify(char leftRight, long x, int width)
          Converts a long to a string and returns it formatted formatted according to the justification type and the specified width.
static java.lang.String justify(char leftRight, java.lang.String str, int width)
          Returns a string that is formatted according to the justification type and the specified width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format()
Method Detail

justify

public static java.lang.String justify(char leftRight,
                                       java.lang.String str,
                                       int width)
Returns a string that is formatted according to the justification type and the specified width. If the width is less than the length of the string, returns a string of stars (*) whose length equals the width.
Parameters:
leftRight - the type of justification ('l', 'c', or 'r').
str - the string to be formatted.
width - the number of columns in which the string is placed. Examples:

   String right = Format.justify('l', "Hi", 4);
   String left = Format.justify('c', "Hi", 4);
   String center = Format.justify('r', "Hi", 4);
   String noChange = Format.justify('r', "Hi", 2);
   String tooFew = Format.justify('r', "Hi", 1);

   left now refers to      "Hi  "
   center now refers to    " Hi "
   right now refers to     "  Hi"
   noChange now refers to  "Hi"
   tooFew now refers to    "**"
 

justify

public static java.lang.String justify(char leftRight,
                                       char ch,
                                       int width)
Converts a character to a string and returns it formatted formatted according to the justification type and the specified width.
Parameters:
leftRight - the type of justification ('l', 'c', or 'r').
ch - the character to be formatted.
width - the number of columns in which the character is placed.

justify

public static java.lang.String justify(char leftRight,
                                       long x,
                                       int width)
Converts a long to a string and returns it formatted formatted according to the justification type and the specified width.
Parameters:
leftRight - the type of justification ('l', 'c', or 'r').
x - the long integer to be formatted.
width - the number of columns in which the integer is placed.

justify

public static java.lang.String justify(char leftRight,
                                       double x,
                                       int width,
                                       int precision)
Converts a double to a string and returns it formatted according to the justification type and the specified width and precision. The decimal point occupies a column in the formatted number.
Parameters:
leftRight - the type of justification ('l', 'c', or 'r').
x - the number to be formatted.
width - the number of columns in which the number is placed.
precision - the number of places of precision retained in the formatted number. Examples:
   String fourPlaces = Format.justify('r', 3.1416, 7, 4);
   String threePlaces = Format.justify('r', 3.1416, 7, 3);
   String twoPlaces = Format.justify('r', 3.1416, 7, 2);
   String noPlaces = Format.justify('r', 3.1416, 7, 0);

   fourPlaces now refers to  " 3.1416"
   threePlaces now refers to "  3.142"
   twoPlaces now refers to   "   3.14"
   noPlaces now refers to    "      3"