4ab4c440edd7e5a88a036f9ed59a71dc963e13ce
[Mograsim.git] / LogicUI / src / era / mi / components / gui / GUINotGate.java
1 package era.mi.components.gui;
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
13 public class GUINotGate extends NotGate implements BasicGUIComponent
14 {
15         private static final String LABEL = "\u22651";//>=1
16
17         private final List<WireArray>   connectedWireArrays;
18         private final List<Point>               wireArrayConnectionPoints;
19
20         public GUINotGate(int processTime, WireArray in, WireArray out)
21         {
22                 super(processTime, in, out);
23
24                 List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
25                 List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
26
27                 connectedWireArraysModifiable.add(in);
28                 wireArrayConnectionPointsModifiable.add(new Point(0, 5));
29
30                 connectedWireArraysModifiable.add(out);
31                 wireArrayConnectionPointsModifiable.add(new Point(20, 5));
32
33                 this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
34                 this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
35         }
36
37         @Override
38         public void render(GeneralGC gc)
39         {
40                 gc.drawRectangle(0, 0, 17, 10);
41                 Font oldFont = gc.getFont();
42                 Font labelFont = new Font(oldFont.getName(), 5, oldFont.getStyle());
43                 gc.setFont(labelFont);
44                 Point textExtent = gc.textExtent(LABEL);
45                 gc.drawText(LABEL, 8.5 - textExtent.x / 2, 5 - textExtent.y / 2, true);
46                 gc.setFont(oldFont);
47                 gc.drawOval(17, 3.5, 3, 3);
48         }
49
50         @Override
51         public int getConnectedWireArraysCount()
52         {
53                 return connectedWireArrays.size();
54         }
55         @Override
56         public WireArray getConnectedWireArray(int connectionIndex)
57         {
58                 return connectedWireArrays.get(connectionIndex);
59         }
60         @Override
61         public Point getWireArrayConnectionPoint(int connectionI)
62         {
63                 return wireArrayConnectionPoints.get(connectionI);
64         }
65 }