From 26d5c3c4b6fa4d85f4aba3552a69da9c9c832d7f Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 15 May 2019 10:23:10 +0200 Subject: [PATCH] Implemented GUISplitter and GUIMerger --- LogicUI/src/LogicUI.java | 8 +-- .../src/era/mi/components/gui/GUIMerger.java | 69 +++++++++++++++++++ .../era/mi/components/gui/GUISplitter.java | 69 +++++++++++++++++++ 3 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 LogicUI/src/era/mi/components/gui/GUIMerger.java create mode 100644 LogicUI/src/era/mi/components/gui/GUISplitter.java diff --git a/LogicUI/src/LogicUI.java b/LogicUI/src/LogicUI.java index 070f3431..501f1933 100644 --- a/LogicUI/src/LogicUI.java +++ b/LogicUI/src/LogicUI.java @@ -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 index 00000000..0f4f2daf --- /dev/null +++ b/LogicUI/src/era/mi/components/gui/GUIMerger.java @@ -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 connectedWireArrays; + private final List wireArrayConnectionPoints; + + public GUIMerger(WireArray union, WireArray... inputs) + { + super(union, inputs); + + List connectedWireArraysModifiable = new ArrayList<>(); + List 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 index 00000000..67405bf5 --- /dev/null +++ b/LogicUI/src/era/mi/components/gui/GUISplitter.java @@ -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 connectedWireArrays; + private final List wireArrayConnectionPoints; + + public GUISplitter(WireArray input, WireArray... outputs) + { + super(input, outputs); + + List connectedWireArraysModifiable = new ArrayList<>(); + List 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 -- 2.17.1