From: Daniel Kirschten Date: Wed, 15 May 2019 08:52:12 +0000 (+0200) Subject: Implemented GUIAndGate X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=c88be3fe785d0b1f9adcae3d9be3606e6982728d;p=Mograsim.git Implemented GUIAndGate --- diff --git a/LogicUI/src/LogicUI.java b/LogicUI/src/LogicUI.java index 50e8f96d..8242666e 100644 --- a/LogicUI/src/LogicUI.java +++ b/LogicUI/src/LogicUI.java @@ -9,12 +9,12 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import era.mi.components.gui.BasicGUIComponent; +import era.mi.components.gui.GUIAndGate; import era.mi.components.gui.GUIMerger; import era.mi.components.gui.GUIMux; import era.mi.components.gui.GUINotGate; import era.mi.components.gui.GUISplitter; import era.mi.logic.Simulation; -import era.mi.logic.components.gates.AndGate; import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.gcs.TranslatedGC; @@ -50,7 +50,7 @@ public class LogicUI Simulation.TIMELINE.reset(); WireArray a = new WireArray(1, 1), b = new WireArray(1, 1), c = new WireArray(1, 10), d = new WireArray(2, 1), e = new WireArray(1, 1), f = new WireArray(1, 1), g = new WireArray(1, 1), h = new WireArray(2, 1), i = new WireArray(2, 1), j = new WireArray(1, 1), k = new WireArray(1, 1); - new AndGate(1, f, a, b); + addComponent(new GUIAndGate(1, f, a, b), 130, 10); addComponent(new GUINotGate(1, f, g), 100, 10); addComponent(new GUIMerger(h, c, g), 70, 10); addComponent(new GUIMux(1, i, e, h, d), 10, 10); diff --git a/LogicUI/src/era/mi/components/gui/GUIAndGate.java b/LogicUI/src/era/mi/components/gui/GUIAndGate.java new file mode 100644 index 00000000..92bc86ed --- /dev/null +++ b/LogicUI/src/era/mi/components/gui/GUIAndGate.java @@ -0,0 +1,75 @@ +package era.mi.components.gui; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import era.mi.logic.components.gates.AndGate; +import era.mi.logic.wires.WireArray; +import net.haspamelodica.swt.helper.gcs.GeneralGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Font; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; + +public class GUIAndGate extends AndGate implements BasicGUIComponent +{ + private static final String LABEL = "&"; + + private final int inputCount; + private final double height; + private final List connectedWireArrays; + private final List wireArrayConnectionPoints; + + public GUIAndGate(int processTime, WireArray out, WireArray... in) + { + super(processTime, out, in); + + List connectedWireArraysModifiable = new ArrayList<>(); + List wireArrayConnectionPointsModifiable = new ArrayList<>(); + + this.inputCount = in.length; + this.height = inputCount * 10; + + { + connectedWireArraysModifiable.addAll(Arrays.asList(in)); + double inputHeight = 5; + for(int i = 0; i < inputCount; i ++, inputHeight += 10) + wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + } + + connectedWireArraysModifiable.add(out); + wireArrayConnectionPointsModifiable.add(new Point(20, height / 2)); + + this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); + this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + } + + @Override + public void render(GeneralGC gc) + { + gc.drawRectangle(0, 0, 17, height); + Font oldFont = gc.getFont(); + Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle()); + gc.setFont(labelFont); + Point textExtent = gc.textExtent(LABEL); + gc.drawText(LABEL, 8.5 - textExtent.x / 2, (height - textExtent.y) / 2, true); + gc.setFont(oldFont); + gc.drawOval(17, height / 2 - 1.5, 3, 3); + } + + @Override + public int getConnectedWireArraysCount() + { + return connectedWireArrays.size(); + } + @Override + public WireArray getConnectedWireArray(int connectionIndex) + { + return connectedWireArrays.get(connectionIndex); + } + @Override + public Point getWireArrayConnectionPoint(int connectionI) + { + return wireArrayConnectionPoints.get(connectionI); + } +} \ No newline at end of file