Renamed project folders to match the respective project name
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / wires / WireCrossPoint.java
1 package net.mograsim.logic.ui.model.wires;
2
3 import net.mograsim.logic.ui.ColorHelper;
4 import net.mograsim.logic.ui.model.ViewModel;
5 import net.mograsim.logic.ui.model.components.GUIComponent;
6 import net.haspamelodica.swt.helper.gcs.GeneralGC;
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
8 import net.mograsim.logic.core.types.BitVectorFormatter;
9 import net.mograsim.logic.core.wires.Wire.ReadEnd;
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 }