util
Class StringFiler

java.lang.Object
  extended by util.StringFiler

public class StringFiler
extends java.lang.Object

Encapsulates saving and loading strings from a file. Saving is done in its own Thread. Loading a string is in the current Thread, since returning a value is more complex across Threads (but see loadFromThread()). StringFiler itself should be used from the event thread.


Constructor Summary
StringFiler(java.lang.String text)
          create a new instance of StringFiler with no filename
StringFiler(java.lang.String text, java.lang.String name)
          create a new instance of StringFiler
 
Method Summary
 java.lang.String getFilename()
           
 java.lang.String getShortName()
           
 java.lang.String getText()
           
 java.lang.String load()
          loads a string from a file.
static java.lang.String load(java.io.File file)
          static method to load a string from a file without creating an object.
 java.lang.Thread loadFromThread()
          loads a string from a file in its own thread.
 void save()
          save the current text in the current file.
 void save(java.lang.String text)
          changes the current text and saves it in the current file.
static void save(java.lang.String text, java.io.File file)
          static method to just save without creating an object
 void saveAs()
          save the current text in a file to be selected, and changes the file name with a save as dialog.
 void saveAs(java.lang.String text)
          changes the current text and saves it in a file to be selected, and changes the file name with a save as dialog.
 void setFilename(java.lang.String name)
           
 void setText(java.lang.String text)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringFiler

public StringFiler(java.lang.String text)
create a new instance of StringFiler with no filename

Parameters:
text - the text to save

StringFiler

public StringFiler(java.lang.String text,
                   java.lang.String name)
create a new instance of StringFiler

Parameters:
text - the text to save (use null to use this to load a string, or (better) use the static method {link #loadString(String)})
name - the name of the file
Method Detail

getFilename

public java.lang.String getFilename()
Returns:
the name of the file (full path name). returns null if the file is not set

getShortName

public java.lang.String getShortName()
Returns:
the name of the file (without the whole path). returns null if the file is not set

setFilename

public void setFilename(java.lang.String name)
Parameters:
name - the name of the file

getText

public java.lang.String getText()
Returns:
the current text

setText

public void setText(java.lang.String text)
Parameters:
text - the new text

save

public void save()
save the current text in the current file. If the file is not set, put up a save as dialog


save

public void save(java.lang.String text)
changes the current text and saves it in the current file. If the file is not set, put up a save as dialog

Parameters:
text - the new text to save

saveAs

public void saveAs()
save the current text in a file to be selected, and changes the file name with a save as dialog. if the user cancels from the dialog, does nothing


saveAs

public void saveAs(java.lang.String text)
changes the current text and saves it in a file to be selected, and changes the file name with a save as dialog. if the user cancels from the dialog, just changes the text but doesn't save anything


save

public static void save(java.lang.String text,
                        java.io.File file)
static method to just save without creating an object

Parameters:
text - the text to save
file - the File to save into (use null to put up a save as dialog) saves in its own thread. If the user cancels from the save as dialog, does nothing

load

public java.lang.String load()
loads a string from a file. If getFilename() == null, puts up an open file dialog if the user does not cancel, getFilename() will return the name if the load is successful, getText() will return the string loaded

Returns:
the string loaded; if the user cancelled or an error happened, return null

loadFromThread

public java.lang.Thread loadFromThread()
loads a string from a file in its own thread. If getFilename() == null, puts up an open file dialog if the user does not cancel, getFilename() will return the name if the load is successful, getText() will return the string loaded. if the load is not successful, getText() will return null.

Returns:
the Thread that was started, for you to join() or whatever. If the user cancelled, returns null.

load

public static java.lang.String load(java.io.File file)
static method to load a string from a file without creating an object.

Parameters:
file - the File to load from (use null to put up an open file dialog). If the user cancels or an error happens, returns null. An empty file returns an empty string