org.jmol.util
Class TextFormat

java.lang.Object
  extended by org.jmol.util.TextFormat

public class TextFormat
extends Object


Field Summary
private static DecimalFormat[] formatters
           
private static String[] formattingStrings
           
private static Boolean[] useNumberLocalization
           
 
Constructor Summary
TextFormat()
           
 
Method Summary
private static String fdup(String f, int pt, int n)
          fdup duplicates p or q formats for formatCheck and the format() function.
static String format(double value, int width, int precision, boolean alignLeft, boolean zeroPad, boolean allowOverflow)
           
static String format(float value, int width, int precision, boolean alignLeft, boolean zeroPad)
           
static String format(String value, int width, int precision, boolean alignLeft, boolean zeroPad)
           
static String formatCheck(String strFormat)
          formatCheck checks p and q formats and duplicates if necessary "%10.5p xxxx" ==> "%10.5p%10.5p%10.5p xxxx"
static String formatDecimal(float value, int decimalDigits)
           
static String formatString(String strFormat, String key, float floatT)
           
static String formatString(String strFormat, String key, int intT)
           
static String formatString(String strFormat, String key, String strT)
           
private static String formatString(String strFormat, String key, String strT, float floatT, double doubleT, boolean doOne)
          generic string formatter based on formatLabel in Atom
static boolean isMatch(String s, String strWildcard, boolean checkStar, boolean allowInitialStar)
           
static boolean isWild(String s)
           
static String join(String[] s, char c, int i0)
           
static void lFill(StringBuffer s, String s1, String s2)
           
static String replaceAllCharacters(String str, String strFrom, char chTo)
          Does a clean replace of any of the characters in str with chrTo If strTo contains strFrom, then only a single pass is done.
static String replaceAllCharacters(String str, String strFrom, String strTo)
          Does a clean replace of any of the characters in str with strTo If strTo contains strFrom, then only a single pass is done.
static String replaceQuotedStrings(String s, List list, List newList)
           
static String replaceStrings(String s, List list, List newList)
           
static void rFill(StringBuffer s, String s1, String s2)
           
static String safeTruncate(float f, int n)
           
static void setUseNumberLocalization(boolean TF)
           
static String simpleReplace(String str, String strFrom, String strTo)
          Does a clean replace of strFrom in str with strTo If strTo contains strFrom, then only a single pass is done.
static String[] split(String text, char ch)
           
static String[] split(String text, String run)
          proper splitting, even for Java 1.3 -- if the text ends in the run, no new line is appended.
static String sprintf(String strFormat, Object[] values)
          sprintf emulation uses (almost) c++ standard string formats 's' string 'i' or 'd' integer 'f' float/decimal 'p' point3f 'q' quaternion/plane/axisangle ' with added "i" in addion to the insipid "d" (digits?)
static String trim(String str, String chars)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

formatters

private static final DecimalFormat[] formatters

formattingStrings

private static final String[] formattingStrings

useNumberLocalization

private static final Boolean[] useNumberLocalization
Constructor Detail

TextFormat

public TextFormat()
Method Detail

setUseNumberLocalization

public static void setUseNumberLocalization(boolean TF)

formatDecimal

public static String formatDecimal(float value,
                                   int decimalDigits)

format

public static String format(float value,
                            int width,
                            int precision,
                            boolean alignLeft,
                            boolean zeroPad)

format

public static String format(double value,
                            int width,
                            int precision,
                            boolean alignLeft,
                            boolean zeroPad,
                            boolean allowOverflow)

format

public static String format(String value,
                            int width,
                            int precision,
                            boolean alignLeft,
                            boolean zeroPad)
Parameters:
value -
width - number of columns
precision - precision > 0 ==> precision = number of characters max from left precision < 0 ==> -1 - precision = number of char. max from right
alignLeft -
zeroPad - generally for numbers turned strings
Returns:
formatted string

formatString

public static String formatString(String strFormat,
                                  String key,
                                  String strT)

formatString

public static String formatString(String strFormat,
                                  String key,
                                  float floatT)

formatString

public static String formatString(String strFormat,
                                  String key,
                                  int intT)

sprintf

public static String sprintf(String strFormat,
                             Object[] values)
sprintf emulation uses (almost) c++ standard string formats 's' string 'i' or 'd' integer 'f' float/decimal 'p' point3f 'q' quaternion/plane/axisangle ' with added "i" in addion to the insipid "d" (digits?)

Parameters:
strFormat -
values -
Returns:
formatted string

formatString

private static String formatString(String strFormat,
                                   String key,
                                   String strT,
                                   float floatT,
                                   double doubleT,
                                   boolean doOne)
generic string formatter based on formatLabel in Atom

Parameters:
strFormat - .... %width.precisionKEY....
key - any string to match
strT - replacement string or null
floatT - replacement float or Float.NaN
doubleT - replacement double or Double.NaN -- for exponential
doOne - mimic sprintf
Returns:
formatted string

formatCheck

public static String formatCheck(String strFormat)
formatCheck checks p and q formats and duplicates if necessary "%10.5p xxxx" ==> "%10.5p%10.5p%10.5p xxxx"

Parameters:
strFormat -
Returns:
f or dupicated format

fdup

private static String fdup(String f,
                           int pt,
                           int n)
fdup duplicates p or q formats for formatCheck and the format() function.

Parameters:
f -
pt -
n -
Returns:
%3.5q%3.5q%3.5q%3.5q or %3.5p%3.5p%3.5p

split

public static String[] split(String text,
                             String run)
proper splitting, even for Java 1.3 -- if the text ends in the run, no new line is appended.

Parameters:
text -
run -
Returns:
String array

replaceAllCharacters

public static String replaceAllCharacters(String str,
                                          String strFrom,
                                          String strTo)
Does a clean replace of any of the characters in str with strTo If strTo contains strFrom, then only a single pass is done. Otherwise, multiple passes are made until no more replacements can be made.

Parameters:
str -
strFrom -
strTo -
Returns:
replaced string

replaceAllCharacters

public static String replaceAllCharacters(String str,
                                          String strFrom,
                                          char chTo)
Does a clean replace of any of the characters in str with chrTo If strTo contains strFrom, then only a single pass is done. Otherwise, multiple passes are made until no more replacements can be made.

Parameters:
str -
strFrom -
chTo -
Returns:
replaced string

simpleReplace

public static String simpleReplace(String str,
                                   String strFrom,
                                   String strTo)
Does a clean replace of strFrom in str with strTo If strTo contains strFrom, then only a single pass is done. Otherwise, multiple passes are made until no more replacements can be made.

Parameters:
str -
strFrom -
strTo -
Returns:
replaced string

trim

public static String trim(String str,
                          String chars)

split

public static String[] split(String text,
                             char ch)

lFill

public static void lFill(StringBuffer s,
                         String s1,
                         String s2)

rFill

public static void rFill(StringBuffer s,
                         String s1,
                         String s2)

safeTruncate

public static String safeTruncate(float f,
                                  int n)

isWild

public static boolean isWild(String s)

isMatch

public static boolean isMatch(String s,
                              String strWildcard,
                              boolean checkStar,
                              boolean allowInitialStar)

join

public static String join(String[] s,
                          char c,
                          int i0)

replaceQuotedStrings

public static String replaceQuotedStrings(String s,
                                          List list,
                                          List newList)

replaceStrings

public static String replaceStrings(String s,
                                    List list,
                                    List newList)