X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2FGUIComponent.java;h=85b1e5a081b7d2598d722cb89b1790c258b90047;hb=a25f554756e1bc9a1f842293aefe60a220d8b950;hp=4baf33527e8f8907c0889fdf35ae78cd894c5b8c;hpb=d333df14f718d96b419d751c6b2c64c6375726a8;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/GUIComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/GUIComponent.java index 4baf3352..85b1e5a0 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/GUIComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/GUIComponent.java @@ -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,14 +26,14 @@ 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. */ protected final ViewModelModifiable model; /** - * The name of this component. Is unique in its model. + * The name of this component. Is unique for all components in its model. */ public final String name; private final Rectangle bounds; @@ -51,6 +53,9 @@ public abstract class GUIComponent private final List redrawListeners; private final Runnable redrawListenerForSubcomponents; + + private HighLevelStateHandler highLevelStateHandler; + // creation and destruction public GUIComponent(ViewModelModifiable model, String name) @@ -149,18 +154,16 @@ public abstract class GUIComponent // high-level access /** - * Sets the given high-level state to the given value.
- * See {@link HighLevelStateHandler} for an explanation of high-level state IDs. - * - * @see #getHighLevelState(String) - * @see HighLevelStateHandler#setHighLevelState(String, Object) - * * @author Daniel Kirschten */ - @SuppressWarnings({ "static-method", "unused" }) // this method is intended to be overridden - public void setHighLevelState(String stateID, Object newState) + protected void setHighLevelStateHandler(HighLevelStateHandler highLevelStateHandler) + { + this.highLevelStateHandler = highLevelStateHandler; + } + + public HighLevelStateHandler getHighLevelStateHandler() { - throw new IllegalArgumentException("No high level state with ID " + stateID); + return highLevelStateHandler; } /** @@ -172,10 +175,23 @@ 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); + } + + /** + * Sets the given high-level state to the given value.
+ * See {@link HighLevelStateHandler} for an explanation of high-level state IDs. + * + * @see #getHighLevelState(String) + * @see HighLevelStateHandler#setHighLevelState(String, Object) + * + * @author Daniel Kirschten + */ + public void setHighLevelState(String stateID, Object newState) + { + highLevelStateHandler.setHighLevelState(stateID, newState); } // "graphical" operations @@ -278,8 +294,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; }