public class DialogSettings extends Object implements IDialogSettings
IDialogSettings
)
using a hash table and XML. The dialog store can be read
from and saved to a stream. All keys and values must be strings or array of
strings. Primitive types are converted to strings.
This class was not designed to be subclassed. Here is an example of using a DialogSettings:
DialogSettings settings = new DialogSettings("root");
settings.put("Boolean1",true);
settings.put("Long1",100);
settings.put("Array1",new String[]{"aaaa1","bbbb1","cccc1"});
DialogSettings section = new DialogSettings("sectionName");
settings.addSection(section);
section.put("Int2",200);
section.put("Float2",1.1);
section.put("Array2",new String[]{"aaaa2","bbbb2","cccc2"});
settings.save("c:\\temp\\test\\dialog.xml");
Constructor and Description |
---|
DialogSettings(String sectionName)
Create an empty dialog settings which loads and saves its
content to a file.
|
Modifier and Type | Method and Description |
---|---|
IDialogSettings |
addNewSection(String sectionName)
Create a new section in the receiver and return it.
|
void |
addSection(IDialogSettings section)
Add a section in the receiver.
|
String |
get(String key)
Returns the value of the given key in this dialog settings.
|
String[] |
getArray(String key)
Returns the value, an array of strings, of the given key in this dialog
settings.
|
boolean |
getBoolean(String key)
Convenience API.
|
double |
getDouble(String key)
Convenience API.
|
float |
getFloat(String key)
Convenience API.
|
int |
getInt(String key)
Convenience API.
|
long |
getLong(String key)
Convenience API.
|
String |
getName()
Returns the IDialogSettings name.
|
static IDialogSettings |
getOrCreateSection(IDialogSettings settings,
String sectionName)
Returns a section with the given name in the given dialog settings.
|
IDialogSettings |
getSection(String sectionName)
Returns the section with the given name in this dialog settings.
|
IDialogSettings[] |
getSections()
Returns all the sections in this dialog settings.
|
void |
load(Reader r)
Load a dialog settings from a stream and fill the receiver with its
content.
|
void |
load(String fileName)
Load a dialog settings from a file and fill the receiver with its
content.
|
void |
put(String key,
boolean value)
Convenience API.
|
void |
put(String key,
double value)
Convenience API.
|
void |
put(String key,
float value)
Convenience API.
|
void |
put(String key,
int value)
Convenience API.
|
void |
put(String key,
long value)
Convenience API.
|
void |
put(String key,
String value)
Adds the pair
key/value to this dialog settings. |
void |
put(String key,
String[] value)
Adds the pair
key/value to this dialog settings. |
void |
removeSection(IDialogSettings section)
Remove a section in the receiver.
|
IDialogSettings |
removeSection(String sectionName)
Remove a section by name in the receiver.
|
void |
save(String fileName)
Save a dialog settings to a file.
|
void |
save(Writer writer)
Save a dialog settings to a stream
|
public DialogSettings(String sectionName)
load(String)
and store(String)
to load and store this dialog settings.sectionName
- the name of the section in the settings.public IDialogSettings addNewSection(String sectionName)
IDialogSettings
addNewSection
in interface IDialogSettings
sectionName
- the name of the new sectiongetOrCreateSection(IDialogSettings, String)
public void addSection(IDialogSettings section)
IDialogSettings
addSection
in interface IDialogSettings
section
- the section to be addedpublic void removeSection(IDialogSettings section)
section
- the section to be removed. Must not be null
.public IDialogSettings removeSection(String sectionName)
sectionName
- the name of the section to be removed. Must not be null
.null
if it wasn't there.public String get(String key)
IDialogSettings
get
in interface IDialogSettings
key
- the keynull
if nonepublic String[] getArray(String key)
IDialogSettings
getArray
in interface IDialogSettings
key
- the keynull
if nonepublic boolean getBoolean(String key)
IDialogSettings
getBoolean
in interface IDialogSettings
key
- the keyfalse
if nonepublic double getDouble(String key) throws NumberFormatException
IDialogSettings
getDouble
in interface IDialogSettings
key
- the keyNumberFormatException
if noneNumberFormatException
- if the string value does not contain a parsable number.Double.valueOf(java.lang.String)
public float getFloat(String key) throws NumberFormatException
IDialogSettings
getFloat
in interface IDialogSettings
key
- the keyNumberFormatException
if noneNumberFormatException
- if the string value does not contain a parsable number.Float.valueOf(java.lang.String)
public int getInt(String key) throws NumberFormatException
IDialogSettings
getInt
in interface IDialogSettings
key
- the keyNumberFormatException
if noneNumberFormatException
- if the string value does not contain a parsable number.Integer.valueOf(java.lang.String)
public long getLong(String key) throws NumberFormatException
IDialogSettings
getLong
in interface IDialogSettings
key
- the keyNumberFormatException
if noneNumberFormatException
- if the string value does not contain a parsable number.Long.valueOf(java.lang.String)
public String getName()
IDialogSettings
getName
in interface IDialogSettings
public static IDialogSettings getOrCreateSection(IDialogSettings settings, String sectionName)
settings
- the parent settingssectionName
- the name of the sectionpublic IDialogSettings getSection(String sectionName)
IDialogSettings
getSection
in interface IDialogSettings
sectionName
- the keynull
if nonegetOrCreateSection(IDialogSettings, String)
public IDialogSettings[] getSections()
IDialogSettings
getSections
in interface IDialogSettings
null
if nonepublic void load(Reader r)
IDialogSettings
load
in interface IDialogSettings
r
- a Reader specifying the stream where the settings are read
from.public void load(String fileName) throws IOException
IDialogSettings
load
in interface IDialogSettings
fileName
- the name of the file the settings are read from.IOException
public void put(String key, String[] value)
IDialogSettings
key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, double value)
IDialogSettings
value
to a string and
adds the pair key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, float value)
IDialogSettings
value
to a string and
adds the pair key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, int value)
IDialogSettings
value
to a string and
adds the pair key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, long value)
IDialogSettings
value
to a string and
adds the pair key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, String value)
IDialogSettings
key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void put(String key, boolean value)
IDialogSettings
value
to a string
and adds the pair key/value
to this dialog settings.put
in interface IDialogSettings
key
- the key.value
- the value to be associated with the key
public void save(Writer writer) throws IOException
IDialogSettings
save
in interface IDialogSettings
writer
- a Writer specifying the stream the settings are written in.IOException
public void save(String fileName) throws IOException
IDialogSettings
save
in interface IDialogSettings
fileName
- the name of the file the settings are written in.IOException
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.