package net.mograsim.logic.model.model.components.atomic;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
import org.eclipse.swt.graphics.Color;
import com.google.gson.JsonSyntaxException;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.core.LogicObserver;
import net.mograsim.logic.core.components.CoreClock;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.components.ModelComponent;
import net.mograsim.logic.model.model.components.Orientation;
private OrientationCalculator oc;
private CoreClock clock;
+ private final List<Consumer<Object>> hlsListeners;
+
public ModelClock(LogicModelModifiable model, ModelClockParams params)
{
this(model, params, null);
{
super(model, name, false);
this.params = params;
- logicObs = (i) -> model.requestRedraw();
oc = new OrientationCalculator(params.orientation, width, height);
setSize(oc.width(), oc.height());
this.outputPin = new Pin(model, this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2));
addPin(outputPin);
+ this.hlsListeners = new ArrayList<>();
+
+ logicObs = i ->
+ {
+ model.requestRedraw();
+ BitVector v = getOutValues();
+ hlsListeners.forEach(l -> l.accept(v));
+ };
+
setHighLevelStateHandler(new HighLevelStateHandler()
{
@Override
- public Object getHighLevelState(String stateID)
+ public Object get(String stateID)
{
switch (stateID)
{
case "out":
if (clock != null)
- return clock.getOut().getInputValues();
+ return getOutValues();
return null;
default:
throw new IllegalArgumentException("No high level state with ID " + stateID);
}
@Override
- public void setHighLevelState(String stateID, Object newState)
+ public void set(String stateID, Object newState)
{
switch (stateID)
{
}
}
+ @Override
+ public void addListener(String stateID, Consumer<Object> stateChanged)
+ {
+ switch (stateID)
+ {
+ case "out":
+ hlsListeners.add(stateChanged);
+ break;
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
+ @Override
+ public void removeListener(String stateID, java.util.function.Consumer<Object> stateChanged)
+ {
+ switch (stateID)
+ {
+ case "out":
+ hlsListeners.remove(stateChanged);
+ break;
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
@Override
public String getIDForSerializing(IdentifyParams idParams)
{
return clock != null;
}
+ // TODO remove
public CoreClock getClock()
{
return clock;
return params;
}
+ private BitVector getOutValues()
+ {
+ return clock.getOutValues();
+ }
+
static
{
LogicCoreAdapter.addComponentAdapter(new ClockAdapter());