|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object util.StringFiler
public class StringFiler
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 |
---|
public StringFiler(java.lang.String text)
text
- the text to savepublic StringFiler(java.lang.String text, java.lang.String name)
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 fileMethod Detail |
---|
public java.lang.String getFilename()
public java.lang.String getShortName()
public void setFilename(java.lang.String name)
name
- the name of the filepublic java.lang.String getText()
public void setText(java.lang.String text)
text
- the new textpublic void save()
public void save(java.lang.String text)
text
- the new text to savepublic void saveAs()
public void saveAs(java.lang.String text)
public static void save(java.lang.String text, java.io.File file)
text
- the text to savefile
- 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 nothingpublic java.lang.String load()
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
public java.lang.Thread loadFromThread()
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.
public static java.lang.String load(java.io.File file)
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |