1 package net.mograsim.logic.ui.model.wires;
5 import net.haspamelodica.swt.helper.gcs.GeneralGC;
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
7 import net.mograsim.logic.core.LogicObservable;
8 import net.mograsim.logic.core.LogicObserver;
9 import net.mograsim.logic.core.types.BitVectorFormatter;
10 import net.mograsim.logic.core.wires.Wire.ReadEnd;
11 import net.mograsim.logic.ui.ColorHelper;
12 import net.mograsim.logic.ui.model.ViewModelModifiable;
13 import net.mograsim.logic.ui.model.components.GUIComponent;
14 import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate;
16 public class WireCrossPoint extends GUIComponent
18 private static final int CIRCLE_RADIUS = 1;
19 private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2;
21 private final Pin pin;
22 private final int logicWidth;
24 private final LogicObserver logicObs;
27 public WireCrossPoint(ViewModelModifiable model, int logicWidth)
30 logicObs = (i) -> requestRedraw();
32 this.logicWidth = logicWidth;
33 setSize(CIRCLE_DIAM, CIRCLE_DIAM);
34 addPin(this.pin = new Pin(this, "", logicWidth, CIRCLE_RADIUS, CIRCLE_RADIUS));
37 public void moveCenterTo(double x, double y)
39 moveTo(x - CIRCLE_RADIUS, y - CIRCLE_RADIUS);
43 public void render(GeneralGC gc, Rectangle visibleRegion)
45 Rectangle bounds = getBounds();
46 ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end),
47 () -> gc.fillOval(bounds.x, bounds.y, CIRCLE_DIAM, CIRCLE_DIAM));
50 public void setLogicModelBinding(ReadEnd end)
52 deregisterLogicObs(this.end);
54 registerLogicObs(end);
57 private void registerLogicObs(LogicObservable observable)
59 if (observable != null)
60 observable.registerObserver(logicObs);
63 private void deregisterLogicObs(LogicObservable observable)
65 if (observable != null)
66 observable.deregisterObserver(logicObs);
69 public int getLogicWidth()
80 public Map<String, Object> getInstantiationParameters()
82 Map<String, Object> m = super.getInstantiationParameters();
83 m.put(SimpleRectangularGUIGate.kLogicWidth, logicWidth);