Fixed text centering being off 1.75px
[Mograsim.git] / LogicUI / src / era / mi / components / gui / GUINotGate.java
1 package era.mi.components.gui;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collections;\r
5 import java.util.List;\r
6 \r
7 import era.mi.logic.components.gates.NotGate;\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 \r
13 public class GUINotGate extends NotGate implements BasicGUIComponent\r
14 {\r
15         private static final String LABEL = "\u22651";//>=1\r
16 \r
17         private final List<WireArray>   connectedWireArrays;\r
18         private final List<Point>               wireArrayConnectionPoints;\r
19 \r
20         public GUINotGate(int processTime, WireArray in, WireArray out)\r
21         {\r
22                 super(processTime, in, out);\r
23 \r
24                 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
25                 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
26 \r
27                 connectedWireArraysModifiable.add(in);\r
28                 wireArrayConnectionPointsModifiable.add(new Point(0, 5));\r
29 \r
30                 connectedWireArraysModifiable.add(out);\r
31                 wireArrayConnectionPointsModifiable.add(new Point(20, 5));\r
32 \r
33                 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
34                 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\r
35         }\r
36 \r
37         @Override\r
38         public void render(GeneralGC gc)\r
39         {\r
40                 gc.drawRectangle(0, 0, 17, 10);\r
41                 Font oldFont = gc.getFont();\r
42                 Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());\r
43                 gc.setFont(labelFont);\r
44                 Point textExtent = gc.textExtent(LABEL);\r
45                 gc.drawText(LABEL, 8.5 - textExtent.x / 2, 5 - textExtent.y / 2, true);\r
46                 gc.setFont(oldFont);\r
47                 gc.drawOval(17, 3.5, 3, 3);\r
48         }\r
49 \r
50         @Override\r
51         public int getConnectedWireArraysCount()\r
52         {\r
53                 return connectedWireArrays.size();\r
54         }\r
55         @Override\r
56         public WireArray getConnectedWireArray(int connectionIndex)\r
57         {\r
58                 return connectedWireArrays.get(connectionIndex);\r
59         }\r
60         @Override\r
61         public Point getWireArrayConnectionPoint(int connectionI)\r
62         {\r
63                 return wireArrayConnectionPoints.get(connectionI);\r
64         }\r
65 }