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