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