04c5f1e8406cc3ef892f693e37d740478de08e5f
[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                 Rectangle bounds = getBounds();
30                 ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end),
31                                 () -> gc.fillOval(bounds.x - 1, bounds.y - 1, 2, 2));
32         }
33
34         public void setLogicModelBinding(ReadEnd end)
35         {
36                 this.end = end;
37                 end.addObserver((i, o) -> callComponentLookChangedListeners());
38         }
39
40         public int getLogicWidth()
41         {
42                 return logicWidth;
43         }
44
45         public Pin getPin()
46         {
47                 return pin;
48         }
49 }