Implemented GUIOrGate
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 22:09:53 +0000 (00:09 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 22:09:53 +0000 (00:09 +0200)
LogicUI/src/era/mi/components/gui/GUIOrGate.java [new file with mode: 0644]

diff --git a/LogicUI/src/era/mi/components/gui/GUIOrGate.java b/LogicUI/src/era/mi/components/gui/GUIOrGate.java
new file mode 100644 (file)
index 0000000..1ace000
--- /dev/null
@@ -0,0 +1,81 @@
+package era.mi.components.gui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import era.mi.logic.components.gates.OrGate;\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
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;\r
+\r
+public class GUIOrGate extends OrGate implements BasicGUIComponent\r
+{\r
+       private static final String LABEL = "\u22651";//>=1\r
+\r
+       private final int                               inputCount;\r
+       private final double                    height;\r
+       private final List<WireArray>   connectedWireArrays;\r
+       private final List<Point>               wireArrayConnectionPoints;\r
+\r
+       public GUIOrGate(int processTime, WireArray out, WireArray... in)\r
+       {\r
+               super(processTime, out, in);\r
+\r
+               List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
+               List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
+\r
+               this.inputCount = in.length;\r
+               this.height = inputCount * 10;\r
+\r
+               {\r
+                       connectedWireArraysModifiable.addAll(Arrays.asList(in));\r
+                       double inputHeight = 5;\r
+                       for(int i = 0; i < inputCount; i ++, inputHeight += 10)\r
+                               wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));\r
+               }\r
+\r
+               connectedWireArraysModifiable.add(out);\r
+               wireArrayConnectionPointsModifiable.add(new Point(20, height / 2));\r
+\r
+               this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
+               this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\r
+       }\r
+\r
+       @Override\r
+       public Rectangle getBounds()\r
+       {\r
+               return new Rectangle(0, 0, 20, height);\r
+       }\r
+       @Override\r
+       public void render(GeneralGC gc)\r
+       {\r
+               gc.drawRectangle(0, 0, 17, height);\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, 8.5 - textExtent.x / 2, (height - textExtent.y) / 2, true);\r
+               gc.setFont(oldFont);\r
+               gc.drawOval(17, height / 2 - 1.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