1 package era.mi.components.gui;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import era.mi.logic.components.ManualSwitch;
8 import era.mi.logic.wires.WireArray;
9 import net.haspamelodica.swt.helper.gcs.GeneralGC;
10 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
12 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
14 public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent
16 private final List<WireArray> connectedWireArrays;
17 private final List<Point> wireArrayConnectionPoints;
19 public GUIManualSwitch(WireArray output)
23 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
24 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
26 connectedWireArraysModifiable.add(output);
27 wireArrayConnectionPointsModifiable.add(new Point(20, 7.5));
29 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
30 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
34 public Rectangle getBounds()
36 return new Rectangle(0, 0, 20, 15);
39 public void render(GeneralGC gc)
41 gc.drawRectangle(0, 0, 20, 15);
42 String label = isOn() ? "ON" : "OFF";
43 Font oldFont = gc.getFont();
44 Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle());
45 gc.setFont(labelFont);
46 Point textExtent = gc.textExtent(label);
47 gc.drawText(label, 10 - textExtent.x / 2, 7.5 - textExtent.y / 2, true);
51 public boolean clicked(double x, double y)
58 public int getConnectedWireArraysCount()
60 return connectedWireArrays.size();
63 public WireArray getConnectedWireArray(int connectionIndex)
65 return connectedWireArrays.get(connectionIndex);
68 public Point getWireArrayConnectionPoint(int connectionI)
70 return wireArrayConnectionPoints.get(connectionI);