Added String preferences
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 18 May 2020 15:00:40 +0000 (17:00 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 18 May 2020 15:00:40 +0000 (17:00 +0200)
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/preferences/DefaultRenderPreferences.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/DefaultPluginPreferences.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/preferences/EclipsePreferences.java
plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java
plugins/net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java

index 0a9e432..43d58c7 100644 (file)
@@ -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)
        {
index e3dcc72..ae6d828 100755 (executable)
@@ -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)
        {
index c57c443..e238f8b 100755 (executable)
@@ -30,6 +30,7 @@ public class EclipsePreferences implements Preferences
        private final ListenerManager<Boolean> booleanListeners;
        private final ListenerManager<Integer> intListeners;
        private final ListenerManager<Double> doubleListeners;
+       private final ListenerManager<String> stringListeners;
        private final ListenerManager<ColorDefinition> 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<String> listener)
+       {
+               stringListeners.addListener(name, listener);
+       }
+
+       @Override
+       public void removeStringListener(String name, Consumer<String> listener)
+       {
+               stringListeners.removeListener(name, listener);
+       }
+
        @Override
        public void addColorDefinitionListener(String name, Consumer<ColorDefinition> listener)
        {
index d51acab..fcb06f9 100644 (file)
@@ -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<Boolean> listener) {/**/}
-       @Override public void removeBooleanListener(String name, Consumer<Boolean> listener) {/**/}
-       @Override public void addIntListener(String name, Consumer<Integer> listener) {/**/}
-       @Override public void removeIntListener(String name, Consumer<Integer> listener) {/**/}
-       @Override public void addDoubleListener(String name, Consumer<Double> listener) {/**/}
-       @Override public void removeDoubleListener(String name, Consumer<Double> listener) {/**/}
-       @Override public void addColorDefinitionListener(String name, Consumer<ColorDefinition> listener) {/**/}
-       @Override public void removeColorDefinitionListener(String name, Consumer<ColorDefinition> listener) {/**/}
+       @Override public final void addBooleanListener(String name, Consumer<Boolean> listener) {/**/}
+       @Override public final void removeBooleanListener(String name, Consumer<Boolean> listener) {/**/}
+       @Override public final void addIntListener(String name, Consumer<Integer> listener) {/**/}
+       @Override public final void removeIntListener(String name, Consumer<Integer> listener) {/**/}
+       @Override public final void addDoubleListener(String name, Consumer<Double> listener) {/**/}
+       @Override public final void removeDoubleListener(String name, Consumer<Double> listener) {/**/}
+       @Override public final void addStringListener(String name, Consumer<String> listener) {/**/}
+       @Override public final void removeStringListener(String name, Consumer<String> listener) {/**/}
+       @Override public final void addColorDefinitionListener(String name, Consumer<ColorDefinition> listener) {/**/}
+       @Override public final void removeColorDefinitionListener(String name, Consumer<ColorDefinition> listener) {/**/}
        //@formatter:on
 }
\ No newline at end of file
index f19ae65..62b3b47 100644 (file)
@@ -24,6 +24,12 @@ public interface Preferences
 
        public void removeDoubleListener(String name, Consumer<Double> listener);
 
+       public String getString(String name);
+
+       public void addStringListener(String name, Consumer<String> listener);
+
+       public void removeStringListener(String name, Consumer<String> listener);
+
        public ColorDefinition getColorDefinition(String name);
 
        public void addColorDefinitionListener(String name, Consumer<ColorDefinition> listener);