Pins now have names
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / AtomicAm2901NANDBased.java
1 package net.mograsim.logic.ui.model.components;
2
3 import java.util.List;
4
5 import net.haspamelodica.swt.helper.gcs.GeneralGC;
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
9 import net.mograsim.logic.ui.model.ViewModelModifiable;
10 import net.mograsim.logic.ui.model.wires.Pin;
11
12 public class AtomicAm2901NANDBased extends GUIComponent
13 {
14         public final List<String> inputNames;
15         public final List<String> outputNames;
16
17         public AtomicAm2901NANDBased(ViewModelModifiable model)
18         {
19                 super(model);
20
21                 this.inputNames = List.of("I8", "I7", "I6", "I5", "I4", "I3", "I2", "I1", "I0", "C", "Cn", "D1", "D2", "D3", "D4", "A0", "A1", "A2",
22                                 "A3", "B0", "B1", "B2", "B3", "IRAMn", "IRAMn+3", "IQn", "IQn+3");
23                 this.outputNames = List.of("Y1", "Y2", "Y3", "Y4", "F=0", "Cn+4", "OVR", "F3_ORAMn+3", "ORAMn", "OQn", "OQn+3");
24                 setSize(50, inputNames.size() * 10);
25                 for (int i = 0; i < inputNames.size(); i++)
26                         addPin(new Pin(this, "Input pin #" + i, 1, 0, 5 + 10 * i));
27                 for (int i = 0; i < outputNames.size(); i++)
28                         addPin(new Pin(this, "Output pin #" + i, 1, 50, 5 + 10 * i));
29         }
30
31         @Override
32         public void render(GeneralGC gc, Rectangle visibleRegion)
33         {
34                 double posX = getBounds().x;
35                 double posY = getBounds().y;
36
37                 gc.drawRectangle(getBounds());
38                 Font oldFont = gc.getFont();
39                 Font labelFont = new Font(oldFont.getName(), 4, oldFont.getStyle());
40                 gc.setFont(labelFont);
41                 for (int i = 0; i < inputNames.size(); i++)
42                 {
43                         Point textExtent = gc.textExtent(inputNames.get(i));
44                         gc.drawText(inputNames.get(i), posX, posY + 5 + 10 * i - textExtent.y / 2, true);
45                 }
46                 for (int i = 0; i < outputNames.size(); i++)
47                 {
48                         Point textExtent = gc.textExtent(outputNames.get(i));
49                         gc.drawText(outputNames.get(i), posX + 50 - textExtent.x, posY + 5 + 10 * i - textExtent.y / 2, true);
50                 }
51                 gc.setFont(oldFont);
52         }
53 }