Implemented GUISplitter and GUIMerger
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 08:23:10 +0000 (10:23 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 15 May 2019 08:23:10 +0000 (10:23 +0200)
LogicUI/src/LogicUI.java
LogicUI/src/era/mi/components/gui/GUIMerger.java [new file with mode: 0644]
LogicUI/src/era/mi/components/gui/GUISplitter.java [new file with mode: 0644]

index 070f343..501f193 100644 (file)
@@ -9,10 +9,10 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 
 import era.mi.components.gui.BasicGUIComponent;
+import era.mi.components.gui.GUIMerger;
 import era.mi.components.gui.GUIMux;
+import era.mi.components.gui.GUISplitter;
 import era.mi.logic.Simulation;
-import era.mi.logic.components.Merger;
-import era.mi.logic.components.Splitter;
 import era.mi.logic.components.gates.AndGate;
 import era.mi.logic.components.gates.NotGate;
 import era.mi.logic.wires.WireArray;
@@ -52,9 +52,9 @@ public class LogicUI
                                f = new WireArray(1, 1), g = new WireArray(1, 1), h = new WireArray(2, 1), i = new WireArray(2, 1), j = new WireArray(1, 1), k = new WireArray(1, 1);
                new AndGate(1, f, a, b);
                new NotGate(1, f, g);
-               new Merger(h, c, g);
+               addComponent(new GUIMerger(h, c, g), 70, 10);
                addComponent(new GUIMux(1, i, e, h, d), 10, 10);
-               new Splitter(i, k, j);
+               addComponent(new GUISplitter(i, k, j), 40, 10);
        }
        private void addComponent(BasicGUIComponent component, double x, double y)
        {
diff --git a/LogicUI/src/era/mi/components/gui/GUIMerger.java b/LogicUI/src/era/mi/components/gui/GUIMerger.java
new file mode 100644 (file)
index 0000000..0f4f2da
--- /dev/null
@@ -0,0 +1,69 @@
+package era.mi.components.gui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import era.mi.logic.components.Merger;
+import era.mi.logic.wires.WireArray;
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+
+public class GUIMerger extends Merger implements BasicGUIComponent
+{
+       private final int                               inputCount;
+       private final double                    height;
+       private final List<WireArray>   connectedWireArrays;
+       private final List<Point>               wireArrayConnectionPoints;
+
+       public GUIMerger(WireArray union, WireArray... inputs)
+       {
+               super(union, inputs);
+
+               List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
+               List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
+
+               this.inputCount = inputs.length;
+               this.height = (inputCount - 1) * 10;
+
+               {
+                       connectedWireArraysModifiable.addAll(Arrays.asList(inputs));
+                       double inputHeight = 0;
+                       for(int i = 0; i < inputCount; i ++, inputHeight += 10)
+                               wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));
+               }
+
+               connectedWireArraysModifiable.add(union);
+               wireArrayConnectionPointsModifiable.add(new Point(20, height / 2));
+
+               this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
+               this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
+       }
+
+       @Override
+       public void render(GeneralGC gc)
+       {
+               double inputHeight = 0;
+               for(int i = 0; i < inputCount; i ++, inputHeight += 10)
+                       gc.drawLine(0, inputHeight, 10, inputHeight);
+               gc.drawLine(10, 0, 10, height);
+               gc.drawLine(10, height / 2, 20, height / 2);
+       }
+
+       @Override
+       public int getConnectedWireArraysCount()
+       {
+               return connectedWireArrays.size();
+       }
+       @Override
+       public WireArray getConnectedWireArray(int connectionIndex)
+       {
+               return connectedWireArrays.get(connectionIndex);
+       }
+       @Override
+       public Point getWireArrayConnectionPoint(int connectionI)
+       {
+               return wireArrayConnectionPoints.get(connectionI);
+       }
+}
\ No newline at end of file
diff --git a/LogicUI/src/era/mi/components/gui/GUISplitter.java b/LogicUI/src/era/mi/components/gui/GUISplitter.java
new file mode 100644 (file)
index 0000000..67405bf
--- /dev/null
@@ -0,0 +1,69 @@
+package era.mi.components.gui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import era.mi.logic.components.Splitter;
+import era.mi.logic.wires.WireArray;
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+
+public class GUISplitter extends Splitter implements BasicGUIComponent
+{
+       private final int                               outputCount;
+       private final double                    height;
+       private final List<WireArray>   connectedWireArrays;
+       private final List<Point>               wireArrayConnectionPoints;
+
+       public GUISplitter(WireArray input, WireArray... outputs)
+       {
+               super(input, outputs);
+
+               List<WireArray> connectedWireArraysModifiable = new ArrayList<>();
+               List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();
+
+               this.outputCount = outputs.length;
+               this.height = (outputCount - 1) * 10;
+
+               connectedWireArraysModifiable.add(input);
+               wireArrayConnectionPointsModifiable.add(new Point(0, height / 2));
+
+               {
+                       connectedWireArraysModifiable.addAll(Arrays.asList(outputs));
+                       double outputHeight = 0;
+                       for(int i = 0; i < outputCount; i ++, outputHeight += 10)
+                               wireArrayConnectionPointsModifiable.add(new Point(20, outputHeight));
+               }
+
+               this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);
+               this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);
+       }
+
+       @Override
+       public void render(GeneralGC gc)
+       {
+               gc.drawLine(0, height / 2, 10, height / 2);
+               gc.drawLine(10, 0, 10, height);
+               double outputHeight = 0;
+               for(int i = 0; i < outputCount; i ++, outputHeight += 10)
+                       gc.drawLine(10, outputHeight, 20, outputHeight);
+       }
+
+       @Override
+       public int getConnectedWireArraysCount()
+       {
+               return connectedWireArrays.size();
+       }
+       @Override
+       public WireArray getConnectedWireArray(int connectionIndex)
+       {
+               return connectedWireArrays.get(connectionIndex);
+       }
+       @Override
+       public Point getWireArrayConnectionPoint(int connectionI)
+       {
+               return wireArrayConnectionPoints.get(connectionI);
+       }
+}
\ No newline at end of file