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