jutil
Class JUtil

java.lang.Object
  extended by jutil.JUtil

public final class JUtil
extends Object

A Windows®-specific Java utility class.

Version:
1.0
Author:
Pat Paternostro, Tri-Com Consulting Group L.L.C.

Field Summary
static int DRIVE_CDROM
          The drive is a CD-ROM drive.
static int DRIVE_FIXED
          The disk cannot be removed from the drive.
static int DRIVE_NO_ROOT_DIR
          The root directory does not exist.
static int DRIVE_RAMDISK
          The drive is a RAM disk.
static int DRIVE_REMOTE
          The drive is a remote (network) drive.
static int DRIVE_REMOVABLE
          The disk can be removed from the drive.
static int DRIVE_UNKNOWN
          The drive type cannot be determined.
 
Constructor Summary
private JUtil()
           
 
Method Summary
static void copyFile(String source, String dest)
          Copies the specified source file to the specified destination file.
static char getConsoleChar()
          Retrieves the character typed at the command console.
static String getCurrentDirectory()
          Retrieves the current directory.
static int getDriveType(String drive)
          Retrieves the specified drive's type.
static long getFreeDiskSpace(String drive)
          Retrieves the specified drive's free disk space.
static int getHwnd(String title)
          Retrieves the Win32® window handle for the specified window title.
static String[] getLogicalDrives()
          Retrieves the system's logical drives.
static String getVolumeLabel(String drive)
          Retrieves the specified volume's label.
static void setContainerDefaultFont(Container cont, Font f)
          Sets the specified container's components to the specified font.
static boolean setCurrentDirectory(String directory)
          Sets the current directory.
static void setMenuBarDefaultFont(MenuBar mb, Font f)
          Sets the specified menubar's menus and menu items to the specified font.
static void setWindowAlwaysOnTop(int hwnd, boolean flag)
          Sets the specified window as the topmost window in the z-order.
static void setWindowMaximized(int hwnd)
          Maximizes the specified window.
static void setWindowMaximizeEnabled(int hwnd, boolean flag)
          Enables/disables the specified window's Maximize button.
static void setWindowMinimized(int hwnd)
          Minimizes the specified window.
static void setWindowMinimizeEnabled(int hwnd, boolean flag)
          Enables/disables the specified window's Minimize button.
static void setWindowMoveEnabled(int hwnd, boolean flag)
          Enables/disables the specified window's Move system menu item.
static void setWindowRestored(int hwnd)
          Restores the specified window.
static void setWindowRestoreEnabled(int hwnd, boolean flag)
          Enables/disables the specified window's Restore button.
static void setWindowSizeEnabled(int hwnd, boolean flag)
          Enables/disables the specified window's Size system menu item.
static boolean setVolumeLabel(String drive, String label)
          Sets the specified volume's label.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRIVE_UNKNOWN

public static final int DRIVE_UNKNOWN
The drive type cannot be determined.

See Also:
Constant Field Values

DRIVE_NO_ROOT_DIR

public static final int DRIVE_NO_ROOT_DIR
The root directory does not exist.

See Also:
Constant Field Values

DRIVE_REMOVABLE

public static final int DRIVE_REMOVABLE
The disk can be removed from the drive.

See Also:
Constant Field Values

DRIVE_FIXED

public static final int DRIVE_FIXED
The disk cannot be removed from the drive.

See Also:
Constant Field Values

DRIVE_REMOTE

public static final int DRIVE_REMOTE
The drive is a remote (network) drive.

See Also:
Constant Field Values

DRIVE_CDROM

public static final int DRIVE_CDROM
The drive is a CD-ROM drive.

See Also:
Constant Field Values

DRIVE_RAMDISK

public static final int DRIVE_RAMDISK
The drive is a RAM disk.

See Also:
Constant Field Values
Constructor Detail

JUtil

private JUtil()
Method Detail

getConsoleChar

public static char getConsoleChar()
Retrieves the character typed at the command console.

Returns:
the character typed at the command console

getLogicalDrives

public static String[] getLogicalDrives()
Retrieves the system's logical drives.

Returns:
an array of String objects that contains the logical drive names in the form of x:\ where x denotes the drive letter

getFreeDiskSpace

public static long getFreeDiskSpace(String drive)
Retrieves the specified drive's free disk space.

Parameters:
drive - a String that specifies the root directory of the disk to return free disk space information about. If drive is null the method uses the root of the current directory.
Returns:
the free disk space in bytes
See Also:
getLogicalDrives()

getDriveType

public static int getDriveType(String drive)
Retrieves the specified drive's type.

Parameters:
drive - a String that specifies the root directory of the disk to return the drive type information about. If drive is null the method uses the root of the current directory.
Returns:
an int that specifies the drive type
See Also:
getLogicalDrives(), DRIVE_UNKNOWN, DRIVE_NO_ROOT_DIR, DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_REMOTE, DRIVE_CDROM, DRIVE_RAMDISK

getVolumeLabel

public static String getVolumeLabel(String drive)
Retrieves the specified volume's label.

Parameters:
drive - a String that specifies the root directory of the disk to return the volume label. If drive is null the method uses the root of the current directory.
Returns:
a String containing the specified volume's label
See Also:
getLogicalDrives()

setVolumeLabel

public static boolean setVolumeLabel(String drive,
                                     String label)
Sets the specified volume's label.

Parameters:
drive - a String that specifies the root directory of the disk to set the volume label. If drive is null the method uses the root of the current directory.
label - a String that represents the volume's label name. The maximum number of characters for a volume label is 11. If label is more that 11 characters long the volume's label will not be set. If label is null the specified volume's label is deleted.
Returns:
a boolean specifying whether the volume's label was set. true if the volume's label was set, false otherwise.
See Also:
getLogicalDrives()

getCurrentDirectory

public static String getCurrentDirectory()
Retrieves the current directory.

Returns:
a String representing the current directory

setCurrentDirectory

public static boolean setCurrentDirectory(String directory)
Sets the current directory.

Parameters:
directory - a String that specifies the current directory to set
Returns:
a boolean indicating if the current directory was set. true if the current directory was set, false otherwise.

getHwnd

public static int getHwnd(String title)
Retrieves the Win32® window handle for the specified window title.

Parameters:
title - the title of the window whose Win32® window handle to retrieve
Returns:
an int representing the Win32® window handle for the specified window title

setWindowMinimized

public static void setWindowMinimized(int hwnd)
Minimizes the specified window.

Parameters:
hwnd - the window's Win32® handle
See Also:
getHwnd(java.lang.String)

setWindowMaximized

public static void setWindowMaximized(int hwnd)
Maximizes the specified window.

Parameters:
hwnd - the window's Win32® handle
See Also:
getHwnd(java.lang.String)

setWindowRestored

public static void setWindowRestored(int hwnd)
Restores the specified window.

Parameters:
hwnd - the window's Win32® handle
See Also:
getHwnd(java.lang.String)

setWindowRestoreEnabled

public static void setWindowRestoreEnabled(int hwnd,
                                           boolean flag)
Enables/disables the specified window's Restore button.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether to enable or disable the window's Restore button. true enables the button, false disables the button.
See Also:
getHwnd(java.lang.String)

setWindowMoveEnabled

public static void setWindowMoveEnabled(int hwnd,
                                        boolean flag)
Enables/disables the specified window's Move system menu item.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether to enable or disable the window's Move system menu item. true enables the menu item, false disables the menu item.
See Also:
getHwnd(java.lang.String)

setWindowSizeEnabled

public static void setWindowSizeEnabled(int hwnd,
                                        boolean flag)
Enables/disables the specified window's Size system menu item.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether to enable or disable the window's Size system menu item. true enables the menu item, false disables the menu item.
See Also:
getHwnd(java.lang.String)

setWindowMinimizeEnabled

public static void setWindowMinimizeEnabled(int hwnd,
                                            boolean flag)
Enables/disables the specified window's Minimize button.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether to enable or disable the window's Minimize button. true enables the button, false disables the button.
See Also:
getHwnd(java.lang.String)

setWindowMaximizeEnabled

public static void setWindowMaximizeEnabled(int hwnd,
                                            boolean flag)
Enables/disables the specified window's Maximize button.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether to enable or disable the window's Maximize button. true enables the button, false disables the button.
See Also:
getHwnd(java.lang.String)

setWindowAlwaysOnTop

public static void setWindowAlwaysOnTop(int hwnd,
                                        boolean flag)
Sets the specified window as the topmost window in the z-order.

Parameters:
hwnd - the window's Win32® handle
flag - a boolean parameter that specifies whether the window will be the topmost window in the z-order. true sets the window as the topmost window in the z-order, false sets the window behind all topmost windows.
See Also:
getHwnd(java.lang.String)

setContainerDefaultFont

public static void setContainerDefaultFont(Container cont,
                                           Font f)
                                    throws IllegalArgumentException
Sets the specified container's components to the specified font.

Parameters:
cont - the Container whose components will be set with the specified font
f - the Font object that will be used
Throws:
IllegalArgumentException - if cont or f are null
See Also:
Container, Font

setMenuBarDefaultFont

public static void setMenuBarDefaultFont(MenuBar mb,
                                         Font f)
                                  throws IllegalArgumentException
Sets the specified menubar's menus and menu items to the specified font.

Parameters:
mb - the MenuBar whose menus and menu items will be set with the specified font
f - the Font object that will be used
Throws:
IllegalArgumentException - if mb or f are null
See Also:
MenuBar, Font

copyFile

public static void copyFile(String source,
                            String dest)
                     throws IllegalArgumentException,
                            FileNotFoundException,
                            IOException
Copies the specified source file to the specified destination file.

Parameters:
source - the source file name
dest - the destination file name
Throws:
IllegalArgumentException - if the source or dest file names are null or empty
FileNotFoundException - if the source file name does not exist
IOException - if a problem was encountered reading from the source file or writing to the destination file