From a737fba3e3ff7272fa58b3c85b11b7b21a93bf97 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 18 May 2020 17:00:40 +0200 Subject: [PATCH] Added String preferences --- .../preferences/DefaultRenderPreferences.java | 10 +++++++++ .../preferences/DefaultPluginPreferences.java | 10 +++++++++ .../preferences/EclipsePreferences.java | 21 +++++++++++++++++++ .../preferences/DefaultPreferences.java | 18 +++++++++------- .../net/mograsim/preferences/Preferences.java | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java index 0a9e4323..43d58c7f 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java @@ -60,6 +60,16 @@ public class DefaultRenderPreferences extends DefaultPreferences implements Rend } } + @Override + public String getString(String name) + { + switch (name) + { + default: + throw new IllegalArgumentException("Unknown string preference name: " + name); + } + } + @Override public ColorDefinition getColorDefinition(String name) { diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/DefaultPluginPreferences.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/DefaultPluginPreferences.java index e3dcc72b..ae6d8281 100755 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/DefaultPluginPreferences.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/DefaultPluginPreferences.java @@ -41,6 +41,16 @@ public class DefaultPluginPreferences extends DefaultPreferences implements Plug } } + @Override + public String getString(String name) + { + switch (name) + { + default: + throw new IllegalArgumentException("Unknown double preference name: " + name); + } + } + @Override public ColorDefinition getColorDefinition(String name) { diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/EclipsePreferences.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/EclipsePreferences.java index c57c443e..e238f8b0 100755 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/EclipsePreferences.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/EclipsePreferences.java @@ -30,6 +30,7 @@ public class EclipsePreferences implements Preferences private final ListenerManager booleanListeners; private final ListenerManager intListeners; private final ListenerManager doubleListeners; + private final ListenerManager stringListeners; private final ListenerManager colorDefinitionListeners; protected EclipsePreferences(ITheme theme, IPreferenceStore prefs, Preferences defaultPrefs) @@ -41,6 +42,7 @@ public class EclipsePreferences implements Preferences this.booleanListeners = new ListenerManager<>(this::getBoolean); this.intListeners = new ListenerManager<>(this::getInt); this.doubleListeners = new ListenerManager<>(this::getDouble); + this.stringListeners = new ListenerManager<>(this::getString); this.colorDefinitionListeners = new ListenerManager<>(this::getColorDefinition); } @@ -65,6 +67,13 @@ public class EclipsePreferences implements Preferences return prefs.getDouble(name); } + @Override + public String getString(String name) + { + prefs.setDefault(name, defaultPrefs.getString(name)); + return prefs.getString(name); + } + @Override public ColorDefinition getColorDefinition(String name) { @@ -124,6 +133,18 @@ public class EclipsePreferences implements Preferences doubleListeners.removeListener(name, listener); } + @Override + public void addStringListener(String name, Consumer listener) + { + stringListeners.addListener(name, listener); + } + + @Override + public void removeStringListener(String name, Consumer listener) + { + stringListeners.removeListener(name, listener); + } + @Override public void addColorDefinitionListener(String name, Consumer listener) { diff --git a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java index d51acab3..fcb06f91 100644 --- a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java +++ b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java @@ -7,13 +7,15 @@ public abstract class DefaultPreferences implements Preferences // Adding / removing listeners. All are no-ops, since DefaultPreferences are immutable. //@formatter:off - @Override public void addBooleanListener(String name, Consumer listener) {/**/} - @Override public void removeBooleanListener(String name, Consumer listener) {/**/} - @Override public void addIntListener(String name, Consumer listener) {/**/} - @Override public void removeIntListener(String name, Consumer listener) {/**/} - @Override public void addDoubleListener(String name, Consumer listener) {/**/} - @Override public void removeDoubleListener(String name, Consumer listener) {/**/} - @Override public void addColorDefinitionListener(String name, Consumer listener) {/**/} - @Override public void removeColorDefinitionListener(String name, Consumer listener) {/**/} + @Override public final void addBooleanListener(String name, Consumer listener) {/**/} + @Override public final void removeBooleanListener(String name, Consumer listener) {/**/} + @Override public final void addIntListener(String name, Consumer listener) {/**/} + @Override public final void removeIntListener(String name, Consumer listener) {/**/} + @Override public final void addDoubleListener(String name, Consumer listener) {/**/} + @Override public final void removeDoubleListener(String name, Consumer listener) {/**/} + @Override public final void addStringListener(String name, Consumer listener) {/**/} + @Override public final void removeStringListener(String name, Consumer listener) {/**/} + @Override public final void addColorDefinitionListener(String name, Consumer listener) {/**/} + @Override public final void removeColorDefinitionListener(String name, Consumer listener) {/**/} //@formatter:on } \ No newline at end of file diff --git a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java index f19ae65c..62b3b471 100644 --- a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java +++ b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java @@ -24,6 +24,12 @@ public interface Preferences public void removeDoubleListener(String name, Consumer listener); + public String getString(String name); + + public void addStringListener(String name, Consumer listener); + + public void removeStringListener(String name, Consumer listener); + public ColorDefinition getColorDefinition(String name); public void addColorDefinitionListener(String name, Consumer listener); -- 2.17.1