com.jstatcom.io
Class FileSupport
- java.lang.Object
-
- com.jstatcom.io.FileSupport
-
public final class FileSupport extends java.lang.ObjectSupport for convenient file selection. This class is a Singleton and can be accessed by thegetInstancemethod.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.io.FilechooseDirectory(java.awt.Component parent, java.lang.String titleText)Lets the user choose a directory with the JFileChooser.FileSupportSettingsgetFileSupportSettings()Gets the settings instance according to the previously made file selections.static FileSupportgetInstance()Gets the Singleton instance of this class.DataHandlerTypesgetSelectedImportHandlerType()Gets the handler type chosen for data import.DataHandlerTypesgetSelectedSaveHandlerType()Gets the handler type chosen for data export.java.lang.StringreadTextFile(java.lang.String fileName)Reads the contents of a text file and returns it as a string.java.io.FilesaveDataFile(java.awt.Component parent, java.lang.String filenameShort, DataHandlerTypes... types)Selects a data file for saving with a file chooser.java.io.FilesaveProjectFile(java.awt.Component parent)Selects a project file for saving with a file chooser.voidsaveStringToFile(java.io.File file, java.lang.String stringDat, boolean append)StoresstringDattofile.java.io.FilesaveTextFile(java.awt.Component parent)Selects a text file for saving with a file chooser.java.io.FileselectDataFile(java.awt.Component parent, DataHandlerTypes... types)Selects a data file to open with a file chooser.java.io.FileselectProjectFile(java.awt.Component parent)Selects a project file to open with a file chooser.voidsetDefaultPath(java.lang.String newDefaultPath)Sets the directory that will be displayed as default selection when a file chooser is created.voidsetFileSupportSettings(FileSupportSettings settings)Sets the selected files and directories to the settings argument.voidstartWorkers()Starts theSwingWorkerthreads to createJFileChooserinstances in the background.
-
-
-
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 DialogtitleText- 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 dialogsfilenameShort- the selected filename without path, can benulltypes- the data handler types, the last element will be set as default- Returns:
- file if ok,
nullotherwise
-
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,
nullotherwise
-
saveStringToFile
public void saveStringToFile(java.io.File file, java.lang.String stringDat, boolean append)StoresstringDattofile.- Parameters:
file- the file to storestringDattostringDat- the string to saveappend-trueif 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,
nullotherwise
-
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 dialogstypes- the data handler types, the last element will be set as default- Returns:
- file if ok,
nullotherwise
-
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,
nullotherwise
-
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 theSwingWorkerthreads to createJFileChooserinstances in the background.
-
setFileSupportSettings
public void setFileSupportSettings(FileSupportSettings settings)
Sets the selected files and directories to the settings argument. Nothing happens if the argument isnullor 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
-
-
DMelt 3.0 © DataMelt by jWork.ORG