VdexReload 1.1.3 API

uk.ac.reload.dweezil.util
Class ReloadUtils

java.lang.Object
  extended byuk.ac.reload.dweezil.util.ReloadUtils
All Implemented Interfaces:
DweezilConstants

public final class ReloadUtils
extends java.lang.Object
implements DweezilConstants

Some useful General Utilities


Field Summary
static int MACINTOSH
          Macintosh OS
static int UNIX
          Unix OS
static int WINDOWS_2000
          Windows 2000
static int WINDOWS_9x
          Windows 98
static int WINDOWS_NT
          Windows NT
static int WINDOWS_XP
          Windows XP
 
Fields inherited from interface uk.ac.reload.dweezil.DweezilConstants
CR, DEBUG
 
Method Summary
static java.io.File askFileNameOpen(java.awt.Component parent, java.lang.String title, javax.swing.filechooser.FileFilter filter)
          Ask the user for a File name to open
static java.io.File askFileNameOpenUsingDirName(java.awt.Component parent, java.lang.String title, javax.swing.filechooser.FileFilter filter, java.io.File currentDir)
          Ask the user for a File name to open, the name of the current dir is given
static java.io.File askFileNameSave(java.awt.Component parent, java.lang.String title, javax.swing.filechooser.FileFilter filter, java.lang.String extension)
          Ask the user for a File name to save a Document as
static void centreWindow(java.awt.Window window, int width, int height)
          Centres a window on the screen given the size of window.
static void centreWindowProportional(java.awt.Window window, double width, double height)
          Centres a window on the screen given the proportional size of window.
static void copyFile(java.io.File srcFile, java.io.File destFile)
          Copy a File.
static boolean copyFolder(java.io.File srcFolder, java.io.File destFolder, ReloadProgressMonitor progressMonitor)
          Copy a Folder and all its files and sub-folder to target Folder Both Source Folder and Target Folder must exist
static int countFiles(java.io.File folder)
          Counts the total files & folders in a given folder
static void deleteFolder(java.io.File afolder)
          Delete a folder and its contents
static java.lang.Class getClassFromJar(java.lang.String className, java.io.File jarFile)
          Returns a class from a jar file that exists in the given folder
static java.lang.Object getClassInstanceFromJar(java.lang.String className, java.io.File jarFile)
          Returns a class New Instance from a jar file that exists in the given jar
static java.lang.String getFileExtension(java.io.File file)
          Get the extension portion of a filename.
static java.lang.String getFileNameWithoutExtension(java.io.File file)
          Get the name portion of a filename not including the extension.
static javax.swing.JInternalFrame getInternalFrameAncestor(java.awt.Component c)
           
static java.lang.String getJavaVersion()
          Get the version of Java we are on.
static java.lang.String getLocalFileURL(java.io.File file)
          Mac and Linux absolute file paths begin with "/" i.e /Users/fredbloggs/packages/index.htm so simply prepending "file:///" to obtain a valid URL will not work because we will end up with four forward slashes, which is an illegal URL This method examines the file reference and if it starts with a forward slash prepends "file://" instead of "file:///" and returns the String result
static java.util.Date getNow()
          Get the time as it is now.
static int getOS()
          Determine the OS we are running on.
static java.lang.String getRelativePath(java.io.File rootFolder, java.io.File file)
          Get a relative path for a file given its relationship to rootFolder
static java.net.URL getResourceURL(java.lang.String fileName)
          Gets a local resource URL.
This may be for example a help file or image that exists actually in the shipped jar.
static int getScreenHeight()
          Get the Screen Height
static int getScreenWidth()
          Get the Screen Width
static boolean isComponentInInternalFrame(java.awt.Component c)
           
static boolean isComponentInMainFrame(java.awt.Component c)
           
static boolean isJava14()
          Make sure we've got java version 1.4.x.
static void launchFile(java.io.File file)
          Launch a File in the OS
static void launchFile(java.lang.String path)
          Launch a File by Path in the OS
static void moveFile(java.io.File srcFile, java.io.File destFile)
          Move a File
static java.lang.String parseDate(java.util.Date date)
          Parse a date to a short date string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MACINTOSH

public static final int MACINTOSH
Macintosh OS

See Also:
Constant Field Values

WINDOWS_XP

public static final int WINDOWS_XP
Windows XP

See Also:
Constant Field Values

WINDOWS_9x

public static final int WINDOWS_9x
Windows 98

See Also:
Constant Field Values

WINDOWS_NT

public static final int WINDOWS_NT
Windows NT

See Also:
Constant Field Values

WINDOWS_2000

public static final int WINDOWS_2000
Windows 2000

See Also:
Constant Field Values

UNIX

public static final int UNIX
Unix OS

See Also:
Constant Field Values
Method Detail

getOS

public static int getOS()
Determine the OS we are running on.

Returns:
The OS we are running on:-
0 - MACINTOSH
1 - WINDOWS
2 - UNIX
3 - NT

getJavaVersion

public static java.lang.String getJavaVersion()
Get the version of Java we are on.

Returns:
The version

isJava14

public static boolean isJava14()
Make sure we've got java version 1.4.x.

Returns:
true if we are running on Java 1.4.x

parseDate

public static java.lang.String parseDate(java.util.Date date)
Parse a date to a short date string.

Parameters:
date - The date to parse
Returns:
A String representation of the date such as "25-12-2002"

getNow

public static java.util.Date getNow()
Get the time as it is now.

Returns:
The Time Now

getFileExtension

public static java.lang.String getFileExtension(java.io.File file)
Get the extension portion of a filename.

Parameters:
file - The File in question
Returns:
The extension part of the filename excluding the "."

getFileNameWithoutExtension

public static java.lang.String getFileNameWithoutExtension(java.io.File file)
Get the name portion of a filename not including the extension.

Parameters:
file - The File in question
Returns:
The name part of a file name excluding the extension

copyFolder

public static boolean copyFolder(java.io.File srcFolder,
                                 java.io.File destFolder,
                                 ReloadProgressMonitor progressMonitor)
                          throws java.io.IOException
Copy a Folder and all its files and sub-folder to target Folder Both Source Folder and Target Folder must exist

Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File srcFile,
                            java.io.File destFile)
                     throws java.io.IOException
Copy a File. The Source file must exist. The target file will be created.

Throws:
java.io.IOException

moveFile

public static void moveFile(java.io.File srcFile,
                            java.io.File destFile)
                     throws java.io.IOException
Move a File

Throws:
java.io.IOException

deleteFolder

public static void deleteFolder(java.io.File afolder)
                         throws java.io.IOException
Delete a folder and its contents

Parameters:
afolder - - a folder
Throws:
java.io.IOException

countFiles

public static int countFiles(java.io.File folder)
Counts the total files & folders in a given folder

Parameters:
folder - The folder parent to count in
Returns:
The number of files & folders in folder

centreWindowProportional

public static void centreWindowProportional(java.awt.Window window,
                                            double width,
                                            double height)
Centres a window on the screen given the proportional size of window. It does not show the window.

Parameters:
window - The Window to centre
width - The width of the Window as a percentage of the Screen Width
height - The height of the Window as a percentage of the Screen Height

centreWindow

public static void centreWindow(java.awt.Window window,
                                int width,
                                int height)
Centres a window on the screen given the size of window. It does not show the window.

Parameters:
window - The Window to centre
width - The width of the Window
height - The height of the Window

getScreenWidth

public static int getScreenWidth()
Get the Screen Width

Returns:
The width of the screen

getScreenHeight

public static int getScreenHeight()
Get the Screen Height

Returns:
The height of the screen

getResourceURL

public static java.net.URL getResourceURL(java.lang.String fileName)
Gets a local resource URL.
This may be for example a help file or image that exists actually in the shipped jar.

Parameters:
fileName - The filename of the Resource
Returns:
The URL of the Resource

getClassFromJar

public static java.lang.Class getClassFromJar(java.lang.String className,
                                              java.io.File jarFile)
Returns a class from a jar file that exists in the given folder

Parameters:
className - The name of the class required
jarFile - The file of the jar
Returns:
The class or null if could not be created

getClassInstanceFromJar

public static java.lang.Object getClassInstanceFromJar(java.lang.String className,
                                                       java.io.File jarFile)
Returns a class New Instance from a jar file that exists in the given jar

Parameters:
className - The name of the class required
jarFile - The file of the jar
Returns:
An instance of the class or null if it could not be created

getRelativePath

public static java.lang.String getRelativePath(java.io.File rootFolder,
                                               java.io.File file)
Get a relative path for a file given its relationship to rootFolder


getInternalFrameAncestor

public static javax.swing.JInternalFrame getInternalFrameAncestor(java.awt.Component c)
Returns:
the first JInternalFrame ancestor of c, or null if component is not contained inside a JInternalFrame or will return it if it actually is a frame

isComponentInMainFrame

public static boolean isComponentInMainFrame(java.awt.Component c)
Returns:
whether Component c belongs directly to the Reload Main Frame

isComponentInInternalFrame

public static boolean isComponentInInternalFrame(java.awt.Component c)
Returns:
whether Component c belongs in a JInternalFrame

getLocalFileURL

public static java.lang.String getLocalFileURL(java.io.File file)
Mac and Linux absolute file paths begin with "/" i.e /Users/fredbloggs/packages/index.htm so simply prepending "file:///" to obtain a valid URL will not work because we will end up with four forward slashes, which is an illegal URL This method examines the file reference and if it starts with a forward slash prepends "file://" instead of "file:///" and returns the String result

Returns:
a valid local URL reference as a string

launchFile

public static void launchFile(java.io.File file)
Launch a File in the OS


launchFile

public static void launchFile(java.lang.String path)
Launch a File by Path in the OS


askFileNameOpen

public static java.io.File askFileNameOpen(java.awt.Component parent,
                                           java.lang.String title,
                                           javax.swing.filechooser.FileFilter filter)
Ask the user for a File name to open

Returns:
File or null if cancelled

askFileNameOpenUsingDirName

public static java.io.File askFileNameOpenUsingDirName(java.awt.Component parent,
                                                       java.lang.String title,
                                                       javax.swing.filechooser.FileFilter filter,
                                                       java.io.File currentDir)
Ask the user for a File name to open, the name of the current dir is given

Parameters:
parent - the parent component
title - the open dialog title
filter - the File Filter
currentDir - the current directory to open
Returns:
File or null if cancelled

askFileNameSave

public static java.io.File askFileNameSave(java.awt.Component parent,
                                           java.lang.String title,
                                           javax.swing.filechooser.FileFilter filter,
                                           java.lang.String extension)
Ask the user for a File name to save a Document as

Parameters:
parent - the parent component of the dialog
title - the title to display on the dialog
filter - the file filter
extension - the default extension to use in case the user doesn't provide one (no dot)
Returns:
the File or null if cancelled

VdexReload 1.1.3 API