X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSimpleRectangularGUIGate.java;fp=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSimpleRectangularGUIGate.java;h=0000000000000000000000000000000000000000;hb=01c5d7035474a5eb58f216b6831b2c0d8c174efa;hp=0dd4c40318c73c6ffd492dc104e23169f4833237;hpb=4ac977cb31feb34f24e05e9d5e7976951dccf557;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 deleted file mode 100644 index 0dd4c403..00000000 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.mograsim.logic.ui.model.components; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.graphics.Color; - -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; -import net.mograsim.preferences.Preferences; - -public class SimpleRectangularGUIGate extends GUIComponent -{ - private static final double width = 20; - private static final double pinDistance = 10; - private static final double fontHeight = 5; - private static final double invertedCircleDiam = 3.5; - - private final String label; - protected final int logicWidth; - private final boolean isInverted; - private final double rectWidth; - - private MovablePin outputPin; - private final List inputPins; - - 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, "Y", logicWidth, width, 0); - addPin(outputPin); - this.inputPins = new ArrayList<>(); - setInputCount(1); - } - - protected void setInputCount(int inputCount) - { - int oldInputCount = inputPins.size(); - setSize(width, inputCount * pinDistance); - if (oldInputCount > inputCount) - while (inputPins.size() > inputCount) - removePin(inputPins.remove(inputCount).name); - else if (oldInputCount < inputCount) - for (int i = oldInputCount; i < inputCount; i++) - { - // 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); - } - - @Override - public void render(GeneralGC gc, Rectangle visibleRegion) - { - Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground"); - if (foreground != null) - gc.setForeground(foreground); - double height = (getPins().size() - 1) * pinDistance; - gc.drawRectangle(getPosX(), getPosY(), rectWidth, height); - if (isInverted) - gc.drawOval(getPosX() + rectWidth, getPosY() + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); - Font oldFont = gc.getFont(); - Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); - gc.setFont(labelFont); - Point textExtent = gc.textExtent(label); - Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text"); - if (textColor != null) - gc.setForeground(textColor); - gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); - gc.setFont(oldFont); - } - - @Override - public Map getInstantiationParameters() - { - Map m = super.getInstantiationParameters(); - m.put(kLogicWidth, logicWidth); - return m; - } -} \ No newline at end of file