Implemented GUINotGate
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 08:41:01 +0000 (10:41 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 08:41:01 +0000 (10:41 +0200)
LogicUI/src/LogicUI.java
LogicUI/src/era/mi/components/gui/GUINotGate.java [new file with mode: 0644]

index 34ac68b..0ed5e95 100644 (file)
@@ -11,10 +11,10 @@ import org.eclipse.swt.widgets.Shell;
 import era.mi.components.gui.BasicGUIComponent;\r
 import era.mi.components.gui.GUIMerger;\r
 import era.mi.components.gui.GUIMux;\r
 import era.mi.components.gui.BasicGUIComponent;\r
 import era.mi.components.gui.GUIMerger;\r
 import era.mi.components.gui.GUIMux;\r
+import era.mi.components.gui.GUINotGate;\r
 import era.mi.components.gui.GUISplitter;\r
 import era.mi.logic.Simulation;\r
 import era.mi.logic.components.gates.AndGate;\r
 import era.mi.components.gui.GUISplitter;\r
 import era.mi.logic.Simulation;\r
 import era.mi.logic.components.gates.AndGate;\r
-import era.mi.logic.components.gates.NotGate;\r
 import era.mi.logic.wires.WireArray;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
 import net.haspamelodica.swt.helper.gcs.TranslatedGC;\r
 import era.mi.logic.wires.WireArray;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
 import net.haspamelodica.swt.helper.gcs.TranslatedGC;\r
@@ -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),\r
                                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);\r
                new AndGate(1, f, a, b);\r
                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),\r
                                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);\r
                new AndGate(1, f, a, b);\r
-               new NotGate(1, f, g);\r
+               addComponent(new GUINotGate(1, f, g), 100, 10);\r
                addComponent(new GUIMerger(h, c, g), 70, 10);\r
                addComponent(new GUIMux(1, i, e, h, d), 10, 10);\r
                addComponent(new GUISplitter(i, k, j), 40, 10);\r
                addComponent(new GUIMerger(h, c, g), 70, 10);\r
                addComponent(new GUIMux(1, i, e, h, d), 10, 10);\r
                addComponent(new GUISplitter(i, k, j), 40, 10);\r
diff --git a/LogicUI/src/era/mi/components/gui/GUINotGate.java b/LogicUI/src/era/mi/components/gui/GUINotGate.java
new file mode 100644 (file)
index 0000000..a66c24d
--- /dev/null
@@ -0,0 +1,65 @@
+package era.mi.components.gui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import era.mi.logic.components.gates.NotGate;\r
+import era.mi.logic.wires.WireArray;\r
+import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Font;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
+\r
+public class GUINotGate extends NotGate implements BasicGUIComponent\r
+{\r
+       private static final String LABEL = "\u22651";//>=1\r
+\r
+       private final List<WireArray>   connectedWireArrays;\r
+       private final List<Point>               wireArrayConnectionPoints;\r
+\r
+       public GUINotGate(int processTime, WireArray in, WireArray out)\r
+       {\r
+               super(processTime, in, out);\r
+\r
+               List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
+               List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
+\r
+               connectedWireArraysModifiable.add(in);\r
+               wireArrayConnectionPointsModifiable.add(new Point(0, 5));\r
+\r
+               connectedWireArraysModifiable.add(out);\r
+               wireArrayConnectionPointsModifiable.add(new Point(20, 5));\r
+\r
+               this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
+               this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\r
+       }\r
+\r
+       @Override\r
+       public void render(GeneralGC gc)\r
+       {\r
+               gc.drawRectangle(0, 0, 17, 10);\r
+               Font oldFont = gc.getFont();\r
+               Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());\r
+               gc.setFont(labelFont);\r
+               Point textExtent = gc.textExtent(LABEL);\r
+               gc.drawText(LABEL, 10 - textExtent.x / 2, 5 - textExtent.y / 2, true);\r
+               gc.setFont(oldFont);\r
+               gc.drawOval(17, 3.5, 3, 3);\r
+       }\r
+\r
+       @Override\r
+       public int getConnectedWireArraysCount()\r
+       {\r
+               return connectedWireArrays.size();\r
+       }\r
+       @Override\r
+       public WireArray getConnectedWireArray(int connectionIndex)\r
+       {\r
+               return connectedWireArrays.get(connectionIndex);\r
+       }\r
+       @Override\r
+       public Point getWireArrayConnectionPoint(int connectionI)\r
+       {\r
+               return wireArrayConnectionPoints.get(connectionI);\r
+       }\r
+}
\ No newline at end of file