Wrote TODO
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / GUIComponent.java
index 382d7e3..2ffe890 100644 (file)
@@ -14,6 +14,8 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.model.model.ViewModelModifiable;
 import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.serializing.IdentifierGetter;
+import net.mograsim.logic.model.serializing.JSONSerializable;
 import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 
 /**
@@ -24,7 +26,7 @@ import net.mograsim.logic.model.snippets.HighLevelStateHandler;
  * 
  * @author Daniel Kirschten
  */
-public abstract class GUIComponent
+public abstract class GUIComponent implements JSONSerializable
 {
        /**
         * The model this component is a part of.
@@ -51,6 +53,9 @@ public abstract class GUIComponent
        private final List<Runnable> redrawListeners;
 
        private final Runnable redrawListenerForSubcomponents;
+
+       private HighLevelStateHandler highLevelStateHandler;
+
        // creation and destruction
 
        public GUIComponent(ViewModelModifiable model, String name)
@@ -69,6 +74,8 @@ public abstract class GUIComponent
 
                redrawListenerForSubcomponents = this::requestRedraw;
 
+               // TODO this will crash the high level state debug shell because submodel is not yet set.
+               // The same problem exists in ViewModelModifiable.getDefaultComponentName; see there
                model.componentCreated(this);
        }
 
@@ -148,6 +155,19 @@ public abstract class GUIComponent
 
        // high-level access
 
+       /**
+        * @author Daniel Kirschten
+        */
+       protected void setHighLevelStateHandler(HighLevelStateHandler highLevelStateHandler)
+       {
+               this.highLevelStateHandler = highLevelStateHandler;
+       }
+
+       public HighLevelStateHandler getHighLevelStateHandler()
+       {
+               return highLevelStateHandler;
+       }
+
        /**
         * Gets the current value of the given high-level state. <br>
         * See {@link HighLevelStateHandler} for an explanation of high-level state IDs.
@@ -157,10 +177,9 @@ public abstract class GUIComponent
         * 
         * @author Daniel Kirschten
         */
-       @SuppressWarnings("static-method") // this method is intended to be overridden
        public Object getHighLevelState(String stateID)
        {
-               throw new IllegalArgumentException("No high level state with ID " + stateID);
+               return highLevelStateHandler.getHighLevelState(stateID);
        }
 
        /**
@@ -172,10 +191,9 @@ public abstract class GUIComponent
         * 
         * @author Daniel Kirschten
         */
-       @SuppressWarnings({ "static-method", "unused" }) // this method is intended to be overridden
        public void setHighLevelState(String stateID, Object newState)
        {
-               throw new IllegalArgumentException("No high level state with ID " + stateID);
+               highLevelStateHandler.setHighLevelState(stateID, newState);
        }
 
        // "graphical" operations
@@ -278,8 +296,8 @@ public abstract class GUIComponent
 
        // serializing
 
-       @SuppressWarnings("static-method") // this method is intended to be overridden
-       public JsonElement getParamsForSerializing()
+       @Override
+       public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
        {
                return JsonNull.INSTANCE;
        }