Timeline now passed via constructor
[Mograsim.git] / LogicUI / src / era / mi / gui / components / GUINotGate.java
1 package era.mi.gui.components;\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.timeline.Timeline;\r
9 import era.mi.logic.wires.Wire.ReadEnd;\r
10 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
11 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
12 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;\r
13 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
14 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;\r
15 \r
16 public class GUINotGate extends NotGate implements BasicGUIComponent\r
17 {\r
18         private static final String LABEL = "\u22651";// >=1\r
19 \r
20         private final List<ReadEnd> connectedWireEnds;\r
21         private final List<Point> WireEndConnectionPoints;\r
22 \r
23         public GUINotGate(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out)\r
24         {\r
25                 super(timeline, processTime, in, out);\r
26 \r
27                 List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
28                 List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
29 \r
30                 connectedWireEndsModifiable.add(in);\r
31                 WireEndConnectionPointsModifiable.add(new Point(0, 5));\r
32 \r
33                 connectedWireEndsModifiable.add(out);\r
34                 WireEndConnectionPointsModifiable.add(new Point(20, 5));\r
35 \r
36                 this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);\r
37                 this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);\r
38         }\r
39 \r
40         @Override\r
41         public Rectangle getBounds()\r
42         {\r
43                 return new Rectangle(0, 0, 20, 10);\r
44         }\r
45 \r
46         @Override\r
47         public void render(GeneralGC gc)\r
48         {\r
49                 gc.drawRectangle(0, 0, 17, 10);\r
50                 Font oldFont = gc.getFont();\r
51                 Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());\r
52                 gc.setFont(labelFont);\r
53                 Point textExtent = gc.textExtent(LABEL);\r
54                 gc.drawText(LABEL, 8.5 - textExtent.x / 2, 5 - textExtent.y / 2, true);\r
55                 gc.setFont(oldFont);\r
56                 gc.drawOval(17, 3.5, 3, 3);\r
57         }\r
58 \r
59         @Override\r
60         public int getConnectedWireEndsCount()\r
61         {\r
62                 return connectedWireEnds.size();\r
63         }\r
64 \r
65         @Override\r
66         public ReadEnd getConnectedWireEnd(int connectionIndex)\r
67         {\r
68                 return connectedWireEnds.get(connectionIndex);\r
69         }\r
70 \r
71         @Override\r
72         public Point getWireEndConnectionPoint(int connectionI)\r
73         {\r
74                 return WireEndConnectionPoints.get(connectionI);\r
75         }\r
76 }