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=da0a45062ac4d0dc2c6a1788f77dadccbfa2f553;hb=5ece0acf049bf9af2933f513fe0206565681f622;hp=c412c56ee5319b74cb30403eacf1aa8ef1ec97d3;hpb=ebb085f881b06ed507aae6b229e36cdfa93d1ee5;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 c412c56e..da0a4506 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,16 +1,18 @@ package net.mograsim.logic.ui.model.wires; -import java.util.Map; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; 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.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; -import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate; +import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; /** * A {@link GUIComponent} with only one pin. Is used to create wires connecting more than two pins.
@@ -44,7 +46,12 @@ public class WireCrossPoint extends GUIComponent public WireCrossPoint(ViewModelModifiable model, int logicWidth) { - super(model); + this(model, logicWidth, null); + } + + public WireCrossPoint(ViewModelModifiable model, int logicWidth, String name) + { + super(model, name); logicObs = (i) -> requestRedraw(); setSize(CIRCLE_DIAM, CIRCLE_DIAM); @@ -73,8 +80,10 @@ public class WireCrossPoint extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), - () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM)); + ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); + if (wireColor != null) + gc.setBackground(ColorManager.current().toColor(wireColor)); + gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM); } // logic model binding @@ -95,13 +104,25 @@ public class WireCrossPoint extends GUIComponent end.registerObserver(logicObs); } + /** + * Returns whether this {@link WireCrossPoint} has a logic model binding or not. + */ + public boolean hasLogicModelBinding() + { + return end != null; + } + // serializing @Override - public Map getInstantiationParameters() + public JsonElement getParams() + { + return new JsonPrimitive(pin.logicWidth); + } + + static { - Map m = super.getInstantiationParameters(); - m.put(SimpleRectangularGUIGate.kLogicWidth, pin.logicWidth); - return m; + IndirectGUIComponentCreator.setComponentSupplier(WireCrossPoint.class.getCanonicalName(), + (m, p, n) -> new WireCrossPoint(m, p.getAsInt(), n)); } } \ No newline at end of file