All Packages Class Hierarchy This Package Previous Next Index
Class datarep.common.Util
java.lang.Object
|
+----datarep.common.Util
- public class Util
- extends Object
datarep.common.Util is a catch-all class with various useful static methods.
- Version:
- 1.2
- Author:
- Data Representations, Inc.
-
Util()
-
-
backup(File)
- backup:
A utility method for making a backup of a file.
-
bubbleSort(String[])
- bubbleSort:
A utility method for performing a bubble sort on an array of strings.
-
changeDirectory(String)
- changeDirectory:
changes the default user directory to be used in file operations.
-
changeProperty(String, String)
- changeProperty:
changes a system property.
-
copyFromClipboard(Component)
- copyFromClipboard:
returns text from the System clipboard.
-
copyToClipboard(Component, String)
- copyToClipboard:
copies some text to the system clipboard.
-
drawCenteredString(Graphics, String, int, int)
- drawCenteredString:
draws a centered string in a particular graphics context.
-
fileCopy(File, File)
- fileCopy:
Copies a file.
-
fileCopy(InputStream, File)
- fileCopy:
Copies a file.
-
fileCopy(URL, File)
- fileCopy:
Copies a file.
-
getApplet(Component)
- getApplet:
returns the Applet which a component belongs to.
-
getFrame(Component)
- getFrame:
returns the Frame to which a component belongs.
-
getTopPanel(Component)
- getTopPanel:
returns the top panel which a component belongs to.
-
getWindow(Component)
- getWindow:
returns the Window to which a component belongs.
-
readln()
- readln():
reads in a line of text from System.in.
-
readln(boolean)
- readln(boolean block):
reads in a line of text from System.in.
-
stripLF(String)
- stripLF:
a utility method for removing line feeds from strings.
Util
public Util()
getFrame
public static Frame getFrame(Component comp)
- getFrame:
returns the Frame to which a component belongs. If a component does not belong to any Frame,
returns null.
- Parameters:
- comp - the component in question
- Returns:
- returns the Frame which is the "parent" of the component, or null if there is no
such frame.
getWindow
public static Window getWindow(Component comp)
- getWindow:
returns the Window to which a component belongs. If a component does not belong to any
Window, returns null.
- Parameters:
- comp - the component in question
- Returns:
- returns the Window which is the "parent" of the component, or null if there is no
such window.
getApplet
public static Applet getApplet(Component comp)
- getApplet:
returns the Applet which a component belongs to. If a component does not belong to an
Applet, returns null.
- Parameters:
- comp - the component in question
- Returns:
- returns the Applet which is the "parent" of the component, or null.
getTopPanel
public static Component getTopPanel(Component comp)
- getTopPanel:
returns the top panel which a component belongs to. If a component does not belong to a
panel at all, returns null. This is useful because it is possible (and sometimes necessary)
to nest panels.
- Parameters:
- comp - the component in question
- Returns:
- returns the top panel which is a "parent" of the component, or null.
drawCenteredString
public static void drawCenteredString(Graphics g,
String str,
int x,
int y)
- drawCenteredString:
draws a centered string in a particular graphics context.
fileCopy
public static boolean fileCopy(File source,
File destination)
- fileCopy:
Copies a file. Returns a boolean corresponding to whether or not the copy was sucessful.
- Parameters:
- source - a File object corresponding to the source file
- destination - a File object corresponding to the destination
- Returns:
- returns true if copy was sucessful; false if not.
fileCopy
public static boolean fileCopy(URL source,
File destination)
- fileCopy:
Copies a file. Returns a boolean corresponding to whether or not the copy was sucessful.
- Parameters:
- source - a URL corresponding to the location of the source file
- destination - a File object corresponding to the destination
- Returns:
- returns true if copy was sucessful; false if not.
fileCopy
public static boolean fileCopy(InputStream source,
File destination)
- fileCopy:
Copies a file. Returns a boolean corresponding to whether or not the copy was sucessful.
- Parameters:
- source - an InputStream corresponding to the source file
- destination - a File object corresponding to the destination. If a file already
exists, it will be overwritten.
- Returns:
- returns true if copy was sucessful; false if not.
changeDirectory
public static String changeDirectory(String dir)
- changeDirectory:
changes the default user directory to be used in file operations. Returns a string which is
the previous directory. Note that the string is not checked at this stage to see if it is
a valid directory.
- Parameters:
- dir - the name of the new directory
- Returns:
- returns a string which is the previous default directory.
changeProperty
public static String changeProperty(String key,
String value)
- changeProperty:
changes a system property. Returns a string which corresponds to the old value of the
property.
- Parameters:
- key - the name of the property to be changed (e.g. "user.dir")
- value - the new value for the property.
- Returns:
- returns a string which corresponds to the old value of the property.
readln
public static String readln()
- readln():
reads in a line of text from System.in. Stops reading if it encounters the end of a line,
or if there are no incoming characters (i.e. System.in.available() = 0).
The end of a line is a line feed or carriage return or an escape. readln
returns a string of the text read in (but not including the final line feed/carriage return).
- Returns:
- returns a string of the text read in.
readln
public static String readln(boolean block)
- readln(boolean block):
reads in a line of text from System.in. If block is false, the behavior is identical to
readln(). If block is true, readln only stops reading if it encounters the end of a line.
The end of a line is a line feed or carriage return or an escape. readln
returns a string of the text read in (but not including the final line feed/carriage return).
- Returns:
- returns a string of the text read in.
copyToClipboard
public static void copyToClipboard(Component owner,
String text)
- copyToClipboard:
copies some text to the system clipboard.
- Parameters:
- owner - any component (needed to access the system clipboard; which one is not
important)
- text - the text to be copied to the clipboard
copyFromClipboard
public static String copyFromClipboard(Component owner)
- copyFromClipboard:
returns text from the System clipboard. If the clipboard doesn't contain text, "" is
returned.
- Parameters:
- owner - any component (needed to access the system clipboard; which one is not
important)
- Returns:
- returns a String corresponding to the contents of the clipboard, or "" if an error
occurs.
bubbleSort
public static void bubbleSort(String strings[])
- bubbleSort:
A utility method for performing a bubble sort on an array of strings. This method uses the
java.lang.String.compareTo method to perform a lexicographical comparison. The array will
be sorted in ascending order (A-Z,a-z).
The bubble sort is a fairly simple sorting algorithm. There are many places where a
complete discussion of various sorting algorithms can be found.
- Parameters:
- strings - the String array which will be sorted.
- See Also:
- compareTo
backup
public static void backup(File original)
- backup:
A utility method for making a backup of a file. If the file being saved exists, then a backup will
be made, in a new sub-directory called "Backup". If a backup file already exists in this directory, it will be
replaced with the new backup. This method will output a warning to standard output if it is unable to perform
a backup or encounters an exception.
- Parameters:
- original - the File object which is to be backed up.
stripLF
public static String stripLF(String in)
- stripLF:
a utility method for removing line feeds from strings. This will replace a line feed
(\r) with a carriage return (\n), or a \r \n combination with a single \n. A \0 escape
character will also be replaced with a \n.
- Parameters:
- in - String which will have line feeds stripped
- Returns:
- returns a string with line feeds removed as described above
All Packages Class Hierarchy This Package Previous Next Index