wt.clients.util
Class FileLocator

java.lang.Object
  extended bywt.clients.util.FileLocator

public class FileLocator
extends Object

General purpose file locator class. Currently uses java.awt.FileDialog but may be converted into a bean which inherits from FileDialog.


Nested Class Summary
(package private)  class FileLocator.LastAccessListener
          This inner class is used to keep track of the last path accessed.
 
Field Summary
private  FileAccess fileAccess
           
private  FileDialog fileDialog
           
private  Frame frame
           
private static String lastPath
          Keep track of the last path accessed by any FileLocator.
private  Hashtable listeners
           
static int LOAD
          Load mode indicator.
private  int mode
           
private  String path
           
private static String RESOURCE
           
static int SAVE
          Save mode indicator.
private  int status
           
static int STATUS_CANCEL
          File dialog was closed without file beind identified, returned by getStatus().
static int STATUS_INITIAL
          Initial or inactive status, returned by getStatus().
static int STATUS_OK
          File dialog was closed with file identified, returned by getStatus().
static int STATUS_SHOW
          File dialog showing status indicator, returned by getStatus().
static String UNIX_HOME
          The Unix home directory environment variable.
static String WINDOWS_TEMP
          The Windows temp directory environment variable.
 
Constructor Summary
FileLocator(Frame frame, int mode)
          Constructor which leaves FileLocator in a valid state for calling show().
FileLocator(Frame frame, String path, int mode)
          Constructor which leaves FileLocator in a valid state for calling show().
 
Method Summary
 void addFileLocatorListener(FileLocatorListener l)
          Add a listener to file locator events.
private  void fireFileLocatorEvent(int newStatus)
           
static String getDefaultDirectory()
          Return the default local directory path for the passed application data item.
static String getDefaultFileName()
          Return the default file name.
private  FileAccess getFileAccess()
           
private  FileDialog getFileDialog()
           
 Frame getFrame()
          Return the frame used to launch the dialog.
static String getLastPath()
          Return the last path accessed with a FileLocator.
 int getMode()
          Return the mode of file location, returns SAVE or LOAD.
 String getPath()
          Get the path.
 int getStatus()
          Return the status of the last operation.
static boolean isUnix()
          Test for Unix operating system.
static boolean isWindows()
          Test for Windows operating system.
static String parseDirectory(String path)
          File path parsing utility for determining directory path.
static String parseFilename(String path)
          File path parsing utility for determining file name.
 void removeFileLocatorListener(FileLocatorListener l)
          Remove a listener to file locator events.
protected  void setFrame(Frame newValue)
          Set the frame used to launch the dialog.
 void setMode(int newMode)
          Set the mode to SAVE or LOAD.
 void setPath(String newValue)
          Set the path.
protected  void setStatus(int newStatus)
           
 void show(boolean block)
          Show the file load dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SAVE

public static final int SAVE
Save mode indicator.

See Also:
Constant Field Values

LOAD

public static final int LOAD
Load mode indicator.

See Also:
Constant Field Values

WINDOWS_TEMP

public static final String WINDOWS_TEMP
The Windows temp directory environment variable. Used to determine a default path for local files.

See Also:
Constant Field Values

UNIX_HOME

public static final String UNIX_HOME
The Unix home directory environment variable. Used to determine a default path for local files.

See Also:
Constant Field Values

STATUS_INITIAL

public static final int STATUS_INITIAL
Initial or inactive status, returned by getStatus().

See Also:
Constant Field Values

STATUS_SHOW

public static final int STATUS_SHOW
File dialog showing status indicator, returned by getStatus().

See Also:
Constant Field Values

STATUS_OK

public static final int STATUS_OK
File dialog was closed with file identified, returned by getStatus().

See Also:
Constant Field Values

STATUS_CANCEL

public static final int STATUS_CANCEL
File dialog was closed without file beind identified, returned by getStatus().

See Also:
Constant Field Values

lastPath

private static String lastPath
Keep track of the last path accessed by any FileLocator.


RESOURCE

private static String RESOURCE

frame

private Frame frame

fileDialog

private FileDialog fileDialog

path

private String path

mode

private int mode

status

private int status

listeners

private Hashtable listeners

fileAccess

private FileAccess fileAccess
Constructor Detail

FileLocator

public FileLocator(Frame frame,
                   int mode)
Constructor which leaves FileLocator in a valid state for calling show(). This constructor initializes the file path from the results of the last FileLocator show (or search). This provides a global "memory" of the last file path accessed.


FileLocator

public FileLocator(Frame frame,
                   String path,
                   int mode)
Constructor which leaves FileLocator in a valid state for calling show(). Note that this constructor uses the path argument and will not use the most recently used path.

Method Detail

getStatus

public int getStatus()
Return the status of the last operation. May return STATUS_INITIAL, STATUS_SHOW, STATUS_OK or STATUS_CANCEL.


setStatus

protected void setStatus(int newStatus)

getFrame

public Frame getFrame()
Return the frame used to launch the dialog.


setFrame

protected void setFrame(Frame newValue)
Set the frame used to launch the dialog.


getPath

public String getPath()
Get the path.


setPath

public void setPath(String newValue)
Set the path.


getLastPath

public static String getLastPath()
Return the last path accessed with a FileLocator. If no previous path was accessed then a default directory and file name will be used.


getMode

public int getMode()
Return the mode of file location, returns SAVE or LOAD.


setMode

public void setMode(int newMode)
Set the mode to SAVE or LOAD.

Parameters:
newMode - The mode of operation.

show

public void show(boolean block)
Show the file load dialog. Currently blocking is not implemented.

Parameters:
block - Either block the thread or launch a new thread.

addFileLocatorListener

public void addFileLocatorListener(FileLocatorListener l)
Add a listener to file locator events.


removeFileLocatorListener

public void removeFileLocatorListener(FileLocatorListener l)
Remove a listener to file locator events.


getDefaultFileName

public static String getDefaultFileName()
Return the default file name.


getDefaultDirectory

public static String getDefaultDirectory()
Return the default local directory path for the passed application data item. The algorithm for determining the directory path is:
1. On Windcows default a location in the temp directory.
2. On Unix default a location in the user home directory.

Returns:
the default directory path for the content item, may be "". If not "" then it will be terminated with a directory delimiter.

parseDirectory

public static String parseDirectory(String path)
File path parsing utility for determining directory path.


parseFilename

public static String parseFilename(String path)
File path parsing utility for determining file name.


isWindows

public static boolean isWindows()
Test for Windows operating system.


isUnix

public static boolean isUnix()
Test for Unix operating system.


getFileAccess

private FileAccess getFileAccess()

getFileDialog

private FileDialog getFileDialog()

fireFileLocatorEvent

private void fireFileLocatorEvent(int newStatus)