Replaced "provider" in identifiers with "supplier"
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIdff.java
1 package net.mograsim.logic.ui.model.components.mi.nandbased;
2
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.ui.model.ViewModelModifiable;
5 import net.mograsim.logic.ui.model.components.atomic.GUINandGate;
6 import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
7 import net.mograsim.logic.ui.model.wires.GUIWire;
8 import net.mograsim.logic.ui.model.wires.Pin;
9 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
10 import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
11
12 public class GUIdff extends SimpleRectangularSubmodelComponent
13 {
14         private GUI_rsLatch _rsLatch;
15
16         public GUIdff(ViewModelModifiable model)
17         {
18                 super(model, 1, "GUIdff");
19                 setSubmodelScale(.2);
20                 setInputPins("C", "D");
21                 setOutputPins("Q", "_Q");
22                 initSubmodelComponents();
23         }
24
25         @SuppressWarnings("unused") // for GUIWires being created
26         private void initSubmodelComponents()
27         {
28                 Pin C = getSubmodelPin("C");
29                 Pin D = getSubmodelPin("D");
30                 Pin Q = getSubmodelPin("Q");
31                 Pin _Q = getSubmodelPin("_Q");
32
33                 GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable);
34                 GUInand3 nand3 = new GUInand3(submodelModifiable);
35                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
36                 GUI_rsLatch _rsLatch2 = this._rsLatch = new GUI_rsLatch(submodelModifiable);
37
38                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
39                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
40                 WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1);
41                 WireCrossPoint cp4 = new WireCrossPoint(submodelModifiable, 1);
42
43                 _rsLatch1.moveTo(40, 10);
44                 nand3.moveTo(40, 40);
45                 nand2.moveTo(120, 60);
46                 _rsLatch2.moveTo(120, 30);
47                 cp1.moveCenterTo(10, 25);
48                 cp2.moveCenterTo(20, 65);
49                 cp3.moveCenterTo(100, 35);
50                 cp4.moveCenterTo(100, 45);
51
52                 new GUIWire(submodelModifiable, C, cp1, new Point[0]);
53                 new GUIWire(submodelModifiable, cp1, _rsLatch1.getPin("_R"), new Point[0]);
54                 new GUIWire(submodelModifiable, cp1, nand3.getPin("B"), new Point(10, 55));
55                 new GUIWire(submodelModifiable, D, nand2.getPin("B"), new Point[0]);
56                 new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(145, 70), new Point(145, 85), new Point(20, 85));
57                 new GUIWire(submodelModifiable, cp2, _rsLatch1.getPin("_S"), new Point(20, 15));
58                 new GUIWire(submodelModifiable, cp2, nand3.getPin("C"), new Point[0]);
59                 new GUIWire(submodelModifiable, _rsLatch1.getPin("_Q"), cp3, new Point(100, 25));
60                 new GUIWire(submodelModifiable, cp3, nand3.getPin("A"), new Point(30, 35), new Point(30, 45));
61                 new GUIWire(submodelModifiable, cp3, _rsLatch2.getPin("_S"), new Point[0]);
62                 new GUIWire(submodelModifiable, nand3.getPin("Y"), cp4, new Point[0]);
63                 new GUIWire(submodelModifiable, cp4, _rsLatch2.getPin("_R"), new Point[0]);
64                 new GUIWire(submodelModifiable, cp4, nand2.getPin("A"), new Point(100, 65));
65                 new GUIWire(submodelModifiable, _rsLatch2.getPin("Q"), Q);
66                 new GUIWire(submodelModifiable, _rsLatch2.getPin("_Q"), _Q);
67
68                 addAtomicHighLevelStateID("q");
69         }
70
71         @Override
72         public void setAtomicHighLevelState(String stateID, Object newState)
73         {
74                 switch (stateID)
75                 {
76                 case "q":
77                         _rsLatch.setHighLevelState("q", newState);
78                         break;
79                 default:
80                         // should not happen because we tell SubmodelComponent to only allow these state IDs.
81                         throw new IllegalStateException("Illegal atomic state ID: " + stateID);
82                 }
83         }
84
85         @Override
86         public Object getAtomicHighLevelState(String stateID)
87         {
88                 switch (stateID)
89                 {
90                 case "q":
91                         return _rsLatch.getHighLevelState("q");
92                 default:
93                         // should not happen because we tell SubmodelComponent to only allow these state IDs.
94                         throw new IllegalStateException("Illegal atomic state ID: " + stateID);
95                 }
96         }
97
98         static
99         {
100                 IndirectGUIComponentCreator.setComponentSupplier(GUIdff.class.getCanonicalName(), (m, p) -> new GUIdff(m));
101         }
102 }