c5c3ab790d6abd8a0f267fb13fad909e8b16c055
[Mograsim.git] / net.mograsim.logic.model.am2900 / test / net / mograsim / logic / model / am2900 / SwitchWithDisplay.java
1 package net.mograsim.logic.model.am2900;
2
3 import net.mograsim.logic.core.components.BitDisplay;
4 import net.mograsim.logic.core.components.ManualSwitch;
5 import net.mograsim.logic.core.types.BitVector;
6 import net.mograsim.logic.model.model.ViewModelModifiable;
7 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
8 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
9 import net.mograsim.logic.model.model.wires.Pin;
10 import net.mograsim.logic.model.model.wires.WireCrossPoint;
11 import net.mograsim.logic.model.util.ModellingTool;
12
13 public class SwitchWithDisplay
14 {
15         private final Pin pin;
16         private final GUIBitDisplay guiBitDisplay;
17         private final GUIManualSwitch guiManualSwitch;
18
19         public SwitchWithDisplay(ViewModelModifiable model, Pin target)
20         {
21                 pin = target;
22                 guiBitDisplay = new GUIBitDisplay(model, pin.logicWidth);
23                 guiManualSwitch = new GUIManualSwitch(model, pin.logicWidth);
24
25                 ModellingTool tool = ModellingTool.createFor(model);
26                 WireCrossPoint crossPoint = new WireCrossPoint(model, pin.logicWidth);
27                 tool.connect(guiBitDisplay.getInputPin(), crossPoint);
28                 tool.connect(guiManualSwitch.getOutputPin(), crossPoint);
29         }
30
31         public final BitVector getDisplayedValue()
32         {
33                 return guiBitDisplay.getBitDisplay().getDisplayedValue();
34         }
35
36         public final void setState(BitVector bits)
37         {
38                 guiManualSwitch.getManualSwitch().setState(bits);
39         }
40
41         public final Pin getPin()
42         {
43                 return pin;
44         }
45
46         public final BitDisplay getBitDisplay()
47         {
48                 return guiBitDisplay.getBitDisplay();
49         }
50
51         public final ManualSwitch getManualSwitch()
52         {
53                 return guiManualSwitch.getManualSwitch();
54         }
55
56         final GUIBitDisplay getGuiBitDisplay()
57         {
58                 return guiBitDisplay;
59         }
60
61         final GUIManualSwitch getGuiManualSwitch()
62         {
63                 return guiManualSwitch;
64         }
65 }