All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jclass.util.JCUtilConverter

java.lang.Object
   |
   +----jclass.util.JCUtilConverter

public class JCUtilConverter
extends Object
JCUtilConverter contains static methods for retrieving parameters from a source file or applet, and for converting parameters to particular data types.


Variable Index

 o conv
 o param_source
Hash table of alternate parameter sources.

Constructor Index

 o JCUtilConverter()

Method Index

 o checkEnum(int, String, int[])
Checks the validity of an enum.
 o error(String)
Writes a parse error message to stdout.
 o error(String, String)
Writes a parse error message to stdout.
 o fromEnum(int, String, String, String[][], int[][], String)
Converts an enum to a string.
 o fromEnum(int, String[], int[])
Converts an enum to a string.
 o fromNewLine(String)
Converts all occurrences of char '\n' to string "\n"
 o getParam(Applet, Component, String)
Gets a parameter value from the applet or source.
 o getParam(Applet, Component, String, String)
Gets a parameter of the applet in the following precedence:
 <component_name>.<param>
 <param>
 
 o removeEscape(String)
Removes "escape" characters (backslashes) from the string.
 o setParamSource(Component, String)
Sets the source from which getParam should read parameter values.
 o toBoolean(Applet, Component, String, String, boolean)
Retrieves a parameter and converts its value to a boolean value.
 o toBoolean(String, boolean)
Converts a string to a boolean.
 o toColor(String)
Converts a string to a Color.
 o toColor(String, Color)
Converts a string to a Color.
 o toColorList(String)
Converts a string to an array of Colors.
 o toColorList(String, Color[])
Converts a string to an array of Colors.
 o toDate(String, Date)
Converts a String to a Date
 o toDimension(String, Dimension)
Converts a string to a Dimension instance.
 o toDouble(String, double)
Converts a string to an double.
 o toEnum(String, String, String, String[][], int[][], int)
Converts a string to an enum.
 o toEnum(String, String, String[], int[], int)
Converts a string to an enum.
 o toEnum(String, String, String[], long[], long)
Converts a string to an enum.
 o toEnum(String, String[], int[], int)
Converts a string to an enum.
 o toEnumList(String, String, String[], int[], int[])
Converts a string to a list of enums.
 o toFont(String)
Converts a font name to a font instance.
 o toFont(String, Font)
Converts a font name to a font instance.
 o toImage(Component, String)
Returns an image which gets pixel data from the specified file.
 o toImage(Component, String, Image)
Returns an image which gets pixel data from the specified file.
 o toImageList(Component, String, Image[])
Returns an array of images which get pixel data from the specified file.
 o toInsets(String, Insets)
Converts a string to an Insets instance.
 o toInt(String, int)
Converts a string to an integer.
 o toIntList(String, char)
Converts a string to an array of integers based on the provided delimiter.
 o toIntList(String, char, int[])
Converts a string to an array of integers based on the provided delimiter.
 o toNewLine(String)
Converts all occurrences of "\n" to newlines.
 o toPoint(String, Point)
Converts a string to a Point instance.
 o toString(Object)
Converts an object to a string.
 o toStringList(String)
Converts a string to an array of Strings.
 o toVector(Component, String, char, boolean)
Converts a delimited list of tokens to a JCVector.
 o toVector(Component, String, char, boolean, JCVector)
Converts a delimited list of tokens to a JCVector.
 o toVectorFromCSV(Component, String)
Converts a string using comma-separated value format.
 o toVectorFromCSV(Component, String, JCVector)
Converts a string using comma-separated value format.
 o trim(Object)
Returns a trimmed string, with trailing nulls removed
 o waitForImage(Component, Image)
Waits for an image to be loaded, using the MediaTracker class.

Variables

 o conv
 public static JCConverter conv
 o param_source
 public static Hashtable param_source
Hash table of alternate parameter sources.

Constructors

 o JCUtilConverter
 public JCUtilConverter()

Methods

 o setParamSource
 public static void setParamSource(Component key,
                                   String source)
Sets the source from which getParam should read parameter values.

Parameters:
source - a Vector of Strings; if null, getParam will read values from its specified applet
See Also:
getParam
 o getParam
 public static String getParam(Applet app,
                               Component key,
                               String param)
Gets a parameter value from the applet or source.

Parameters:
app - the applet used to retrieve the parameter
key - the component used as the key for the parameter source hash table
param - the parameter to retrieve
Returns:
parameter value
 o getParam
 public static String getParam(Applet app,
                               Component comp,
                               String comp_name,
                               String param)
Gets a parameter of the applet in the following precedence:
 <component_name>.<param>
 <param>
 

Parameters:
app - the applet whose parameter value is retrieved; if setParamSource() has previously been called, the value will be read from the specified buffer
comp - the component used for converting images (if any) and for retrieving the parameter source
comp_name - the component name
param - the parameter to retrieve
Returns:
value string, or null if the param could not be found
See Also:
setParamSource, getParameter
 o error
 public static void error(String s,
                          String token)
Writes a parse error message to stdout.

Parameters:
s - the entire string being parsed
token - the string which could not be parsed
 o error
 public static void error(String msg)
Writes a parse error message to stdout.

Parameters:
token - the string which could not be parsed
 o trim
 public static String trim(Object obj)
Returns a trimmed string, with trailing nulls removed

Parameters:
obj - the object to trim
String - the version of the object with trailing nulls removed
 o toInt
 public static int toInt(String s,
                         int def)
Converts a string to an integer.

Parameters:
string - the string for conversion
def - the default value to be used when a parsing error occurs
 o toDouble
 public static double toDouble(String s,
                               double def)
Converts a string to an double.

Parameters:
string - the string for conversion
def - the default value to be used when a parsing error occurs
 o toBoolean
 public static boolean toBoolean(String s,
                                 boolean def)
Converts a string to a boolean.

Parameters:
s - the string for conversion
def - the default value to be used when a parsing error occurs
 o toBoolean
 public static boolean toBoolean(Applet app,
                                 Component comp,
                                 String comp_name,
                                 String param,
                                 boolean def)
Retrieves a parameter and converts its value to a boolean value.

Parameters:
app - the applet used to retrieve the parameter value
comp - key used for the parameter source hash table
comp_name - the component name
param - the parameter to retrieve
def - the default value
 o toStringList
 public static String[] toStringList(String s)
Converts a string to an array of Strings.

Parameters:
s - the comma-separated strings
 o toIntList
 public static int[] toIntList(String s,
                               char delim)
Converts a string to an array of integers based on the provided delimiter.

Parameters:
s - the string which will be converted to integers
delim - the delimiter separating the integers in the string
 o toIntList
 public static int[] toIntList(String s,
                               char delim,
                               int def[])
Converts a string to an array of integers based on the provided delimiter.

Parameters:
s - the string which will be converted to integers
delim - the delimiter separating the integers in the string
def - the default value, returned if a parse error occurs
 o toNewLine
 public static String toNewLine(String string)
Converts all occurrences of "\n" to newlines.

 o fromNewLine
 public static String fromNewLine(String s)
Converts all occurrences of char '\n' to string "\n"

 o toVector
 public static JCVector toVector(Component comp,
                                 String s,
                                 char delim,
                                 boolean convert)
Converts a delimited list of tokens to a JCVector.

Parameters:
comp - any component
s - the string to convert
delim - the delimiter that separates the tokens in the string
convert - if true, a token is converted to a JCString if it contains a square bracket ([)
 o toVector
 public static JCVector toVector(Component comp,
                                 String s,
                                 char delim,
                                 boolean convert,
                                 JCVector def)
Converts a delimited list of tokens to a JCVector.

Parameters:
comp - any component
s - the string to convert
delim - the delimiter that separates the tokens in the string
convert - if true, a token is converted to a JCString if it contains a square bracket ([)
def - the default value, returned if a parse error occurs
 o toVectorFromCSV
 public static JCVector toVectorFromCSV(Component comp,
                                        String s)
Converts a string using comma-separated value format.

Parameters:
comp - any component
s - the string to be tokenized
 o toVectorFromCSV
 public static JCVector toVectorFromCSV(Component comp,
                                        String s,
                                        JCVector def)
Converts a string using comma-separated value format.

Parameters:
comp - any component
s - the string to be tokenized
def - the default value, returned if a parse error occurs
 o toImage
 public static Image toImage(Component comp,
                             String file,
                             Image def)
Returns an image which gets pixel data from the specified file. The MediaTracker class is used to wait until the image is loaded.

Parameters:
c - the component that is loading the image. If the component is an applet in a browser, Applet.getImage() is used in order to take advantage of Applet.getDocumentBase()
file - the file containing the image to be loaded; if an http protocol is not specified (a ":" is not present), the current working directory is prepended to the file name
def - the default value, returned if a parse error occurs
See Also:
MediaTracker
 o toImage
 public static Image toImage(Component comp,
                             String file)
Returns an image which gets pixel data from the specified file. The MediaTracker class is used to wait until the image is loaded.

Parameters:
c - the component that is loading the image. If the component is an applet in a browser, Applet.getImage() is used in order to take advantage of Applet.getDocumentBase()
file - the file containing the image to be loaded; if an http protocol is not specified (a ":" is not present), the current working directory is prepended to the file name
See Also:
MediaTracker
 o waitForImage
 public static boolean waitForImage(Component comp,
                                    Image image)
Waits for an image to be loaded, using the MediaTracker class.

Returns:
false if an error occurred
See Also:
MediaTracker
 o toImageList
 public static Image[] toImageList(Component comp,
                                   String s,
                                   Image def[])
Returns an array of images which get pixel data from the specified file.

Parameters:
s - comma-separated list of files
def - the default value, returned if a parse error occurs
See Also:
toImage
 o toColorList
 public static Color[] toColorList(String s,
                                   Color def[])
Converts a string to an array of Colors.

Parameters:
s - the string containing color names separated by commas
def - the default value, returned if a parse error occurs
 o toColorList
 public static Color[] toColorList(String s)
Converts a string to an array of Colors.

Parameters:
s - the comma-separated color names
 o toColor
 public static Color toColor(String s,
                             Color def)
Converts a string to a Color.

Parameters:
s - the string containing a color name
def - the default value, returned if a parse error occurs
 o toColor
 public static Color toColor(String s)
Converts a string to a Color.

Parameters:
s - the string containing a color name
 o toFont
 public static Font toFont(String s,
                           Font def)
Converts a font name to a font instance.

Parameters:
s - the string containing font name
def - the default value, returned if a parse error occurs
 o toFont
 public static Font toFont(String s)
Converts a font name to a font instance.

Parameters:
s - the string containing font name
 o toEnum
 public static int toEnum(String string,
                          String type,
                          String param,
                          String strings[][],
                          int values[][],
                          int def)
Converts a string to an enum. If the string cannot be converted, an error message is written to the console.

Parameters:
string - the string to be converted
type - the enum type
param - the optional PARAM name for the enum, used for the error message
strings - the first item in each list is the enum type; each string has a corresponding value in the values array
values - list of values corresponding to the strings
def - the default value, returned if the string could not be converted
Returns:
either the converted value or the default
 o toEnum
 public static int toEnum(String s,
                          String type,
                          String strings[],
                          int values[],
                          int def)
Converts a string to an enum. If the string cannot be converted, an error message is written to the console.

Parameters:
s - the string to be converted
type - the enum type (for the console message)
strings - list of valid strings
values - list of values corresponding to each string
def - the default value, returned if the string could not be converted
Returns:
either the converted value or the default
 o toEnum
 public static long toEnum(String s,
                           String type,
                           String strings[],
                           long values[],
                           long def)
Converts a string to an enum. If the string cannot be converted, an error message is written to the console.

Parameters:
s - the string to be converted
type - the enum type (for the console message)
strings - list of valid strings
values - list of values corresponding to each string
def - the default value, returned if the string could not be converted
Returns:
either the converted value or the default
 o toEnum
 public static int toEnum(String s,
                          String strings[],
                          int values[],
                          int def)
Converts a string to an enum.

Parameters:
s - the string to be converted
strings - list of valid strings
values - list of values corresponding to each string
def - the default value, returned if the string could not be converted
Returns:
the converted value or the default
 o toEnumList
 public static int[] toEnumList(String s,
                                String type,
                                String strings[],
                                int values[],
                                int def[])
Converts a string to a list of enums. If the string cannot be converted, an error message is written to the console.

Parameters:
s - the comma-separated list of enums
type - the enum type
strings - valid strings
values - list of values corresponding to each string
def - the default value, returned if the string could not be converted
Returns:
either the converted value or the default
 o fromEnum
 public static String fromEnum(int value,
                               String strings[],
                               int values[])
Converts an enum to a string.

Parameters:
value - the enum to be converted
strings - list of valid strings
values - list of values corresponding to each string
Returns:
either the converted value or null
 o fromEnum
 public static String fromEnum(int value,
                               String param,
                               String type,
                               String strings[][],
                               int values[][],
                               String def)
Converts an enum to a string. If the enum cannot be converted, an error message is written to the console.

Parameters:
value - the enum to be converted
param - the optional PARAM name for the enum, used for the error message
type - the enum type
strings - The first item in each list is the enum type; each string has a corresponding value in the values array.
values - list of values corresponding to the strings
def - the default value, returned if the enum could not be converted
Returns:
either the converted value or the default
 o checkEnum
 public static void checkEnum(int value,
                              String param,
                              int values[])
Checks the validity of an enum.

Parameters:
param - enum name, used for error message
Throws: IllegalArgumentException
If the value is invalid
 o toInsets
 public static Insets toInsets(String s,
                               Insets def)
Converts a string to an Insets instance.

Parameters:
s - the string containing the top, left, bottom and right values, separated by commas
def - the default value, returned if the string could not be converted
 o toDimension
 public static Dimension toDimension(String s,
                                     Dimension def)
Converts a string to a Dimension instance.

Parameters:
s - the string in the format [width]x[height]
def - the default value, returned if the string could not be converted
 o toPoint
 public static Point toPoint(String s,
                             Point def)
Converts a string to a Point instance.

Parameters:
s - the string in the format [x],[y]
def - the default value, returned if the string could not be converted
 o toString
 public static String toString(Object o)
Converts an object to a string. If a String, newlines are replaced by "\n". If a Vector, it is converted to a comma-separated list.

 o toDate
 public static Date toDate(String s,
                           Date def)
Converts a String to a Date

 o removeEscape
 public static String removeEscape(String s)
Removes "escape" characters (backslashes) from the string.


All Packages  Class Hierarchy  This Package  Previous  Next  Index