edu.neu.ccs.gui
Class StringableFileIO

java.lang.Object
  extended byedu.neu.ccs.gui.StringableFileIO

public class StringableFileIO
extends Object

Class StringableFileIO contains methods to load or save the state of a Stringable model object using text file IO.

The basic methods use file dialogs. The most complex methods assume a File object has been defined and associated with a text file and then work with that object.

An instance retains information about the Stringable model object as well as the file extension, the file filter, and the most recent directory visited by its file chooser internal object.

Utilizes the class TextFileIO in its implementation.

Version:
2.5.0

Field Summary
protected  Stringable model
          The stringable model to read or save via this class.
protected  TextFileIO textFileIO
          The text file IO tool.
 
Constructor Summary
StringableFileIO(Stringable model, String extension)
          The constructor that provides the Stringable model to read or save via this class and the file extension for its files.
 
Method Summary
 Stringable getModel()
          Returns the Stringable model object.
 boolean readDataFromFile()
          Opens a file dialog to get the file name of a text file with model data and then reads the data into the model.
 boolean readDataFromFile(boolean displayErrorDialogs)
          Opens a file dialog to get the file name of a text file with model data and then reads the data into the model.
 boolean readDataFromFile(File source, boolean displayErrorDialogs)
          Reads the model data from the given text file.
 boolean saveDataToFile()
          Opens a file dialog to get the file name of a model file and then saves the model data to the file.
 boolean saveDataToFile(boolean displayErrorDialogs)
          Opens a file dialog to get the file name of a model file and then saves the model data to the file.
 boolean saveDataToFile(File target, boolean displayErrorDialogs)
          Saves the model data to the given model file.
protected  boolean setModel(String data, boolean displayErrorDialogs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected Stringable model
The stringable model to read or save via this class.


textFileIO

protected TextFileIO textFileIO
The text file IO tool.

Constructor Detail

StringableFileIO

public StringableFileIO(Stringable model,
                        String extension)

The constructor that provides the Stringable model to read or save via this class and the file extension for its files.

Throws NullPointerException if the model is null.

Uses no file extension if the given extension is null.

Parameters:
model - the Stringable model requiring file IO
extension - the file extension to use for model files
Throws:
NullPointerException
Method Detail

getModel

public Stringable getModel()
Returns the Stringable model object.


readDataFromFile

public boolean readDataFromFile()

Opens a file dialog to get the file name of a text file with model data and then reads the data into the model.

Displays error dialogs.

Does nothing to the current data in the model if errors occur.

Returns:
true if the operation succeeds

readDataFromFile

public boolean readDataFromFile(boolean displayErrorDialogs)

Opens a file dialog to get the file name of a text file with model data and then reads the data into the model.

Displays error dialogs if the parameter is set to true.

Does nothing to the current data in the model if errors occur.

Returns:
true if the operation succeeds

readDataFromFile

public boolean readDataFromFile(File source,
                                boolean displayErrorDialogs)

Reads the model data from the given text file.

Does nothing to the current data if errors occur.

Parameters:
source - the data source
displayErrorDialogs - if true display error dialogs
Returns:
true if the operation succeeds

setModel

protected boolean setModel(String data,
                           boolean displayErrorDialogs)

saveDataToFile

public boolean saveDataToFile()

Opens a file dialog to get the file name of a model file and then saves the model data to the file.

Displays error dialogs.

Does no save if any errors occur.

Returns:
true if the operation succeeds

saveDataToFile

public boolean saveDataToFile(boolean displayErrorDialogs)

Opens a file dialog to get the file name of a model file and then saves the model data to the file.

Displays error dialogs if the parameter is set to true.

Does no save if any errors occur.

Returns:
true if the operation succeeds

saveDataToFile

public boolean saveDataToFile(File target,
                              boolean displayErrorDialogs)

Saves the model data to the given model file.

Displays error dialogs if the last parameter is set to true.

Does no save if any errors occur.

Parameters:
target - the data target
displayErrorDialogs - if true display error dialogs
Returns:
true if the operation succeeds