From 4c1cb062db70c2644aff237109a03cb60cd5562f Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 15 May 2019 10:41:01 +0200 Subject: [PATCH] Implemented GUINotGate --- LogicUI/src/LogicUI.java | 4 +- .../src/era/mi/components/gui/GUINotGate.java | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 LogicUI/src/era/mi/components/gui/GUINotGate.java diff --git a/LogicUI/src/LogicUI.java b/LogicUI/src/LogicUI.java index 501f1933..e572730a 100644 --- a/LogicUI/src/LogicUI.java +++ b/LogicUI/src/LogicUI.java @@ -11,10 +11,10 @@ import org.eclipse.swt.widgets.Shell; import era.mi.components.gui.BasicGUIComponent; 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.components.gates.NotGate; import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.gcs.TranslatedGC; @@ -51,7 +51,7 @@ public class LogicUI 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); - new NotGate(1, f, g); + 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); addComponent(new GUISplitter(i, k, j), 40, 10); diff --git a/LogicUI/src/era/mi/components/gui/GUINotGate.java b/LogicUI/src/era/mi/components/gui/GUINotGate.java new file mode 100644 index 00000000..8078b0c6 --- /dev/null +++ b/LogicUI/src/era/mi/components/gui/GUINotGate.java @@ -0,0 +1,65 @@ +package era.mi.components.gui; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import era.mi.logic.components.gates.NotGate; +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 GUINotGate extends NotGate implements BasicGUIComponent +{ + private static final String LABEL = "\u22651";//>=1 + + private final List connectedWireArrays; + private final List wireArrayConnectionPoints; + + public GUINotGate(int processTime, WireArray in, WireArray out) + { + super(processTime, in, out); + + List connectedWireArraysModifiable = new ArrayList<>(); + List wireArrayConnectionPointsModifiable = new ArrayList<>(); + + connectedWireArraysModifiable.add(in); + wireArrayConnectionPointsModifiable.add(new Point(0, 5)); + + connectedWireArraysModifiable.add(out); + wireArrayConnectionPointsModifiable.add(new Point(20, 5)); + + this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); + this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + } + + @Override + public void render(GeneralGC gc) + { + gc.drawRectangle(0, 0, 17, 10); + Font oldFont = gc.getFont(); + Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle()); + gc.setFont(labelFont); + Point textExtent = gc.textExtent(LABEL); + gc.drawText(LABEL, 10 - textExtent.x / 2, 5 - textExtent.y / 2, true); + gc.setFont(oldFont); + gc.drawOval(17, 3.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 -- 2.17.1