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