|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectca.bc.webarts.widgets.Util
A set of useful utility methods/functions for reuse.
Field Summary | |
private static java.lang.String |
CLASSNAME
A holder This classes name (used when logging). |
static java.lang.String |
CLASSPATH
The VM classpath (used in some methods).. |
static short |
DEFAULT_LOOKANDFEEL
the Default LookAndFeel CONSTANT. |
private static boolean |
initUtil
Class flag signifying if the initUtil method has been called |
private static Log |
log_
Gets a Log instance in case any calling classes are using it. |
static short |
MAC_LOOKANDFEEL
the Mac LookAndFeel CONSTANT. |
static java.lang.String |
macClassName
the Mac LookAndFeel class name |
static short |
METAL_LOOKANDFEEL
the Metal LookAndFeel CONSTANT. |
static java.lang.String |
metalClassName
the Java LookAndFeel class name |
static short |
MOTIF_LOOKANDFEEL
the Motif LookAndFeel CONSTANT. |
static java.lang.String |
motifClassName
the motif LookAndFeel class name |
static short |
OPEN_DIALOG
A constant to specify which dialog to open with the chooseFileDialog. |
static short |
SAVE_DIALOG
A constant to specify which dialog to open with the chooseFileDialog. |
static java.lang.String |
SYSTEM_FILE_SEPERATOR
A holder for this clients System File Separator. |
static java.lang.String |
SYSTEM_LINE_SEPERATOR
A holder for this clients System line termination separator. |
static java.lang.String |
USERDIR
The users home ditrectory. |
static java.lang.String |
USERHOME
The users home ditrectory. |
static java.lang.String |
windowsClassName
the Windoze LookAndFeel class name |
static short |
WINDOZE_LOOKANDFEEL
the Windoze LookAndFeel CONSTANT. |
Constructor Summary | |
Util()
|
Method Summary | |
static java.lang.String |
absoluteToPwdRelativePath(java.io.File absPath)
Converts an Absolute path to a relative path from the VM Working Dir. |
static java.lang.String |
absoluteToPwdRelativePath(java.lang.String absPath)
Converts an Absolute path to a relative path from the VM Working Dir. |
static java.lang.String |
capsToSpacesInString(java.lang.String fName)
Takes a string and adds a space in front of any capitalized char. |
static java.lang.String |
chooseAFilename(java.awt.Component parent,
java.lang.String startPath)
Encapsulates the showing of the FileChooser dialog and returns a String representing the absolute path. |
static java.lang.String |
chooseAFilename(java.awt.Component parent,
java.lang.String startPath,
ExampleFileFilter[] filters,
boolean filesAndDirs)
Encapsulates the showing of the FileChooser dialog and returns a String representing the absolute path. |
static java.lang.String |
chooseAFilename(java.awt.Component parent,
java.lang.String startPath,
ExampleFileFilter[] filters,
boolean filesAndDirs,
short openOrClose)
Encapsulates the showing of the FileChooser dialog and returns a String representing the absolute path. |
static long |
countFilesInDir(java.lang.String dirName,
boolean recurse)
Counts the files in a dir (optionally recurses sub dirs) |
static java.lang.String |
createCurrentDateStamp()
Creates a timestamp for the current date. |
static java.lang.String |
createCurrentDateTimeStamp()
Creates a timestamp for the current date and time. |
static java.lang.String |
createCurrentTimeStamp()
Creates a timestamp for the current time in the form of 'hour + "-" + min + "-" + sec + "-" + millis'. |
static java.lang.String |
createTimerTimeStamp(int startTimeMillis)
Creates a Timer timestamp from the current time to the passed startTime in the form of 'hour + "-" + min + "-" + sec + "-" + millis'. |
static long |
dirSize(java.lang.String fileName,
boolean recurseSubdirs)
Obtains the bytes of data contained in all files in this dir (and subdirs). |
static void |
ensureFolderExists(java.io.File folder)
Ensures that a folder exists. |
static void |
ensureFolderExists(java.lang.String foldername)
|
static int |
executeNativeApp(java.lang.String executableLocation,
java.lang.String[] appParms,
java.lang.String outFilename)
Executes the Specified Native OS application with the provided commandline parameters. |
static int |
executeNativeApp(java.lang.String executableLocation,
java.util.Vector appParms,
java.lang.String outFilename)
Executes the Specified Native OS application with the provided commandline parameters. |
static java.util.Vector |
findFile(java.lang.String fileName,
java.lang.String directory,
boolean recurseSubdirs,
boolean regExp,
boolean verbose)
Searches the provided directory (and subdirs) for the requested file. |
static java.awt.Frame |
getAncestorFrame(java.awt.Component c)
This method seeks out and returns the Parent Frame for a given component. |
static java.util.Date |
getCurrentDate()
gets the current date and time. |
static java.net.URL |
getFileBaseURL(java.lang.String fileString)
Creates a URL for the specified filename string. |
static java.net.URL[] |
getFileBaseURLs(java.lang.String[] fileStrings)
Creates a URL[] for the given Strings. |
static java.io.File |
getFileDir(java.lang.String fileString)
Creates a File representing the Dir for the specified filename string. |
static java.lang.String |
getFilePathFromClasspath(java.lang.String filename)
Searches the classpath for the specified filename and then returns the full path that is used for it. |
static java.lang.String |
getFilePathFromClasspath(java.lang.String filename,
java.lang.String fallBack)
Searches the classpath for the specified filename and then returns the full path that is used for it. |
static java.net.InetAddress |
getLocalhostName()
gets the current VMs localhost address. |
static java.io.File |
initDirFile(java.lang.String s)
Initisalizes File only if it is directory.It is represented by the passed in String. |
private static void |
initUtil()
Inits the log and some other vars. |
static java.awt.Image |
loadImage(java.lang.String imageFilename)
Loads the requested Image filename from the classpath. |
static java.awt.Image |
loadImage(java.lang.String imageFilename,
java.lang.String jarFilename)
Loads the requested Image filename from the specified jarfile. |
static void |
main(java.lang.String[] args)
|
static boolean |
moveFile(java.lang.String filename,
java.lang.String foldername)
Moves the specified file to the specified directory. |
static boolean |
removeDir(java.lang.String fileName)
Recursively deletes all the files in the spec'd directory and subdirectories, and then removes the dir. |
static boolean |
removeFile(java.lang.String fileName)
Deletes a file. |
static boolean |
removeOldFiles(java.lang.String dirName,
int numDays,
boolean recurse)
Deletes all files in the spec'd dir that are older than the spec'd number of days. |
static java.lang.String |
removeParentRelativeReference(java.lang.String path)
Removes a '/..' from the filename string and returns the corrected dir name reference. |
static java.util.Hashtable |
searchInFile(java.lang.String searchStr,
java.lang.String filename,
boolean recurseSubdirs,
boolean fileRegExp,
boolean verbose)
Searches the provided file/directory (and subdirs) for the search String. |
static void |
setIconForApp(javax.swing.JFrame appFrame,
java.lang.String imageFilename)
SetsIcon for the passed in Frame |
static void |
setIconForApp(javax.swing.JFrame appFrame,
java.net.URL imageUrl)
SetsIcon for the passed in Frame |
static void |
setTheLookAndFeel(short i,
java.awt.Component comp)
Calls the User Interface Manager and sets the look and feel setting based on the parameter it is passed. |
static boolean |
sleep(long waitTime)
A method to simply abstract the Try/Catch required to put the current thread to sleep for the specified time in ms. |
static java.lang.String |
spacesToCapsInString(java.lang.String fName)
Removes any space chars ' ' from a String and Capitalizes the next char. |
static java.lang.String |
toHEXString(byte b)
A simple byte to Hex String converter. |
static java.lang.String |
tokenReplace(java.lang.String sentence,
java.lang.String token,
java.lang.String replacement)
A simple String token replacement routine. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String SYSTEM_FILE_SEPERATOR
public static final java.lang.String SYSTEM_LINE_SEPERATOR
public static final short OPEN_DIALOG
public static final short SAVE_DIALOG
public static java.lang.String CLASSPATH
public static java.lang.String USERHOME
public static java.lang.String USERDIR
private static java.lang.String CLASSNAME
public static final short METAL_LOOKANDFEEL
public static final short WINDOZE_LOOKANDFEEL
public static final short MOTIF_LOOKANDFEEL
public static final short MAC_LOOKANDFEEL
public static final short DEFAULT_LOOKANDFEEL
public static java.lang.String macClassName
public static java.lang.String metalClassName
public static java.lang.String motifClassName
public static java.lang.String windowsClassName
private static Log log_
private static boolean initUtil
Constructor Detail |
public Util()
Method Detail |
private static void initUtil()
public static void ensureFolderExists(java.io.File folder)
folder
- The File object to check.public static void ensureFolderExists(java.lang.String foldername)
public static boolean moveFile(java.lang.String filename, java.lang.String foldername)
filename
- is the absoulte pathname of the file to move.foldername
- is the directory to move it to.public static java.lang.String toHEXString(byte b)
b
- The byte to convert
public static void setIconForApp(javax.swing.JFrame appFrame, java.lang.String imageFilename)
imageFilename
- - is the filename for the new iconappFrame
- The new iconForApp valuepublic static void setIconForApp(javax.swing.JFrame appFrame, java.net.URL imageUrl)
imageUrl
- - is the URL for the new iconappFrame
- The new iconForApp valuepublic static java.lang.String createCurrentDateStamp()
public static java.lang.String createCurrentDateTimeStamp()
public static java.lang.String createCurrentTimeStamp()
public static java.lang.String createTimerTimeStamp(int startTimeMillis)
public static java.lang.String tokenReplace(java.lang.String sentence, java.lang.String token, java.lang.String replacement)
sentence
- The String to perform the token replacement ontoken
- the token String to seartch for and replacereplacement
- the tokens replacement value
public static boolean removeDir(java.lang.String fileName)
fileName
- The filename of the directory to delete.public static boolean removeFile(java.lang.String fileName)
fileName
- The filename to delete.public static boolean removeOldFiles(java.lang.String dirName, int numDays, boolean recurse)
dirName
- The directory to parse for files to delete.numDays
- The age of the files to delete.recurse
- Do the removal recursively.public static long dirSize(java.lang.String fileName, boolean recurseSubdirs)
fileName
- The filename of the directory to delete.
public static java.util.Hashtable searchInFile(java.lang.String searchStr, java.lang.String filename, boolean recurseSubdirs, boolean fileRegExp, boolean verbose)
searchStr
- The searchString/regexp to search for.filename
- The filename/directoryName to search through.recurseSubdirs
- Flags if the sub-dirs are searched.fileRegExp
- Flags if 'fileName' should be regarded as a regular
expression.verbose
- true will produce output to System.out just like the
UNIX find cmd
public static java.util.Vector findFile(java.lang.String fileName, java.lang.String directory, boolean recurseSubdirs, boolean regExp, boolean verbose)
fileName
- The filename/regexp to search for.directory
- The filename of the directory to delete.recurseSubdirs
- Flags if the sub-dirs are searched.regExp
- Flags if 'fileName' should be regarded as a regular
expression.verbose
- true will produce output to System.out just like the
UNIX find cmd
public static java.io.File initDirFile(java.lang.String s)
s
- the directory name to init as a File
public static java.lang.String spacesToCapsInString(java.lang.String fName)
fName
- a string perform the action
public static java.lang.String capsToSpacesInString(java.lang.String fName)
fName
- a string perform the action
public static java.lang.String getFilePathFromClasspath(java.lang.String filename, java.lang.String fallBack)
filename
- to look for in the classpathfallBack
- if the file is not found in classpath
public static java.lang.String getFilePathFromClasspath(java.lang.String filename)
filename
- the filename to look for
public static java.awt.Frame getAncestorFrame(java.awt.Component c)
c
- The Component to be used as the basis of the frame search
public static void setTheLookAndFeel(short i, java.awt.Component comp)
i
- The new TheLookAndFeel valuepublic static java.awt.Image loadImage(java.lang.String imageFilename, java.lang.String jarFilename)
imageFilename
- the filename in the jarfile to use as the basis for
the Image to retrieve.jarFilename
- the jar file to look through for the image.
public static java.awt.Image loadImage(java.lang.String imageFilename)
imageFilename
- the filename in the jarfile to use as the basis for
the Image to retrieve.
public static boolean sleep(long waitTime)
waitTime
- the sleep time in milli seconds (ms).
public static java.lang.String chooseAFilename(java.awt.Component parent, java.lang.String startPath)
NO file filters will be used and NO directory selection is allowed.
parent
- the owner of this dialog (generally just send this)startPath
- the dir to start the file chooser dialog from
public static java.lang.String chooseAFilename(java.awt.Component parent, java.lang.String startPath, ExampleFileFilter[] filters, boolean filesAndDirs)
This method requires all the config parms specified by the ExampleFileFilter.
parent
- the owner of this dialog (generally just send this)startPath
- the dir to start the file chooser dialog fromfilters
- an array holding the Filters to use in the dialogfilesAndDirs
- specs if the user will be allowed to choose both
files or dirs.
public static java.lang.String chooseAFilename(java.awt.Component parent, java.lang.String startPath, ExampleFileFilter[] filters, boolean filesAndDirs, short openOrClose)
This method requires all the config parms specified by the ExampleFileFilter.
parent
- the owner of this dialog (generally just send this)startPath
- the dir to start the file chooser dialog fromfilters
- an array holding the Filters to use in the dialogfilesAndDirs
- specs if the user will be allowed to choose both
files or dirs.openOrClose
- Description of the Parameter
public static java.lang.String absoluteToPwdRelativePath(java.io.File absPath)
absPath
- is the File to use to to convert
public static java.lang.String absoluteToPwdRelativePath(java.lang.String absPath)
absPath
- is the absolute path to convert
public static java.lang.String removeParentRelativeReference(java.lang.String path)
path
- is the absolute path to convert
public static java.io.File getFileDir(java.lang.String fileString)
fileString
- is the filename to get the dir forpublic static java.net.URL getFileBaseURL(java.lang.String fileString)
fileString
- is the filename to turn into a file://URL
public static java.net.URL[] getFileBaseURLs(java.lang.String[] fileStrings)
fileStrings
- Description of Parameter
public static java.net.InetAddress getLocalhostName()
public static int executeNativeApp(java.lang.String executableLocation, java.lang.String[] appParms, java.lang.String outFilename)
executableLocation
- is the path to the executable to runappParms
- and extra commandline parameters to tag onto the
end of the commandline that gets executed.outFilename
- an outputFile to dump the exe output.
StreamGobbler
,
Runtime.getRuntime()
public static int executeNativeApp(java.lang.String executableLocation, java.util.Vector appParms, java.lang.String outFilename)
executableLocation
- is the path to the executable to runappParms
- and extra commandline parameters to tag onto the
end of the commandline that gets executed.outFilename
- an outputFile to dump the exe output.
StreamGobbler
,
Runtime.getRuntime()
public static java.util.Date getCurrentDate()
public static long countFilesInDir(java.lang.String dirName, boolean recurse)
dirName
- recurse
-
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |