Suppressed warnings where the thing warned about is intentional
[Mograsim.git] / LogicUI / src / era / mi / gui / model / wires / Pin.java
index 1ab7404..abafc07 100644 (file)
@@ -1,5 +1,9 @@
 package era.mi.gui.model.wires;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
 import era.mi.gui.model.components.GUIComponent;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
@@ -7,14 +11,23 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 public class Pin
 {
        public final GUIComponent component;
+       public final int logicWidth;
+
        protected double relX;
        protected double relY;
 
-       public Pin(GUIComponent component, double relX, double relY)
+       private final List<Consumer<? super Pin>> pinMovedListeners;
+
+       public Pin(GUIComponent component, int logicWidth, double relX, double relY)
        {
                this.component = component;
+               this.logicWidth = logicWidth;
                this.relX = relX;
                this.relY = relY;
+
+               this.pinMovedListeners = new ArrayList<>();
+
+               component.addComponentMovedListener(c -> callPinMovedListeners());
        }
 
        public double getRelX()
@@ -38,9 +51,18 @@ public class Pin
                return new Point(relX + componentBounds.x, relY + componentBounds.y);
        }
 
+       // @formatter:off
+       public void addPinMovedListener   (Consumer<? super Pin> listener){pinMovedListeners.add   (listener);}
+
+       public void removePinMovedListener(Consumer<? super Pin> listener){pinMovedListeners.remove(listener);}
+
+       private void callPinMovedListeners() {pinMovedListeners.forEach(l -> l.accept(this));}
+       // @formatter:on
+
        protected void setRelPos(double relX, double relY)
        {
                this.relX = relX;
                this.relY = relY;
+               callPinMovedListeners();
        }
 }
\ No newline at end of file