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>
/**
* 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
*/
/**
* 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
*/
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;
// 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
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)
{
{
public Map<String, String> standardOutlineRendererSuppliers;
public Map<String, String> standardSymbolRendererSuppliers;
+ public Map<String, String> standardHighLevelStateHandlerSuppliers;
}
private static void tryLoadSnippetClass(String snippetClassName)
--- /dev/null
+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
--- /dev/null
+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
"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