com.horstmann.violet.framework
Class FileService

java.lang.Object
  extended by com.horstmann.violet.framework.FileService

public abstract class FileService
extends java.lang.Object


Nested Class Summary
static interface FileService.Open
          An Open object encapsulates the stream and name of the file that the user selected for opening.
static interface FileService.Save
          A Save object encapsulates the stream and name of the file that the user selected for saving.
 
Constructor Summary
FileService()
           
 
Method Summary
static java.lang.String editExtension(java.lang.String original, java.lang.String toBeRemoved, java.lang.String desired)
          Edits the file path so that it ends in the desired extension.
static FileService getInstance(java.io.File initialDirectory)
          Gets a service that is appropriate for the mode in which this program works.
abstract  boolean isWebStart()
          Tests whether the service is provided by WebStart
abstract  FileService.Open open(java.lang.String defaultDirectory, java.lang.String defaultFile, ExtensionFilter extensions)
          Gets an Open object that encapsulates the stream and name of the file that the user selected
abstract  FileService.Save save(java.lang.String defaultDirectory, java.lang.String defaultFile, ExtensionFilter extensions, java.lang.String removeExtension, java.lang.String addExtension)
          Gets a Save object that encapsulates the stream and name of the file that the user selected (or will select)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileService

public FileService()
Method Detail

getInstance

public static FileService getInstance(java.io.File initialDirectory)
Gets a service that is appropriate for the mode in which this program works.

Returns:
a service for local dialogs or for Java Web Start

isWebStart

public abstract boolean isWebStart()
Tests whether the service is provided by WebStart

Returns:
true if this service is provided by WebStart

open

public abstract FileService.Open open(java.lang.String defaultDirectory,
                                      java.lang.String defaultFile,
                                      ExtensionFilter extensions)
                               throws java.io.IOException
Gets an Open object that encapsulates the stream and name of the file that the user selected

Parameters:
defaultDirectory - the default directory for the file chooser
defaultFile - the default file for the file chooser
extensions - the extension filter
Returns:
the Open object for the selected file
Throws:
java.io.IOException

save

public abstract FileService.Save save(java.lang.String defaultDirectory,
                                      java.lang.String defaultFile,
                                      ExtensionFilter extensions,
                                      java.lang.String removeExtension,
                                      java.lang.String addExtension)
                               throws java.io.IOException
Gets a Save object that encapsulates the stream and name of the file that the user selected (or will select)

Parameters:
defaultDirectory - the default directory for the file chooser
defaultFile - the default file for the file chooser
extensions - the extension filter
removeExtension - the extension to remove from the default file name
addExtension - the extension to add to the file name
Returns:
the Save object for the selected file
Throws:
java.io.IOException

editExtension

public static java.lang.String editExtension(java.lang.String original,
                                             java.lang.String toBeRemoved,
                                             java.lang.String desired)
Edits the file path so that it ends in the desired extension.

Parameters:
original - the file to use as a starting point
toBeRemoved - the extension that is to be removed before adding the desired extension. Use null if nothing needs to be removed.
desired - the desired extension (e.g. ".png"), or a | separated list of extensions
Returns:
original if it already has the desired extension, or a new file with the edited file path