24702fc8612d33ccb32372d927000632fa1179ee
[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.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
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<WireArray>   connectedWireArrays;\r
19         private final List<Point>               wireArrayConnectionPoints;\r
20 \r
21         public GUINotGate(int processTime, WireArray in, WireArray out)\r
22         {\r
23                 super(processTime, in, out);\r
24 \r
25                 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
26                 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
27 \r
28                 connectedWireArraysModifiable.add(in);\r
29                 wireArrayConnectionPointsModifiable.add(new Point(0, 5));\r
30 \r
31                 connectedWireArraysModifiable.add(out);\r
32                 wireArrayConnectionPointsModifiable.add(new Point(20, 5));\r
33 \r
34                 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
35                 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\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         @Override\r
44         public void render(GeneralGC gc)\r
45         {\r
46                 gc.drawRectangle(0, 0, 17, 10);\r
47                 Font oldFont = gc.getFont();\r
48                 Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());\r
49                 gc.setFont(labelFont);\r
50                 Point textExtent = gc.textExtent(LABEL);\r
51                 gc.drawText(LABEL, 8.5 - textExtent.x / 2, 5 - textExtent.y / 2, true);\r
52                 gc.setFont(oldFont);\r
53                 gc.drawOval(17, 3.5, 3, 3);\r
54         }\r
55 \r
56         @Override\r
57         public int getConnectedWireArraysCount()\r
58         {\r
59                 return connectedWireArrays.size();\r
60         }\r
61         @Override\r
62         public WireArray getConnectedWireArray(int connectionIndex)\r
63         {\r
64                 return connectedWireArrays.get(connectionIndex);\r
65         }\r
66         @Override\r
67         public Point getWireArrayConnectionPoint(int connectionI)\r
68         {\r
69                 return wireArrayConnectionPoints.get(connectionI);\r
70         }\r
71 }