+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.ManualSwitch;\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 GUIManualSwitch extends ManualSwitch implements BasicGUIComponent\r
+{\r
+ private final List<WireArray> connectedWireArrays;\r
+ private final List<Point> wireArrayConnectionPoints;\r
+\r
+ public GUIManualSwitch(WireArray output)\r
+ {\r
+ super(output);\r
+\r
+ List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
+ List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
+\r
+ connectedWireArraysModifiable.add(output);\r
+ wireArrayConnectionPointsModifiable.add(new Point(20, 7.5));\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, 15);\r
+ }\r
+ @Override\r
+ public void render(GeneralGC gc)\r
+ {\r
+ gc.drawRectangle(0, 0, 20, 15);\r
+ String label = isOn() ? "ON" : "OFF";\r
+ Font oldFont = gc.getFont();\r
+ Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle());\r
+ gc.setFont(labelFont);\r
+ Point textExtent = gc.textExtent(label);\r
+ gc.drawText(label, 10 - textExtent.x / 2, 7.5 - textExtent.y / 2, true);\r
+ gc.setFont(oldFont);\r
+ }\r
+ @Override\r
+ public boolean clicked(double x, double y)\r
+ {\r
+ toggle();\r
+ return true;\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