org.jext
Class Utilities

java.lang.Object
  extended by org.jext.Utilities
Direct Known Subclasses:
DawnUtilities

public class Utilities
extends java.lang.Object

This class contains a bunch of methods, useful for the programmer.

Version:
2.3.0
Author:
Romain Guy, Slava Pestov, James Gosling, Paolo Giarrusso
See Also:
Jext

Field Summary
static java.lang.String JDK_VERSION
          JDK release version.
static int OPEN
          This constant defines an open dialog box.
static int SAVE
          This constant defines a save dialog box.
static int SCRIPT
          This constant defines an open dialog box.
 
Constructor Summary
Utilities()
           
 
Method Summary
static void beep()
          Used to 'beep' the user.
static boolean beginsWithRoot(java.lang.String path)
          It can be necessary to check if a path specified by the user is an absolute path (i.e C:\Gfx\3d\Utils is absolute whereas ..\Jext is relative).
static void centerComponent(java.awt.Component compo)
          A very nice trick is to center windows on screen, this method helps you to to that.
static void centerComponentChild(java.awt.Component parent, java.awt.Component child)
          A very nice trick is to center dialog with their parent.
static java.lang.String chooseFile(java.awt.Component owner, int mode)
          Display a file chooser dialog box.
static java.lang.String[] chooseFiles(java.awt.Component owner, int mode)
          Display a file chooser dialog box and returns selected files.
static java.lang.String classToFile(java.lang.String name)
          Converts a clas name to a file name.
static java.lang.String constructPath(java.lang.String change)
          Constructs a new path from current user path.
static void copy(java.io.InputStream in, java.io.OutputStream out, boolean threaded)
          Convenience method for calling
static void copy(java.io.InputStream in, java.io.OutputStream out, boolean threaded, HandlingRunnable notify)
          Deprecated. maybe, use the version with a CopyThread as second parameter instead(I think it's cleaner, this version should go away).
static java.lang.String createWhiteSpace(int len)
          Create a blank String made of spaces.
static java.lang.String createWhiteSpace(int len, int tabSize)
          Create a blank String made of tabs.
static void downloadFile(java.net.URL source, java.lang.String outPath, boolean threaded)
           
static void downloadFile(java.net.URL source, java.lang.String outPath, boolean threaded, HandlingRunnable notify)
          Downloads the file specified in the URL to the File with the outPath path using copy() (so see copy() for infos about notify and threaded).
static java.lang.String fileToClass(java.lang.String name)
          Converts a file name to a class name.
static java.lang.String getHomeDirectory()
          Returns user's home directory.
static javax.swing.ImageIcon getIcon(java.lang.String picture, java.lang.Class source)
          We may need to load and display images.
static java.awt.Image getImage(java.lang.String picture, java.lang.Class source)
          We may need to load and display images.
static int getLeadingWhiteSpace(java.lang.String str)
          Returns the number of leading white space characters in the specified string.
static int getLeadingWhiteSpaceWidth(java.lang.String str, int tabSize)
          Returns the width of the leading white space in the specified string.
static int getRealLength(java.lang.String str, int tabSize)
           
static java.lang.String getRoot(java.lang.String path)
          It can be necessary to determine which is the root of a path.
static java.awt.Dimension getScreenDimension()
          This methods is used to determine screen's dimensions.
static java.lang.String getShortStringOf(java.lang.String longString, int maxLength)
          Some String can be too long to be correctly displayed on the screen.
static java.lang.String getUserDirectory()
          Returns user directory.
static java.lang.String[] getWildCardMatches(java.lang.String s, boolean sort)
          When the user has to specify file names, he can use wildcards (*, ?).
static java.lang.String[] getWildCardMatches(java.lang.String path, java.lang.String s, boolean sort)
          When the user has to specify file names, he can use wildcards (*, ?).
static java.lang.String globToRE(java.lang.String glob)
          Turns a Un*x glob filter to regexp one
static java.io.File[] listFiles(java.lang.String[] names, boolean construct)
          Lists content of a directory.
static java.io.File[] listFiles(java.lang.String[] names, java.lang.String path, boolean construct)
          Lists content of a directory.
static boolean match(java.lang.String pattern, java.lang.String string)
          This method can determine if a String matches a pattern of wildcards
static void setCursorOnWait(java.awt.Component comp, boolean on)
          Long operations need to display an hourglass.
static void showError(java.lang.String message)
          Display an error message in a dialog box.
static void showMessage(java.lang.String message)
          Display a sample message in a dialog box.
static void showMessage(java.lang.String title, java.lang.String message)
          Display a sample message in a dialog box.
static void sortStrings(java.lang.String[] strings)
          Deprecated. Use the standard Java java.util.Array.sort instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN

public static final int OPEN
This constant defines an open dialog box.

See Also:
Constant Field Values

SAVE

public static final int SAVE
This constant defines a save dialog box.

See Also:
Constant Field Values

SCRIPT

public static final int SCRIPT
This constant defines an open dialog box.

See Also:
Constant Field Values

JDK_VERSION

public static final java.lang.String JDK_VERSION
JDK release version.

Constructor Detail

Utilities

public Utilities()
Method Detail

showMessage

public static void showMessage(java.lang.String message)
Display a sample message in a dialog box.

Parameters:
message - The message to display

showError

public static void showError(java.lang.String message)
Display an error message in a dialog box.

Parameters:
message - The message to display

showMessage

public static void showMessage(java.lang.String title,
                               java.lang.String message)
Display a sample message in a dialog box.

Parameters:
message - The message to display

getScreenDimension

public static java.awt.Dimension getScreenDimension()
This methods is used to determine screen's dimensions.

Returns:
A Dimension object containing screen's resolution

centerComponent

public static void centerComponent(java.awt.Component compo)
A very nice trick is to center windows on screen, this method helps you to to that.

Parameters:
compo - The Component to center

centerComponentChild

public static void centerComponentChild(java.awt.Component parent,
                                        java.awt.Component child)
A very nice trick is to center dialog with their parent.

Parameters:
parent - The parent Component
child - The Component to center

classToFile

public static java.lang.String classToFile(java.lang.String name)
Converts a clas name to a file name. All periods are replaced with slashes and the '.class' extension is added.

Parameters:
name - The class name

fileToClass

public static java.lang.String fileToClass(java.lang.String name)
Converts a file name to a class name. All slash characters are replaced with periods and the trailing '.class' is removed.

Parameters:
name - The file name

beep

public static void beep()
Used to 'beep' the user.


setCursorOnWait

public static void setCursorOnWait(java.awt.Component comp,
                                   boolean on)
Long operations need to display an hourglass.

Parameters:
comp - The JComponent on which to apply the hour glass cursor
on - If true, we set the cursor on the hourglass

getIcon

public static javax.swing.ImageIcon getIcon(java.lang.String picture,
                                            java.lang.Class source)
We may need to load and display images.

Parameters:
picture - The path to the image
source - The class 'root'
Returns:
An ImageIcon

getImage

public static java.awt.Image getImage(java.lang.String picture,
                                      java.lang.Class source)
We may need to load and display images.

Parameters:
picture - The path to the image
source - The class 'root'
Returns:
An Image

chooseFiles

public static java.lang.String[] chooseFiles(java.awt.Component owner,
                                             int mode)
Display a file chooser dialog box and returns selected files.

Parameters:
owner - Component which 'owns' the dialog
mode - Can be either OPEN, SCRIPT or SAVE
Returns:
The path to selected file, null otherwise

chooseFile

public static java.lang.String chooseFile(java.awt.Component owner,
                                          int mode)
Display a file chooser dialog box.

Parameters:
owner - Component which 'owns' the dialog
mode - Can be either OPEN, SCRIPT or SAVE
Returns:
The path to selected file, null otherwise

createWhiteSpace

public static java.lang.String createWhiteSpace(int len)
Create a blank String made of spaces.

Parameters:
len - Amount of spaces contained in the String
Returns:
A blank String

createWhiteSpace

public static java.lang.String createWhiteSpace(int len,
                                                int tabSize)
Create a blank String made of tabs.

Parameters:
len - Amount of spaces contained in the String
tabSize - Tabulation size
Returns:
A blank String

getLeadingWhiteSpace

public static int getLeadingWhiteSpace(java.lang.String str)
Returns the number of leading white space characters in the specified string.

Parameters:
str - The string

getLeadingWhiteSpaceWidth

public static int getLeadingWhiteSpaceWidth(java.lang.String str,
                                            int tabSize)
Returns the width of the leading white space in the specified string.

Parameters:
str - The string
tabSize - The tab size

getRealLength

public static int getRealLength(java.lang.String str,
                                int tabSize)

getShortStringOf

public static java.lang.String getShortStringOf(java.lang.String longString,
                                                int maxLength)
Some String can be too long to be correctly displayed on the screen. Mainly when it is a path to a file. This method truncate a String.

Parameters:
longString - The String to be truncated
maxLength - The maximum length of the String
Returns:
The truncated string

constructPath

public static java.lang.String constructPath(java.lang.String change)
Constructs a new path from current user path. This is an easy way to get a path if the user specified, for example, "..\Java" as new path. This method will return the argument if this one is a path to a root (i.e, if change is equal to C:\Jdk, constructPath will return C:\Jdk).

Parameters:
change - The modification to apply to the path

beginsWithRoot

public static boolean beginsWithRoot(java.lang.String path)
It can be necessary to check if a path specified by the user is an absolute path (i.e C:\Gfx\3d\Utils is absolute whereas ..\Jext is relative).

Parameters:
path - The path to check
Returns:
true if path begins with a root name

getUserDirectory

public static java.lang.String getUserDirectory()
Returns user directory.


getHomeDirectory

public static java.lang.String getHomeDirectory()
Returns user's home directory.


getRoot

public static java.lang.String getRoot(java.lang.String path)
It can be necessary to determine which is the root of a path. For example, the root of D:\Projects\Java is D:\.

Parameters:
path - The path used to get a root
Returns:
The root which contais the specified path

getWildCardMatches

public static java.lang.String[] getWildCardMatches(java.lang.String s,
                                                    boolean sort)
When the user has to specify file names, he can use wildcards (*, ?). This methods handles the usage of these wildcards.

Parameters:
s - Wilcards
sort - Set to true will sort file names
Returns:
An array of String which contains all files matching s in current directory.

getWildCardMatches

public static java.lang.String[] getWildCardMatches(java.lang.String path,
                                                    java.lang.String s,
                                                    boolean sort)
When the user has to specify file names, he can use wildcards (*, ?). This methods handles the usage of these wildcards.

Parameters:
path - The path were to search
s - Wilcards
sort - Set to true will sort file names
Returns:
An array of String which contains all file names matching s in path directory.

match

public static boolean match(java.lang.String pattern,
                            java.lang.String string)
This method can determine if a String matches a pattern of wildcards

Parameters:
pattern - The pattern used for comparison
string - The String to be checked
Returns:
true if string matches pattern

sortStrings

public static void sortStrings(java.lang.String[] strings)
Deprecated. Use the standard Java java.util.Array.sort instead.

Quick sort an array of Strings.

Parameters:
string - Strings to be sorted

listFiles

public static java.io.File[] listFiles(java.lang.String[] names,
                                       boolean construct)
Lists content of a directory.

Parameters:
names - Names of the files
construct - Set it to true if names does not contain full paths
Returns:
An array of Files

listFiles

public static java.io.File[] listFiles(java.lang.String[] names,
                                       java.lang.String path,
                                       boolean construct)
Lists content of a directory.

Parameters:
names - Names of the files
path - Base path for files
construct - Set it to true if names do not contain full paths
Returns:
An array of Files

globToRE

public static java.lang.String globToRE(java.lang.String glob)
Turns a Un*x glob filter to regexp one

Parameters:
glob - Globbed filter

downloadFile

public static void downloadFile(java.net.URL source,
                                java.lang.String outPath,
                                boolean threaded)
                         throws java.io.IOException
Throws:
java.io.IOException
Since:
Jext 3.2pre4

downloadFile

public static void downloadFile(java.net.URL source,
                                java.lang.String outPath,
                                boolean threaded,
                                HandlingRunnable notify)
                         throws java.io.IOException
Downloads the file specified in the URL to the File with the outPath path using copy() (so see copy() for infos about notify and threaded).

Throws:
java.io.IOException
Since:
Jext 3.2pre4

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        boolean threaded)
                 throws java.io.IOException
Convenience method for calling

Throws:
java.io.IOException
Since:
Jext 3.2pre4

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        boolean threaded,
                        HandlingRunnable notify)
                 throws java.io.IOException
Deprecated. maybe, use the version with a CopyThread as second parameter instead(I think it's cleaner, this version should go away).

This method copy the content of the InputStream in to the OutputStream out, in the calling thread or in a new one. If threaded is true, a new thread is created, and notify will be called at the end, and will have passed the exception eventually thrown while doing the copy. Otherwise, the copy is done synchronously; if an exception is thrown during the copy it is dispatched to the calling method, otherwise the notify is called.

Throws:
java.io.IOException
Since:
Jext 3.2pre4


Copyright ? 2002 Romain Guy.