X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fwires%2FWireCrossPoint.java;h=2b07238f58f36f8cb5c66dfc57f0290df73cd265;hb=19b9fa6c1cfcd7036c5b0c44c892f029cd04879b;hp=0949ffbb2e373ddd825006b7b7966d3c4a686b37;hpb=67c1d352795802dae0c045cedeed82c883819d4e;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java index 0949ffbb..2b07238f 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java @@ -1,49 +1,92 @@ -package net.mograsim.logic.ui.model.wires; - -import net.mograsim.logic.ui.ColorHelper; -import net.mograsim.logic.ui.model.ViewModel; -import net.mograsim.logic.ui.model.components.GUIComponent; -import net.haspamelodica.swt.helper.gcs.GeneralGC; -import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; -import net.mograsim.logic.core.types.BitVectorFormatter; -import net.mograsim.logic.core.wires.Wire.ReadEnd; - -public class WireCrossPoint extends GUIComponent -{ - private final Pin pin; - - private ReadEnd end; - private final int logicWidth; - - public WireCrossPoint(ViewModel model, int logicWidth) - { - super(model); - this.logicWidth = logicWidth; - setSize(0, 0); - addPin(this.pin = new Pin(this, logicWidth, 0, 0)); - } - - @Override - public void render(GeneralGC gc, Rectangle visibleRegion) - { - Rectangle bounds = getBounds(); - ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), - () -> gc.fillOval(bounds.x - 1, bounds.y - 1, 2, 2)); - } - - public void setLogicModelBinding(ReadEnd end) - { - this.end = end; - end.addObserver((i, o) -> callComponentLookChangedListeners()); - } - - public int getLogicWidth() - { - return logicWidth; - } - - public Pin getPin() - { - return pin; - } +package net.mograsim.logic.ui.model.wires; + +import java.util.Map; + +import net.haspamelodica.swt.helper.gcs.GeneralGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; +import net.mograsim.logic.core.LogicObservable; +import net.mograsim.logic.core.LogicObserver; +import net.mograsim.logic.core.types.BitVectorFormatter; +import net.mograsim.logic.core.wires.Wire.ReadEnd; +import net.mograsim.logic.ui.ColorHelper; +import net.mograsim.logic.ui.model.ModelVisitor; +import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.logic.ui.model.components.GUIComponent; +import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate; + +public class WireCrossPoint extends GUIComponent +{ + private static final int CIRCLE_RADIUS = 1; + private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2; + + private final Pin pin; + private final int logicWidth; + + private final LogicObserver logicObs; + private ReadEnd end; + + public WireCrossPoint(ViewModelModifiable model, int logicWidth) + { + super(model); + logicObs = (i) -> requestRedraw(); + + this.logicWidth = logicWidth; + setSize(CIRCLE_DIAM, CIRCLE_DIAM); + addPin(this.pin = new Pin(this, "", logicWidth, CIRCLE_RADIUS, CIRCLE_RADIUS)); + } + + public void moveCenterTo(double x, double y) + { + moveTo(x - CIRCLE_RADIUS, y - CIRCLE_RADIUS); + } + + @Override + public void render(GeneralGC gc, Rectangle visibleRegion) + { + ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), + () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM)); + } + + public void setLogicModelBinding(ReadEnd end) + { + deregisterLogicObs(this.end); + this.end = end; + registerLogicObs(end); + } + + private void registerLogicObs(LogicObservable observable) + { + if (observable != null) + observable.registerObserver(logicObs); + } + + private void deregisterLogicObs(LogicObservable observable) + { + if (observable != null) + observable.deregisterObserver(logicObs); + } + + public int getLogicWidth() + { + return logicWidth; + } + + public Pin getPin() + { + return pin; + } + + @Override + public Map getInstantiationParameters() + { + Map m = super.getInstantiationParameters(); + m.put(SimpleRectangularGUIGate.kLogicWidth, logicWidth); + return m; + } + + @Override + public void accept(ModelVisitor mv) + { + mv.visit(this); + } } \ No newline at end of file