X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSimpleRectangularGUIGate.java;h=96bf11e6aa788078fd596b01e1d3ce09192a5760;hb=a19dde054ec5cab3c835840d569880ee8ee156dc;hp=a1b0c8ad4a48972f5e3802c0a9eecd814b468c70;hpb=9c142c9ad59d2af070ebb6495b1ca48242da62d8;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java index a1b0c8ad..96bf11e6 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java @@ -1,8 +1,8 @@ package net.mograsim.logic.ui.model.components; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.Map; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; @@ -26,7 +26,8 @@ public class SimpleRectangularGUIGate extends GUIComponent private MovablePin outputPin; private final List inputPins; - private final List inputPinsUnmodifiable; + + public static final String kLogicWidth = "logicWidth"; protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted) { @@ -35,10 +36,9 @@ public class SimpleRectangularGUIGate extends GUIComponent this.logicWidth = logicWidth; this.isInverted = isInverted; this.rectWidth = width - (isInverted ? invertedCircleDiam : 0); - this.outputPin = new MovablePin(this, logicWidth, width, 0); + this.outputPin = new MovablePin(this, "Y", logicWidth, width, 0); addPin(outputPin); this.inputPins = new ArrayList<>(); - this.inputPinsUnmodifiable = Collections.unmodifiableList(inputPins); setInputCount(1); } @@ -48,34 +48,25 @@ public class SimpleRectangularGUIGate extends GUIComponent setSize(width, inputCount * pinDistance); if (oldInputCount > inputCount) while (inputPins.size() > inputCount) - removePin(inputPins.get(inputCount)); + removePin(inputPins.remove(inputCount).name); else if (oldInputCount < inputCount) for (int i = oldInputCount; i < inputCount; i++) { - Pin pin = new Pin(this, logicWidth, 0, pinDistance / 2 + i * pinDistance); + // TODO what for more than 24 input pins? + Pin pin = new Pin(this, String.valueOf((char) ('A' + i)), logicWidth, 0, pinDistance / 2 + i * pinDistance); inputPins.add(pin); addPin(pin); } outputPin.setRelPos(width, inputCount * pinDistance / 2); } - public Pin getOutputPin() - { - return outputPin; - } - - public List getInputPins() - { - return inputPinsUnmodifiable; - } - @Override public void render(GeneralGC gc, Rectangle visibleRegion) { double posX = getBounds().x; double posY = getBounds().y; - double height = inputPins.size() * pinDistance; + double height = (getPins().size() - 1) * pinDistance; gc.drawRectangle(posX, posY, rectWidth, height); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); @@ -86,4 +77,12 @@ public class SimpleRectangularGUIGate extends GUIComponent if (isInverted) gc.drawOval(posX + rectWidth, posY + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); } + + @Override + public Map getInstantiationParameters() + { + Map m = super.getInstantiationParameters(); + m.put(kLogicWidth, logicWidth); + return m; + } } \ No newline at end of file