X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FSimpleRectangularHardcodedGUIComponent.java;h=b79b2e95dc0eaecd50c0c0c7c4e7c5ed313e7cd7;hb=039f31334c661633b71e945aa4332cedb7055526;hp=c384b540d04bb8854f7d01ae3be1ce6463393d4d;hpb=bbe38c55aaa999d025f534245f9207a88643f6e5;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularHardcodedGUIComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularHardcodedGUIComponent.java index c384b540..b79b2e95 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularHardcodedGUIComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularHardcodedGUIComponent.java @@ -1,6 +1,7 @@ package net.mograsim.logic.model.model.components.atomic; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; @@ -11,6 +12,8 @@ import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.SimpleRectangularHardcodedGUIComponentAdapter; +import net.mograsim.logic.model.serializing.IdentifyParams; +import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer; import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer; import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams; @@ -24,15 +27,21 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen private static final double pinNamesHeight = 3.5; private static final double pinNamesMargin = .5; + private final String id; + private final DefaultOutlineRenderer outlineRenderer; private final CenteredTextSymbolRenderer centerTextRenderer; private final PinNamesSymbolRenderer pinNamesRenderer; + private AtomicReference state; + private Runnable recalculate; + // creation and destruction - public SimpleRectangularHardcodedGUIComponent(ViewModelModifiable model, String name, String centerText) + public SimpleRectangularHardcodedGUIComponent(ViewModelModifiable model, String id, String name, String centerText) { super(model, name); + this.id = id; this.outlineRenderer = new DefaultOutlineRenderer(this); CenteredTextParams centeredTextParams = new CenteredTextParams(); centeredTextParams.text = centerText; @@ -43,6 +52,33 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen pinNamesParams.pinLabelMargin = pinNamesMargin; this.pinNamesRenderer = new PinNamesSymbolRenderer(this, pinNamesParams); addPinRemovedListener(this::pinRemoved); + setHighLevelStateHandler(new HighLevelStateHandler() + { + @Override + public String getIDForSerializing(IdentifyParams idParams) + { + return null;// we don't need to serialize this; it's implicit since we are a SimpleRectangularHardcodedGUIComponent + } + + @Override + public Object getParamsForSerializing(IdentifyParams idParams) + { + return null; + } + + @Override + public Object getHighLevelState(String stateID) + { + return SimpleRectangularHardcodedGUIComponent.this.getHighLevelState(state.get(), stateID); + } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + state.updateAndGet(s -> SimpleRectangularHardcodedGUIComponent.this.setHighLevelState(s, stateID, newState)); + recalculate.run(); + } + }); } // pins @@ -58,9 +94,31 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen pinNamesRenderer.setPinPosition(pin, null); } + // high-level access + + @SuppressWarnings({ "static-method", "unused" }) // this method is intended to be overridden + protected Object getHighLevelState(Object state, String stateID) + { + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + + @SuppressWarnings({ "static-method", "unused" }) // this method is intended to be overridden + protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) + { + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + // logic - protected abstract Object recalculate(Object lastState, Map readEnds, Map readWriteEnds); + public abstract Object recalculate(Object lastState, Map readEnds, Map readWriteEnds); + + // logic model binding + + public void setLogicModelBindingAndResetState(AtomicReference state, Runnable recalculate) + { + this.state = state; + this.recalculate = recalculate; + } // "graphical" operations @@ -72,6 +130,14 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen pinNamesRenderer.render(gc, visibleRegion); } + // serializing + + @Override + public String getIDForSerializing(IdentifyParams idParams) + { + return id; + } + // operations no longer supported @Override @@ -82,6 +148,6 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen static { - ViewLogicModelAdapter.addComponentAdapter(new SimpleRectangularHardcodedGUIComponentAdapter(c -> c::recalculate)); + ViewLogicModelAdapter.addComponentAdapter(new SimpleRectangularHardcodedGUIComponentAdapter()); } } \ No newline at end of file