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=d263f6de9795bcf31ed9fb44850a53e28cae8a85;hb=c223a9de7b0ef783bcb4f7612da350583ca29abd;hp=a2875c6a0b54859336d86a2f24ad03fe0350013c;hpb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;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 a2875c6a..d263f6de 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,16 +1,16 @@ 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.mograsim.logic.ui.model.ViewModel; -import net.mograsim.logic.ui.model.wires.MovablePin; -import net.mograsim.logic.ui.model.wires.Pin; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; +import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.logic.ui.model.wires.MovablePin; +import net.mograsim.logic.ui.model.wires.Pin; public class SimpleRectangularGUIGate extends GUIComponent { @@ -26,19 +26,19 @@ public class SimpleRectangularGUIGate extends GUIComponent private MovablePin outputPin; private final List inputPins; - private final List inputPinsUnmodifiable; - protected SimpleRectangularGUIGate(ViewModel model, int logicWidth, String label, boolean isInverted) + public static final String kLogicWidth = "logicWidth"; + + protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted) { super(model); this.label = label; 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,42 +48,38 @@ 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; - gc.drawRectangle(posX, posY, rectWidth, height); + double height = (getPins().size() - 1) * pinDistance; + gc.drawRectangle(getPosX(), getPosY(), rectWidth, height); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (rectWidth - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); gc.setFont(oldFont); if (isInverted) - gc.drawOval(posX + rectWidth, posY + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); + gc.drawOval(getPosX() + rectWidth, getPosY() + (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