com.jstatcom.io
Class FileSupport

java.lang.Object
  extended by com.jstatcom.io.FileSupport

public final class FileSupport
extends java.lang.Object

Support for convenient file selection. This class is a Singleton and can be accessed by the getInstance method.

Author:
A. Benkwitz, Markus Kraetzig

Method Summary
 java.io.File chooseDirectory(java.awt.Component parent, java.lang.String titleText)
          Lets the user choose a directory with the JFileChooser.
 FileSupportSettings getFileSupportSettings()
          Gets the settings instance according to the previously made file selections.
static FileSupport getInstance()
          Gets the Singleton instance of this class.
 DataHandlerTypes getSelectedImportHandlerType()
          Gets the handler type chosen for data import.
 DataHandlerTypes getSelectedSaveHandlerType()
          Gets the handler type chosen for data export.
 java.lang.String readTextFile(java.lang.String fileName)
          Reads the contents of a text file and returns it as a string.
 java.io.File saveDataFile(java.awt.Component parent, java.lang.String filenameShort, DataHandlerTypes... types)
          Selects a data file for saving with a file chooser.
 java.io.File saveProjectFile(java.awt.Component parent)
          Selects a project file for saving with a file chooser.
 void saveStringToFile(java.io.File file, java.lang.String stringDat, boolean append)
          Stores stringDat to file.
 java.io.File saveTextFile(java.awt.Component parent)
          Selects a text file for saving with a file chooser.
 java.io.File selectDataFile(java.awt.Component parent, DataHandlerTypes... types)
          Selects a data file to open with a file chooser.
 java.io.File selectProjectFile(java.awt.Component parent)
          Selects a project file to open with a file chooser.
 void setDefaultPath(java.lang.String newDefaultPath)
          Sets the directory that will be displayed as default selection when a file chooser is created.
 void setFileSupportSettings(FileSupportSettings settings)
          Sets the selected files and directories to the settings argument.
 void startWorkers()
          Starts the SwingWorker threads to create JFileChooser instances in the background.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

chooseDirectory

public java.io.File chooseDirectory(java.awt.Component parent,
                                    java.lang.String titleText)
Lets the user choose a directory with the JFileChooser.

Parameters:
parent - the parent component for the FileChooser Dialog
titleText - the title String for the dialog
Returns:
null if it was canceled, otherwise the directory that was chosen

getInstance

public static FileSupport getInstance()
Gets the Singleton instance of this class.

Returns:
unique instance of FileSupport

readTextFile

public java.lang.String readTextFile(java.lang.String fileName)
Reads the contents of a text file and returns it as a string.

Parameters:
fileName - of file ro read from
Returns:
a string with the text of the file
Throws:
java.lang.IllegalArgumentException - if (fileName == null)

saveDataFile

public java.io.File saveDataFile(java.awt.Component parent,
                                 java.lang.String filenameShort,
                                 DataHandlerTypes... types)
Selects a data file for saving with a file chooser. The last selected directory is displayed.

Parameters:
parent - the parent component for the dialogs
filenameShort - the selected filename without path, can be null
types - the data handler types, the last element will be set as default
Returns:
file if ok, null otherwise

saveProjectFile

public java.io.File saveProjectFile(java.awt.Component parent)
Selects a project file for saving with a file chooser. The last selected directory is displayed.

Parameters:
parent - the parent component for the dialogs
Returns:
file if ok, null otherwise

saveStringToFile

public void saveStringToFile(java.io.File file,
                             java.lang.String stringDat,
                             boolean append)
Stores stringDat to file.

Parameters:
file - the file to store stringDat to
stringDat - the string to save
append - true if string should be appended to existing file,

saveTextFile

public java.io.File saveTextFile(java.awt.Component parent)
Selects a text file for saving with a file chooser. The last selected directory is displayed.

Parameters:
parent - the parent component for the dialogs
Returns:
file if ok, null otherwise

selectDataFile

public java.io.File selectDataFile(java.awt.Component parent,
                                   DataHandlerTypes... types)
Selects a data file to open with a file chooser. The last selected directory is displayed.

Parameters:
parent - the parent component for the dialogs
types - the data handler types, the last element will be set as default
Returns:
file if ok, null otherwise

selectProjectFile

public java.io.File selectProjectFile(java.awt.Component parent)
Selects a project file to open with a file chooser. The last selected directory is displayed.

Parameters:
parent - the parent component for the dialogs
Returns:
file if ok, null otherwise

setDefaultPath

public void setDefaultPath(java.lang.String newDefaultPath)
Sets the directory that will be displayed as default selection when a file chooser is created. This should be set as program start. At further invocations of the file choosers, the last selected directory will be displayed.

Parameters:
newDefaultPath - the new default path to be selected initially

startWorkers

public void startWorkers()
Starts the SwingWorker threads to create JFileChooser instances in the background.


setFileSupportSettings

public void setFileSupportSettings(FileSupportSettings settings)
Sets the selected files and directories to the settings argument. Nothing happens if the argument is null or does not have at least 6 rows.

Parameters:
settings - holds the file parameters

getFileSupportSettings

public FileSupportSettings getFileSupportSettings()
Gets the settings instance according to the previously made file selections.

Returns:
settings instance

getSelectedImportHandlerType

public DataHandlerTypes getSelectedImportHandlerType()
Gets the handler type chosen for data import.

Returns:
handler type

getSelectedSaveHandlerType

public DataHandlerTypes getSelectedSaveHandlerType()
Gets the handler type chosen for data export.

Returns:
handler type