refactoring of settings class

This commit is contained in:
hneemann 2017-06-06 20:12:14 +02:00
parent 5783cf6a82
commit 17dacd9dba

View File

@ -20,24 +20,6 @@ import java.util.List;
*/ */
public final class Settings implements AttributeListener { public final class Settings implements AttributeListener {
private static final List<Key> INT_LIST = new ArrayList<>();
/**
* The list of supported attributes.
*/
public static final List<Key> SETTINGS_KEYS = Collections.unmodifiableList(INT_LIST);
static {
INT_LIST.add(Keys.SETTINGS_IEEE_SHAPES);
INT_LIST.add(Keys.SETTINGS_LANGUAGE);
INT_LIST.add(Keys.SETTINGS_EXPRESSION_FORMAT);
INT_LIST.add(Keys.SETTINGS_DEFAULT_TREESELECT);
INT_LIST.add(Keys.SETTINGS_ATF1502_FITTER);
if (isLinux())
INT_LIST.add(Keys.SETTINGS_SCREEN_RESOLUTION);
}
private static final class SettingsHolder { private static final class SettingsHolder {
static final Settings INSTANCE = new Settings(); static final Settings INSTANCE = new Settings();
} }
@ -51,23 +33,37 @@ public final class Settings implements AttributeListener {
return SettingsHolder.INSTANCE; return SettingsHolder.INSTANCE;
} }
private ElementAttributes attributes; private final ElementAttributes attributes;
private final File filename; private final File filename;
private final List<Key> settingsKeys;
private Settings() { private Settings() {
List<Key> intList = new ArrayList<>();
intList.add(Keys.SETTINGS_IEEE_SHAPES);
intList.add(Keys.SETTINGS_LANGUAGE);
intList.add(Keys.SETTINGS_EXPRESSION_FORMAT);
intList.add(Keys.SETTINGS_DEFAULT_TREESELECT);
intList.add(Keys.SETTINGS_ATF1502_FITTER);
if (isLinux())
intList.add(Keys.SETTINGS_SCREEN_RESOLUTION);
settingsKeys = Collections.unmodifiableList(intList);
filename = new File(new File(System.getProperty("user.home")), ".digital.cfg"); filename = new File(new File(System.getProperty("user.home")), ".digital.cfg");
ElementAttributes attr = null;
XStream xStream = Circuit.getxStream(); XStream xStream = Circuit.getxStream();
try (InputStream in = new FileInputStream(filename)) { try (InputStream in = new FileInputStream(filename)) {
attributes = (ElementAttributes) xStream.fromXML(in); attr = (ElementAttributes) xStream.fromXML(in);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (attributes == null) { if (attr == null) {
System.out.println("Use default settings!"); System.out.println("Use default settings!");
attributes = new ElementAttributes(); attributes = new ElementAttributes();
} } else
attributes = attr;
attributes.addListener(this); attributes.addListener(this);
} }
@ -102,6 +98,13 @@ public final class Settings implements AttributeListener {
} }
} }
/**
* @return the settings keys
*/
public List<Key> getKeys() {
return settingsKeys;
}
/** /**
* @return true if running on a windows system * @return true if running on a windows system
*/ */