Removed unneccessary "this."
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / model / components / mi / nandbased / GUIdlatch.java
1 package net.mograsim.logic.model.model.components.mi.nandbased;
2
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.model.model.ViewModelModifiable;
5 import net.mograsim.logic.model.model.components.atomic.GUINandGate;
6 import net.mograsim.logic.model.model.components.submodels.SimpleRectangularSubmodelComponent;
7 import net.mograsim.logic.model.model.wires.GUIWire;
8 import net.mograsim.logic.model.model.wires.Pin;
9 import net.mograsim.logic.model.model.wires.WireCrossPoint;
10 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
11 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandler;
12 import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.DelegatingAtomicHighLevelStateHandler;
13
14 public class GUIdlatch extends SimpleRectangularSubmodelComponent
15 {
16         private StandardHighLevelStateHandler highLevelStateHandler;
17
18         public GUIdlatch(ViewModelModifiable model)
19         {
20                 this(model, null);
21         }
22
23         public GUIdlatch(ViewModelModifiable model, String name)
24         {
25                 super(model, 1, "GUIdlatch", name);
26                 setSubmodelScale(.4);
27                 setInputPins("D", "E");
28                 setOutputPins("Q", "_Q");
29                 initSubmodelComponents();
30         }
31
32         @SuppressWarnings("unused") // for GUIWires being created
33         private void initSubmodelComponents()
34         {
35                 Pin D = getSubmodelPin("D");
36                 Pin E = getSubmodelPin("E");
37                 Pin Q = getSubmodelPin("Q");
38                 Pin _Q = getSubmodelPin("_Q");
39
40                 GUINandGate nand1 = new GUINandGate(submodelModifiable, 1);
41                 GUINandGate nand2 = new GUINandGate(submodelModifiable, 1);
42                 GUI_rsLatch _rsLatch = new GUI_rsLatch(submodelModifiable);
43
44                 WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1);
45                 WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1);
46
47                 nand1.moveTo(10, 2.5);
48                 nand2.moveTo(15, 27.5);
49                 _rsLatch.moveTo(45, 7.5);
50                 cp1.moveCenterTo(5, 37.5);
51                 cp2.moveCenterTo(35, 12.5);
52
53                 new GUIWire(submodelModifiable, D, nand1.getPin("A"));
54                 new GUIWire(submodelModifiable, E, cp1, new Point[0]);
55                 new GUIWire(submodelModifiable, cp1, nand1.getPin("B"), new Point(5, 17.5));
56                 new GUIWire(submodelModifiable, cp1, nand2.getPin("B"), new Point(5, 42.5));
57                 new GUIWire(submodelModifiable, nand1.getPin("Y"), cp2, new Point[0]);
58                 new GUIWire(submodelModifiable, cp2, nand2.getPin("A"), new Point(35, 25), new Point(10, 25), new Point(10, 32.5));
59                 new GUIWire(submodelModifiable, cp2, _rsLatch.getPin("_S"), new Point[0]);
60                 new GUIWire(submodelModifiable, nand2.getPin("Y"), _rsLatch.getPin("_R"), new Point(40, 37.5), new Point(40, 22.5));
61                 new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]);
62                 new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q);
63
64                 highLevelStateHandler = new StandardHighLevelStateHandler(this);
65                 highLevelStateHandler.addAtomicHighLevelState("q", DelegatingAtomicHighLevelStateHandler::new).set(_rsLatch, "q");
66         }
67
68         @Override
69         public Object getHighLevelState(String stateID)
70         {
71                 return highLevelStateHandler.getHighLevelState(stateID);
72         }
73
74         @Override
75         public void setHighLevelState(String stateID, Object newState)
76         {
77                 highLevelStateHandler.setHighLevelState(stateID, newState);
78         }
79
80         static
81         {
82                 IndirectGUIComponentCreator.setComponentSupplier(GUIdlatch.class.getCanonicalName(), (m, p, n) -> new GUIdlatch(m, n));
83         }
84 }