Logic model binding of WireCrossPoints is now being set
[Mograsim.git] / LogicUI / src / era / mi / gui / model / wires / WireCrossPoint.java
1 package era.mi.gui.model.wires;
2
3 import era.mi.gui.ColorHelper;
4 import era.mi.gui.model.ViewModel;
5 import era.mi.gui.model.components.GUIComponent;
6 import era.mi.logic.types.BitVectorFormatter;
7 import era.mi.logic.wires.Wire.ReadEnd;
8 import net.haspamelodica.swt.helper.gcs.GeneralGC;
9 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
10
11 public class WireCrossPoint extends GUIComponent
12 {
13         private final Pin pin;
14
15         private ReadEnd end;
16         private final int logicWidth;
17
18         public WireCrossPoint(ViewModel model, int logicWidth)
19         {
20                 super(model);
21                 this.logicWidth = logicWidth;
22                 setSize(0, 0);
23                 addPin(this.pin = new Pin(this, logicWidth, 0, 0));
24         }
25
26         @Override
27         public void render(GeneralGC gc, Rectangle visibleRegion)
28         {
29                 ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), () -> gc.fillOval(-1, -1, 2, 2));
30         }
31
32         public void setLogicModelBinding(ReadEnd end)
33         {
34                 this.end = end;
35                 end.addObserver((i, o) -> callComponentLookChangedListeners());
36         }
37
38         public int getLogicWidth()
39         {
40                 return logicWidth;
41         }
42
43         public Pin getPin()
44         {
45                 return pin;
46         }
47 }