Merged SampleERCP into master
[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.WireArray;
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<WireArray> connectedWireArrays;
19         private final List<Point> wireArrayConnectionPoints;
20
21         public GUINotGate(int processTime, WireArray in, WireArray out)
22         {
23                 super(processTime, in, out);
24
25                 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
26                 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
27
28                 connectedWireArraysModifiable.add(in);
29                 wireArrayConnectionPointsModifiable.add(new Point(0, 5));
30
31                 connectedWireArraysModifiable.add(out);
32                 wireArrayConnectionPointsModifiable.add(new Point(20, 5));
33
34                 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
35                 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
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 getConnectedWireArraysCount()
59         {
60                 return connectedWireArrays.size();
61         }
62
63         @Override
64         public WireArray getConnectedWireArray(int connectionIndex)
65         {
66                 return connectedWireArrays.get(connectionIndex);
67         }
68
69         @Override
70         public Point getWireArrayConnectionPoint(int connectionI)
71         {
72                 return wireArrayConnectionPoints.get(connectionI);
73         }
74 }