CodeSnippetSupplier now supports high level state handlers
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 8 Jul 2019 08:48:30 +0000 (10:48 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 8 Jul 2019 08:48:30 +0000 (10:48 +0200)
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/HighLevelStateHandler.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/highlevelstatehandlers/DefaultHighLevelStateHandler.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json

index 83e6d61..952d753 100644 (file)
@@ -14,6 +14,7 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.logic.ui.serializing.snippets.HighLevelStateHandler;
 
 /**
  * The base class for all GUI components.<br>
@@ -142,13 +143,10 @@ public abstract class GUIComponent
 
        /**
         * Sets the given high-level state to the given value. <br>
-        * A high level state ID consists of parts separated by dots ('.').<br>
-        * The last part (the part after the last dot) is called "atomic high level state ID". The parts before that part are called
-        * "subcomponent ID"s.<br>
-        * If there is no dot in a high level state ID, the whole high level state ID is called atomic.<br>
-        * Note that subcomponent IDs don't have to correspond to actual subcomponents. For example, a RAM component may supply subcomponent IDs
-        * "c0000", "c0001" ... "cFFFF" without actually having a subcomponent for each cell. It also is allowed for an atomic high level state
-        * ID to be delegated to a subcomponent.
+        * See {@link HighLevelStateHandler#setHighLevelState(String, Object)} for an explanation of high-level state IDs.
+        * 
+        * @see #getHighLevelState(String)
+        * @see HighLevelStateHandler#setHighLevelState(String, Object)
         * 
         * @author Daniel Kirschten
         */
@@ -160,7 +158,10 @@ public abstract class GUIComponent
 
        /**
         * Gets the current value of the given high-level state. <br>
-        * See {@link #setHighLevelState(String, Object)} for an explanation of high-level state IDs.
+        * See {@link HighLevelStateHandler#setHighLevelState(String, Object)} for an explanation of high-level state IDs.
+        * 
+        * @see #setHighLevelState(String, Object)
+        * @see HighLevelStateHandler#getHighLevelState(String)
         * 
         * @author Daniel Kirschten
         */
index 0c27461..a6b9dae 100644 (file)
@@ -5,8 +5,10 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import net.mograsim.logic.ui.serializing.snippets.HighLevelStateHandler;
 import net.mograsim.logic.ui.serializing.snippets.Renderer;
 import net.mograsim.logic.ui.serializing.snippets.SnippetSupplier;
+import net.mograsim.logic.ui.serializing.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
 import net.mograsim.logic.ui.serializing.snippets.outlinerenderers.DefaultOutlineRenderer;
 import net.mograsim.logic.ui.serializing.snippets.symbolrenderers.DefaultSymbolRenderer;
 import net.mograsim.logic.ui.util.JsonHandler;
@@ -16,11 +18,13 @@ public class CodeSnippetSupplier<S>
        // public static members
        public static final CodeSnippetSupplier<Renderer> symbolRendererSupplier;
        public static final CodeSnippetSupplier<Renderer> outlineRendererSupplier;
+       public static final CodeSnippetSupplier<HighLevelStateHandler> highLevelStateHandlerSupplier;
 
        static
        {
                symbolRendererSupplier = new CodeSnippetSupplier<>(SnippetSupplier.create(Void.class, DefaultSymbolRenderer::new));
                outlineRendererSupplier = new CodeSnippetSupplier<>(SnippetSupplier.create(Void.class, DefaultOutlineRenderer::new));
+               highLevelStateHandlerSupplier = new CodeSnippetSupplier<>(SnippetSupplier.create(Void.class, DefaultHighLevelStateHandler::new));
        }
 
        // per-instance members
@@ -77,6 +81,7 @@ public class CodeSnippetSupplier<S>
                        SnippetIDClassNames tmp = JsonHandler.readJson(s, SnippetIDClassNames.class);
                        tmp.standardOutlineRendererSuppliers.forEach(outlineRendererSupplier::addStandardSnippetID);
                        tmp.standardSymbolRendererSuppliers.forEach(symbolRendererSupplier::addStandardSnippetID);
+                       tmp.standardHighLevelStateHandlerSuppliers.forEach(highLevelStateHandlerSupplier::addStandardSnippetID);
                }
                catch (Exception e)
                {
@@ -89,6 +94,7 @@ public class CodeSnippetSupplier<S>
        {
                public Map<String, String> standardOutlineRendererSuppliers;
                public Map<String, String> standardSymbolRendererSuppliers;
+               public Map<String, String> standardHighLevelStateHandlerSuppliers;
        }
 
        private static void tryLoadSnippetClass(String snippetClassName)
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/HighLevelStateHandler.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/HighLevelStateHandler.java
new file mode 100644 (file)
index 0000000..596582a
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.ui.serializing.snippets;
+
+import net.mograsim.logic.ui.model.components.GUIComponent;
+
+public interface HighLevelStateHandler
+{
+       /**
+        * Sets the given high-level state to the given value. <br>
+        * A high level state ID consists of parts separated by dots ('.').<br>
+        * The last part (the part after the last dot) is called "atomic high level state ID". The parts before that part are called
+        * "subcomponent ID"s.<br>
+        * If there is no dot in a high level state ID, the whole high level state ID is called atomic.<br>
+        * Note that subcomponent IDs don't have to correspond to actual subcomponents. For example, a RAM component may supply subcomponent IDs
+        * "c0000", "c0001" ... "cFFFF" without actually having a subcomponent for each cell. It also is allowed to delegate an atomic high
+        * level state ID to a subcomponent.
+        * 
+        * @see #getHighLevelState(String)
+        * @see GUIComponent#setHighLevelState(String, Object)
+        * 
+        * @author Daniel Kirschten
+        */
+       public void setHighLevelState(String stateID, Object newState);
+
+       /**
+        * Gets the current value of the given high-level state. <br>
+        * See {@link #setHighLevelState(String, Object)} for an explanation of high-level state IDs.
+        * 
+        * @see #setHighLevelState(String, Object)
+        * @see GUIComponent#getHighLevelState(String)
+        * 
+        * @author Daniel Kirschten
+        */
+       public Object getHighLevelState(String stateID);
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/highlevelstatehandlers/DefaultHighLevelStateHandler.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/highlevelstatehandlers/DefaultHighLevelStateHandler.java
new file mode 100644 (file)
index 0000000..7a68708
--- /dev/null
@@ -0,0 +1,33 @@
+package net.mograsim.logic.ui.serializing.snippets.highlevelstatehandlers;
+
+import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent;
+import net.mograsim.logic.ui.serializing.CodeSnippetSupplier;
+import net.mograsim.logic.ui.serializing.snippets.HighLevelStateHandler;
+import net.mograsim.logic.ui.serializing.snippets.SnippetSupplier;
+
+public class DefaultHighLevelStateHandler implements HighLevelStateHandler
+{
+       @SuppressWarnings("unused") // we don't need the component; and params are always null
+       public DefaultHighLevelStateHandler(SubmodelComponent component, Void params)
+       {
+               // nothing to do here
+       }
+
+       @Override
+       public void setHighLevelState(String stateID, Object newState)
+       {
+               throw new IllegalArgumentException("No high level state with ID " + stateID);
+       }
+
+       @Override
+       public Object getHighLevelState(String stateID)
+       {
+               throw new IllegalArgumentException("No high level state with ID " + stateID);
+       }
+
+       static
+       {
+               CodeSnippetSupplier.highLevelStateHandlerSupplier.setSnippetSupplier(DefaultHighLevelStateHandler.class.getCanonicalName(),
+                               SnippetSupplier.create(Void.class, DefaultHighLevelStateHandler::new));
+       }
+}
\ No newline at end of file
index d55de89..0f25c8c 100644 (file)
@@ -4,5 +4,6 @@ mograsim version: 0.1.3
   "standardSymbolRendererSuppliers": {
     "CenteredTextSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.CenteredTextSymbolRenderer",
     "SimpleRectangularLikeSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer"
-  }
+  },
+  "standardHighLevelStateHandlerSuppliers": {}
 }
\ No newline at end of file