X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fnet.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fsnippets%2Fhighlevelstatehandlers%2Fstandard%2Fatomic%2FDelegatingAtomicHighLevelStateHandler.java;h=98890fe743787c07f0103e0f9410ef2d540e9b85;hb=69ec19d54ceb6d5abbb8b4faa55284af22174859;hp=cdc7e4a2d9ee284b2d961dd824e4ed9f39b7f454;hpb=f1933b06b5fe800902131e4dc34f002ac3fa17f0;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/DelegatingAtomicHighLevelStateHandler.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/DelegatingAtomicHighLevelStateHandler.java index cdc7e4a2..98890fe7 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/DelegatingAtomicHighLevelStateHandler.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/DelegatingAtomicHighLevelStateHandler.java @@ -1,5 +1,7 @@ package net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic; +import java.util.function.Consumer; + import net.mograsim.logic.model.model.components.ModelComponent; import net.mograsim.logic.model.model.components.submodels.SubmodelComponent; import net.mograsim.logic.model.serializing.IdentifyParams; @@ -75,17 +77,35 @@ public class DelegatingAtomicHighLevelStateHandler implements AtomicHighLevelSta @Override public Object getHighLevelState() { - if (delegateTarget == null) - throw new IllegalStateException("Delegating to a component that was destroyed"); + checkTarget(); return delegateTarget.getHighLevelState(subStateID); } @Override public void setHighLevelState(Object newState) + { + checkTarget(); + delegateTarget.setHighLevelState(subStateID, newState); + } + + @Override + public void addListener(Consumer stateChanged) + { + checkTarget(); + delegateTarget.addHighLevelStateListener(subStateID, stateChanged); + } + + @Override + public void removeListener(Consumer stateChanged) + { + checkTarget(); + delegateTarget.removeHighLevelStateListener(subStateID, stateChanged); + } + + private void checkTarget() { if (delegateTarget == null) throw new IllegalStateException("Delegating to a component that was destroyed"); - delegateTarget.setHighLevelState(subStateID, newState); } @Override @@ -97,8 +117,7 @@ public class DelegatingAtomicHighLevelStateHandler implements AtomicHighLevelSta @Override public DelegatingAtomicHighLevelStateHandlerParams getParamsForSerializing(IdentifyParams idParams) { - if (delegateTarget == null) - throw new IllegalStateException("Delegating to a component that was destroyed"); + checkTarget(); DelegatingAtomicHighLevelStateHandlerParams params = new DelegatingAtomicHighLevelStateHandlerParams(); params.delegateTarget = delegateTarget == parentComponent ? null : delegateTarget.getName(); params.subStateID = subStateID;