From c3402b2701c171c5fd9df1b900abd50604869bf0 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 8 Jul 2019 10:48:30 +0200 Subject: [PATCH] CodeSnippetSupplier now supports high level state handlers --- .../ui/model/components/GUIComponent.java | 17 +++++----- .../ui/serializing/CodeSnippetSupplier.java | 6 ++++ .../snippets/HighLevelStateHandler.java | 34 +++++++++++++++++++ .../DefaultHighLevelStateHandler.java | 33 ++++++++++++++++++ .../serializing/standardSnippetIDMapping.json | 3 +- 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/HighLevelStateHandler.java create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/highlevelstatehandlers/DefaultHighLevelStateHandler.java diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java index 83e6d61d..952d753b 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java @@ -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.
@@ -142,13 +143,10 @@ public abstract class GUIComponent /** * Sets the given high-level state to the given value.
- * A high level state ID consists of parts separated by dots ('.').
- * 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.
- * If there is no dot in a high level state ID, the whole high level state ID is called atomic.
- * 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.
- * 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 */ diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java index 0c274610..a6b9dae7 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java @@ -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 // public static members public static final CodeSnippetSupplier symbolRendererSupplier; public static final CodeSnippetSupplier outlineRendererSupplier; + public static final CodeSnippetSupplier 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 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 { public Map standardOutlineRendererSuppliers; public Map standardSymbolRendererSuppliers; + public Map 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 index 00000000..596582a9 --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/HighLevelStateHandler.java @@ -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.
+ * A high level state ID consists of parts separated by dots ('.').
+ * 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.
+ * If there is no dot in a high level state ID, the whole high level state ID is called atomic.
+ * 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.
+ * 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 index 00000000..7a68708a --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/highlevelstatehandlers/DefaultHighLevelStateHandler.java @@ -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 diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json index d55de89e..0f25c8cd 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json @@ -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 -- 2.17.1