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