Common ConnectionPoint interface to simplify many things
authorChristian Femers <femers@in.tum.de>
Fri, 28 Jun 2019 17:22:57 +0000 (19:22 +0200)
committerChristian Femers <femers@in.tum.de>
Fri, 28 Jun 2019 17:22:57 +0000 (19:22 +0200)
Simplifies the GUIWire's constructors and allows to loop to create wire
connections.

net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/ConnectionPoint.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java

diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/ConnectionPoint.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/ConnectionPoint.java
new file mode 100644 (file)
index 0000000..ed10286
--- /dev/null
@@ -0,0 +1,13 @@
+package net.mograsim.logic.ui.model.wires;
+
+public interface ConnectionPoint
+{
+       /**
+        * Retrieves the {@link Pin}, that is used by the {@link GUIWire} to connect to.
+        * 
+        * @return the {@link Pin} for the wire to connect to.
+        * 
+        * @author Christian Femers
+        */
+       Pin getPin();
+}
index 33be875..5a0579c 100644 (file)
@@ -73,37 +73,7 @@ public class GUIWire
         * 
         * @author Daniel Kirschten
         */
-       public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2)
-       {
-               this(model, pin1, pin2, (Point[]) null);
-       }
-
-       /**
-        * Creates a new {@link GUIWire} with automatic interpolation.
-        * 
-        * @author Daniel Kirschten
-        */
-       public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2)
-       {
-               this(model, pin1, pin2, (Point[]) null);
-       }
-
-       /**
-        * Creates a new {@link GUIWire} with automatic interpolation.
-        * 
-        * @author Daniel Kirschten
-        */
-       public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2)
-       {
-               this(model, pin1, pin2, (Point[]) null);
-       }
-
-       /**
-        * Creates a new {@link GUIWire} with automatic interpolation.
-        * 
-        * @author Daniel Kirschten
-        */
-       public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2)
+       public GUIWire(ViewModelModifiable model, ConnectionPoint pin1, ConnectionPoint pin2)
        {
                this(model, pin1, pin2, (Point[]) null);
        }
@@ -113,7 +83,7 @@ public class GUIWire
         * 
         * @author Daniel Kirschten
         */
-       public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2, Point... path)
+       public GUIWire(ViewModelModifiable model, ConnectionPoint pin1, ConnectionPoint pin2, Point... path)
        {
                this(model, pin1.getPin(), pin2.getPin(), path);
        }
@@ -123,27 +93,7 @@ public class GUIWire
         * 
         * @author Daniel Kirschten
         */
-       public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2, Point... path)
-       {
-               this(model, pin1.getPin(), pin2, path);
-       }
-
-       /**
-        * Creates a new {@link GUIWire} without automatic interpolation.
-        * 
-        * @author Daniel Kirschten
-        */
-       public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2, Point... path)
-       {
-               this(model, pin1, pin2.getPin(), path);
-       }
-
-       /**
-        * Creates a new {@link GUIWire} without automatic interpolation.
-        * 
-        * @author Daniel Kirschten
-        */
-       public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path)
+       GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path)
        {
                logicObs = (i) -> callRedrawListeners();
                this.model = model;
index 287a623..b761c0e 100644 (file)
@@ -15,7 +15,7 @@ import net.mograsim.logic.ui.model.components.GUIComponent;
  * 
  * @author Daniel Kirschten
  */
-public class Pin
+public class Pin implements ConnectionPoint
 {
        /**
         * The {@link GUIComponent} this pin belongs to
@@ -136,4 +136,10 @@ public class Pin
        {
                return "Pin [" + name + ", point=" + getPos() + "]";
        }
+
+       @Override
+       public Pin getPin()
+       {
+               return this;
+       }
 }
\ No newline at end of file
index de5ba4a..07bddc6 100644 (file)
@@ -21,7 +21,7 @@ import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate;
  * 
  * @author Daniel Kirschten
  */
-public class WireCrossPoint extends GUIComponent
+public class WireCrossPoint extends GUIComponent implements ConnectionPoint
 {
        private static final int CIRCLE_RADIUS = 1;
        private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2;
@@ -53,6 +53,7 @@ public class WireCrossPoint extends GUIComponent
 
        // pins
 
+       @Override
        public Pin getPin()
        {
                return pin;