|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.fife.ui.app.Prefs
public abstract class Prefs
A simple wrapper for preferences for some object. This class can be used as a simpler replacement for the Java Preferences API for the following reasons:
putXXX()
methods for each individual
preference when saving preferences and getXXX()
methods
while loading them; all public fields are loaded and stored
appropriately automatically.java.util.Properties
directly,
using this class keeps you from having to convert each type of
preference to and from String. java.awt.Color
, for
example, is handled automatically.
Common usage should be as follows: say a class Foo
needs to
store preferences between runs of the application. A class could be created
for its preferences, say FooPrefs
, that extends
Prefs
. The Foo
instance could then loads its
preferences like so:
public void loadPreferences() throws IOException { FooPrefs prefs = new FooPrefs(); // Initializes to defaults prefs.load(new File((String)System.getProperty("user.home"), ".foo.prefs")); this.count = prefs.count; this.id = prefs.id; this.background = prefs.bgColor; }and save its preferences similarly:
public void savePreferences() throws IOException { FooPrefs prefs = new FooPrefs(); prefs.count = this.count; prefs.id = this.id; prefs.bgColor = this.background; prefs.save(new File((String)System.getProperty("user.home"), ".foo.prefs")); }Alternatively (and perhaps more simply), the
Foo
instance could
instantiate and keep the FooPrefs
as a private member. Its
getters and setters that modify its preferences could manipulate the
FooPrefs
's values directly. Then at shutdown time, the
Foo
instance would simply have to call
prefs.save(File)
to save any changes.
Modification of the generated properties files by hand is discouraged unless
you are familiar with the details of that specific concrete
Prefs
implementation.
This class currently handles fields of type:
Constructor Summary | |
---|---|
Prefs()
Constructor. |
Method Summary | |
---|---|
void |
load(java.io.File file)
Loads this preferences class from a file. |
void |
load(java.io.InputStream in)
Loads this preferences class from an input stream. |
void |
load(java.util.Properties props)
Loads this preferences class from a properties object. |
void |
save(java.io.File file)
Saves these preferences to a file. |
void |
save(java.io.OutputStream out)
Saves these preferences to an output stream. |
void |
save(java.util.Properties props)
Saves these preferences to a properties object. |
abstract void |
setDefaults()
Sets all fields in this class to their default values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Prefs()
setDefaults()
.
Method Detail |
---|
public void load(java.io.File file) throws java.io.IOException
file
- The file.
java.io.IOException
- If an IO error occurs.load(InputStream)
,
load(Properties)
public void load(java.io.InputStream in) throws java.io.IOException
in
- The input stream. It is the caller's responsibility to close
this stream.
java.io.IOException
- If an IO error occurs.load(File)
,
load(Properties)
public void load(java.util.Properties props) throws java.io.IOException
Properties
.
props
- The properties to load from.
java.io.IOException
- If an IO error occurs.load(File)
,
load(InputStream)
public void save(java.io.File file) throws java.io.IOException
file
- The file to save to.
java.io.IOException
- If an IO error occurs.save(Properties)
,
save(OutputStream)
public void save(java.util.Properties props) throws java.io.IOException
Prefs
into a single
Properties
.
props
- The properties to save to.
java.io.IOException
- If an IO error occurs.save(File)
,
save(OutputStream)
public void save(java.io.OutputStream out) throws java.io.IOException
out
- The stream to write to.
java.io.IOException
- If an IO error occurs.save(File)
,
save(Properties)
public abstract void setDefaults()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |