From: Daniel Kirschten Date: Mon, 20 May 2019 19:21:26 +0000 (+0200) Subject: Adjusted LogicUI to new Wire / WireEnd concept X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=4be7eddcfc45e5e5794bd0dc1e2c2423fa43ec51;p=Mograsim.git Adjusted LogicUI to new Wire / WireEnd concept --- diff --git a/LogicUI/src/era/mi/gui/components/BasicGUIComponent.java b/LogicUI/src/era/mi/gui/components/BasicGUIComponent.java index fa753e18..b8094a93 100644 --- a/LogicUI/src/era/mi/gui/components/BasicGUIComponent.java +++ b/LogicUI/src/era/mi/gui/components/BasicGUIComponent.java @@ -1,6 +1,6 @@ package era.mi.gui.components; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; @@ -30,15 +30,15 @@ public interface BasicGUIComponent * Returns how many wire arrays are connected to this component. (Connections are static - they can't be removed and no new ones can be * added) */ - public int getConnectedWireArraysCount(); + public int getConnectedWireEndsCount(); /** * Returns the n-th wire array connected to this component. */ - public WireArray getConnectedWireArray(int connectionIndex); + public WireEnd getConnectedWireEnd(int connectionIndex); /** * Returns relative coordinates where the n-th wire array is connected to this component. */ - public Point getWireArrayConnectionPoint(int connectionIndex); + public Point getWireEndConnectionPoint(int connectionIndex); } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUIAndGate.java b/LogicUI/src/era/mi/gui/components/GUIAndGate.java index fa51232b..abc80ff9 100644 --- a/LogicUI/src/era/mi/gui/components/GUIAndGate.java +++ b/LogicUI/src/era/mi/gui/components/GUIAndGate.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.gates.AndGate; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; @@ -18,31 +18,31 @@ public class GUIAndGate extends AndGate implements BasicGUIComponent private final int inputCount; private final double height; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List wireEndConnectionPoints; - public GUIAndGate(int processTime, WireArray out, WireArray... in) + public GUIAndGate(int processTime, WireEnd out, WireEnd... in) { super(processTime, out, in); - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List wireEndConnectionPointsModifiable = new ArrayList<>(); this.inputCount = in.length; this.height = inputCount * 10; { - connectedWireArraysModifiable.addAll(Arrays.asList(in)); + connectedWireEndsModifiable.addAll(Arrays.asList(in)); double inputHeight = 5; for (int i = 0; i < inputCount; i++, inputHeight += 10) - wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + wireEndConnectionPointsModifiable.add(new Point(0, inputHeight)); } - connectedWireArraysModifiable.add(out); - wireArrayConnectionPointsModifiable.add(new Point(20, height / 2)); + connectedWireEndsModifiable.add(out); + wireEndConnectionPointsModifiable.add(new Point(20, height / 2)); - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.wireEndConnectionPoints = Collections.unmodifiableList(wireEndConnectionPointsModifiable); } @Override @@ -64,20 +64,20 @@ public class GUIAndGate extends AndGate implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return wireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java b/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java index c3100ffb..09e243a7 100644 --- a/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java +++ b/LogicUI/src/era/mi/gui/components/GUIManualSwitch.java @@ -6,9 +6,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import era.mi.logic.Bit; import era.mi.logic.components.ManualSwitch; -import era.mi.logic.wires.WireArray; +import era.mi.logic.types.Bit; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; @@ -28,24 +28,24 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent bitNames = Collections.unmodifiableMap(bitNamesModifiable); } - private final WireArray wa; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final WireEnd we; + private final List connectedWireEnds; + private final List wireEndConnectionPoints; - public GUIManualSwitch(WireArray output) + public GUIManualSwitch(WireEnd output) { super(output); - this.wa = output; + this.we = output; - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List wireEndConnectionPointsModifiable = new ArrayList<>(); - connectedWireArraysModifiable.add(output); - wireArrayConnectionPointsModifiable.add(new Point(20, 7.5)); + connectedWireEndsModifiable.add(output); + wireEndConnectionPointsModifiable.add(new Point(20, 7.5)); - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.wireEndConnectionPoints = Collections.unmodifiableList(wireEndConnectionPointsModifiable); } @Override @@ -58,7 +58,7 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent public void render(GeneralGC gc) { gc.drawRectangle(0, 0, 20, 15); - String label = bitNames.get(wa.getValue()); + String label = bitNames.get(we.getValue()); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle()); gc.setFont(labelFont); @@ -75,20 +75,20 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return wireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUIMerger.java b/LogicUI/src/era/mi/gui/components/GUIMerger.java index dd15f173..fed303ba 100644 --- a/LogicUI/src/era/mi/gui/components/GUIMerger.java +++ b/LogicUI/src/era/mi/gui/components/GUIMerger.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.Merger; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; @@ -15,31 +15,31 @@ public class GUIMerger extends Merger implements BasicGUIComponent { private final int inputCount; private final double height; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List WireEndConnectionPoints; - public GUIMerger(WireArray union, WireArray... inputs) + public GUIMerger(WireEnd union, WireEnd... inputs) { super(union, inputs); - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List WireEndConnectionPointsModifiable = new ArrayList<>(); this.inputCount = inputs.length; this.height = (inputCount - 1) * 10; { - connectedWireArraysModifiable.addAll(Arrays.asList(inputs)); + connectedWireEndsModifiable.addAll(Arrays.asList(inputs)); double inputHeight = 0; for (int i = 0; i < inputCount; i++, inputHeight += 10) - wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + WireEndConnectionPointsModifiable.add(new Point(0, inputHeight)); } - connectedWireArraysModifiable.add(union); - wireArrayConnectionPointsModifiable.add(new Point(20, height / 2)); + connectedWireEndsModifiable.add(union); + WireEndConnectionPointsModifiable.add(new Point(20, height / 2)); - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable); } @Override @@ -59,20 +59,20 @@ public class GUIMerger extends Merger implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return WireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUIMux.java b/LogicUI/src/era/mi/gui/components/GUIMux.java index 88ccbd73..c16aa316 100644 --- a/LogicUI/src/era/mi/gui/components/GUIMux.java +++ b/LogicUI/src/era/mi/gui/components/GUIMux.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.Mux; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; @@ -14,10 +14,10 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; public class GUIMux extends Mux implements BasicGUIComponent { private final double height; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List WireEndConnectionPoints; - public GUIMux(int processTime, WireArray out, WireArray select, WireArray... inputs) + public GUIMux(int processTime, WireEnd out, WireEnd select, WireEnd... inputs) { super(processTime, out, select, inputs); @@ -26,25 +26,25 @@ public class GUIMux extends Mux implements BasicGUIComponent height = 10; this.height = height; - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List WireEndConnectionPointsModifiable = new ArrayList<>(); - connectedWireArraysModifiable.add(out); - wireArrayConnectionPointsModifiable.add(new Point(20, 10 + height / 2)); + connectedWireEndsModifiable.add(out); + WireEndConnectionPointsModifiable.add(new Point(20, 10 + height / 2)); - connectedWireArraysModifiable.add(select); - wireArrayConnectionPointsModifiable.add(new Point(10, 5)); + connectedWireEndsModifiable.add(select); + WireEndConnectionPointsModifiable.add(new Point(10, 5)); { - connectedWireArraysModifiable.addAll(Arrays.asList(inputs)); + connectedWireEndsModifiable.addAll(Arrays.asList(inputs)); double inputHeightIncrement = (height + 20) / inputs.length; double inputHeight = inputHeightIncrement / 2; for (int i = 0; i < inputs.length; i++, inputHeight += inputHeightIncrement) - wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + WireEndConnectionPointsModifiable.add(new Point(0, inputHeight)); } - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable); } @Override @@ -60,20 +60,20 @@ public class GUIMux extends Mux implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return WireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUINotGate.java b/LogicUI/src/era/mi/gui/components/GUINotGate.java index 11f80b83..24416ada 100644 --- a/LogicUI/src/era/mi/gui/components/GUINotGate.java +++ b/LogicUI/src/era/mi/gui/components/GUINotGate.java @@ -5,7 +5,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.gates.NotGate; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; @@ -15,24 +15,24 @@ public class GUINotGate extends NotGate implements BasicGUIComponent { private static final String LABEL = "\u22651";// >=1 - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List WireEndConnectionPoints; - public GUINotGate(int processTime, WireArray in, WireArray out) + public GUINotGate(int processTime, WireEnd in, WireEnd out) { super(processTime, in, out); - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List WireEndConnectionPointsModifiable = new ArrayList<>(); - connectedWireArraysModifiable.add(in); - wireArrayConnectionPointsModifiable.add(new Point(0, 5)); + connectedWireEndsModifiable.add(in); + WireEndConnectionPointsModifiable.add(new Point(0, 5)); - connectedWireArraysModifiable.add(out); - wireArrayConnectionPointsModifiable.add(new Point(20, 5)); + connectedWireEndsModifiable.add(out); + WireEndConnectionPointsModifiable.add(new Point(20, 5)); - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable); } @Override @@ -55,20 +55,20 @@ public class GUINotGate extends NotGate implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return WireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUIOrGate.java b/LogicUI/src/era/mi/gui/components/GUIOrGate.java index 1b37b100..9d2b71d2 100644 --- a/LogicUI/src/era/mi/gui/components/GUIOrGate.java +++ b/LogicUI/src/era/mi/gui/components/GUIOrGate.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.gates.OrGate; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; @@ -18,31 +18,31 @@ public class GUIOrGate extends OrGate implements BasicGUIComponent private final int inputCount; private final double height; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List WireEndConnectionPoints; - public GUIOrGate(int processTime, WireArray out, WireArray... in) + public GUIOrGate(int processTime, WireEnd out, WireEnd... in) { super(processTime, out, in); - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List WireEndConnectionPointsModifiable = new ArrayList<>(); this.inputCount = in.length; this.height = inputCount * 10; { - connectedWireArraysModifiable.addAll(Arrays.asList(in)); + connectedWireEndsModifiable.addAll(Arrays.asList(in)); double inputHeight = 5; for (int i = 0; i < inputCount; i++, inputHeight += 10) - wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + WireEndConnectionPointsModifiable.add(new Point(0, inputHeight)); } - connectedWireArraysModifiable.add(out); - wireArrayConnectionPointsModifiable.add(new Point(20, height / 2)); + connectedWireEndsModifiable.add(out); + WireEndConnectionPointsModifiable.add(new Point(20, height / 2)); - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable); } @Override @@ -64,20 +64,20 @@ public class GUIOrGate extends OrGate implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return WireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/components/GUISplitter.java b/LogicUI/src/era/mi/gui/components/GUISplitter.java index bddd9dea..3b877c6e 100644 --- a/LogicUI/src/era/mi/gui/components/GUISplitter.java +++ b/LogicUI/src/era/mi/gui/components/GUISplitter.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import era.mi.logic.components.Splitter; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; @@ -15,31 +15,31 @@ public class GUISplitter extends Splitter implements BasicGUIComponent { private final int outputCount; private final double height; - private final List connectedWireArrays; - private final List wireArrayConnectionPoints; + private final List connectedWireEnds; + private final List WireEndConnectionPoints; - public GUISplitter(WireArray input, WireArray... outputs) + public GUISplitter(WireEnd input, WireEnd... outputs) { super(input, outputs); - List connectedWireArraysModifiable = new ArrayList<>(); - List wireArrayConnectionPointsModifiable = new ArrayList<>(); + List connectedWireEndsModifiable = new ArrayList<>(); + List WireEndConnectionPointsModifiable = new ArrayList<>(); this.outputCount = outputs.length; this.height = (outputCount - 1) * 10; - connectedWireArraysModifiable.add(input); - wireArrayConnectionPointsModifiable.add(new Point(0, height / 2)); + connectedWireEndsModifiable.add(input); + WireEndConnectionPointsModifiable.add(new Point(0, height / 2)); { - connectedWireArraysModifiable.addAll(Arrays.asList(outputs)); + connectedWireEndsModifiable.addAll(Arrays.asList(outputs)); double outputHeight = 0; for (int i = 0; i < outputCount; i++, outputHeight += 10) - wireArrayConnectionPointsModifiable.add(new Point(20, outputHeight)); + WireEndConnectionPointsModifiable.add(new Point(20, outputHeight)); } - this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); - this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); + this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable); + this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable); } @Override @@ -59,20 +59,20 @@ public class GUISplitter extends Splitter implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { - return connectedWireArrays.size(); + return connectedWireEnds.size(); } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return connectedWireArrays.get(connectionIndex); + return connectedWireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionI) + public Point getWireEndConnectionPoint(int connectionI) { - return wireArrayConnectionPoints.get(connectionI); + return WireEndConnectionPoints.get(connectionI); } } \ No newline at end of file diff --git a/LogicUI/src/era/mi/gui/examples/RSLatchGUIExample.java b/LogicUI/src/era/mi/gui/examples/RSLatchGUIExample.java index 1b6582cc..0f2e8f29 100644 --- a/LogicUI/src/era/mi/gui/examples/RSLatchGUIExample.java +++ b/LogicUI/src/era/mi/gui/examples/RSLatchGUIExample.java @@ -6,7 +6,7 @@ import era.mi.gui.components.GUINotGate; import era.mi.gui.components.GUIOrGate; import era.mi.gui.wires.WireConnectionPoint; import era.mi.logic.Simulation; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; public class RSLatchGUIExample @@ -25,19 +25,19 @@ public class RSLatchGUIExample private static void initComponents(LogicUI ui) { Simulation.TIMELINE.reset(); - WireArray r = new WireArray(1, WIRE_DELAY); - WireArray s = new WireArray(1, WIRE_DELAY); - WireArray t2 = new WireArray(1, WIRE_DELAY); - WireArray t1 = new WireArray(1, WIRE_DELAY); - WireArray q = new WireArray(1, WIRE_DELAY); - WireArray nq = new WireArray(1, WIRE_DELAY); + Wire r = new Wire(1, WIRE_DELAY); + Wire s = new Wire(1, WIRE_DELAY); + Wire t2 = new Wire(1, WIRE_DELAY); + Wire t1 = new Wire(1, WIRE_DELAY); + Wire q = new Wire(1, WIRE_DELAY); + Wire nq = new Wire(1, WIRE_DELAY); - GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(r), 100, 100); - GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(s), 100, 200); - GUIOrGate or1 = ui.addComponent(new GUIOrGate(OR_DELAY, t1, r, nq), 160, 102.5); - GUIOrGate or2 = ui.addComponent(new GUIOrGate(OR_DELAY, t2, q, s), 160, 192.5); - GUINotGate not1 = ui.addComponent(new GUINotGate(NOT_DELAY, t1, q), 200, 107.5); - GUINotGate not2 = ui.addComponent(new GUINotGate(NOT_DELAY, t2, nq), 200, 197.5); + GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(r.createEnd()), 100, 100); + GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(s.createEnd()), 100, 200); + GUIOrGate or1 = ui.addComponent(new GUIOrGate(OR_DELAY, t1.createEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()), 160, 102.5); + GUIOrGate or2 = ui.addComponent(new GUIOrGate(OR_DELAY, t2.createEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()), 160, 192.5); + GUINotGate not1 = ui.addComponent(new GUINotGate(NOT_DELAY, t1.createReadOnlyEnd(), q.createEnd()), 200, 107.5); + GUINotGate not2 = ui.addComponent(new GUINotGate(NOT_DELAY, t2.createReadOnlyEnd(), nq.createEnd()), 200, 197.5); WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5); WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5); diff --git a/LogicUI/src/era/mi/gui/wires/GUIWire.java b/LogicUI/src/era/mi/gui/wires/GUIWire.java index e711acb9..a60d3243 100644 --- a/LogicUI/src/era/mi/gui/wires/GUIWire.java +++ b/LogicUI/src/era/mi/gui/wires/GUIWire.java @@ -6,24 +6,24 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import era.mi.gui.components.BasicGUIComponent; -import era.mi.logic.Bit; -import era.mi.logic.wires.WireArray; +import era.mi.logic.types.Bit; +import era.mi.logic.wires.Wire; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; public class GUIWire { - private final WireArray wa; + private final Wire wire; private final double[] path; public GUIWire(Runnable redraw, BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path) { - this.wa = component1.getConnectedWireArray(component1ConnectionIndex); - if (!Objects.equals(wa, component2.getConnectedWireArray(component2ConnectionIndex))) + this.wire = component1.getConnectedWireEnd(component1ConnectionIndex).getWire(); + if (!Objects.equals(wire, component2.getConnectedWireEnd(component2ConnectionIndex).getWire())) throw new IllegalArgumentException("Given connection points are not connected!"); this.path = new double[path.length * 2 + 4]; - Point component1ConnectionPoint = component1.getWireArrayConnectionPoint(component1ConnectionIndex); + Point component1ConnectionPoint = component1.getWireEndConnectionPoint(component1ConnectionIndex); this.path[0] = component1Pos.x + component1ConnectionPoint.x; this.path[1] = component1Pos.y + component1ConnectionPoint.y; for (int srcI = 0, dstI = 2; srcI < path.length; srcI++, dstI += 2) @@ -31,18 +31,18 @@ public class GUIWire this.path[dstI + 0] = path[srcI].x; this.path[dstI + 1] = path[srcI].y; } - Point component2ConnectionPoint = component2.getWireArrayConnectionPoint(component2ConnectionIndex); + Point component2ConnectionPoint = component2.getWireEndConnectionPoint(component2ConnectionIndex); this.path[this.path.length - 2] = component2Pos.x + component2ConnectionPoint.x; this.path[this.path.length - 1] = component2Pos.y + component2ConnectionPoint.y; - wa.addObserver((initiator, oldValues) -> redraw.run()); + wire.addObserver((initiator, oldValues) -> redraw.run()); } public void render(GeneralGC gc) { Color oldFG = gc.getForeground(); - if (wa.length == 1) - gc.setForeground(gc.getDevice().getSystemColor(getSWTColorConstantForBit(wa.getValue()))); + if (wire.length == 1) + gc.setForeground(gc.getDevice().getSystemColor(getSWTColorConstantForBit(wire.getValue()))); gc.drawPolyline(path); gc.setForeground(oldFG); } diff --git a/LogicUI/src/era/mi/gui/wires/WireConnectionPoint.java b/LogicUI/src/era/mi/gui/wires/WireConnectionPoint.java index 916ceabf..f095f0d0 100644 --- a/LogicUI/src/era/mi/gui/wires/WireConnectionPoint.java +++ b/LogicUI/src/era/mi/gui/wires/WireConnectionPoint.java @@ -1,21 +1,31 @@ package era.mi.gui.wires; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.eclipse.swt.graphics.Color; import era.mi.gui.components.BasicGUIComponent; -import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.Wire; +import era.mi.logic.wires.Wire.WireEnd; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; public class WireConnectionPoint implements BasicGUIComponent { - private final WireArray wa; + private final Wire wire; + private final List wireEnds; private final int wiresCrossing; - public WireConnectionPoint(WireArray wa, int wiresCrossing) + public WireConnectionPoint(Wire wire, int wiresCrossing) { - this.wa = wa; + this.wire = wire; + List wireEndsModifiable = new ArrayList<>(); + for (int i = 0; i < wiresCrossing; i++) + wireEndsModifiable.add(wire.createReadOnlyEnd()); + wireEnds = Collections.unmodifiableList(wireEndsModifiable); this.wiresCrossing = wiresCrossing; } @@ -23,8 +33,8 @@ public class WireConnectionPoint implements BasicGUIComponent public void render(GeneralGC gc) { Color oldBG = gc.getBackground(); - if (wa.length == 1) - gc.setBackground(gc.getDevice().getSystemColor(GUIWire.getSWTColorConstantForBit(wa.getValue()))); + if (wire.length == 1) + gc.setBackground(gc.getDevice().getSystemColor(GUIWire.getSWTColorConstantForBit(wire.getValue()))); gc.fillOval(-1, -1, 2, 2); gc.setBackground(oldBG); } @@ -36,19 +46,19 @@ public class WireConnectionPoint implements BasicGUIComponent } @Override - public int getConnectedWireArraysCount() + public int getConnectedWireEndsCount() { return wiresCrossing; } @Override - public WireArray getConnectedWireArray(int connectionIndex) + public WireEnd getConnectedWireEnd(int connectionIndex) { - return wa; + return wireEnds.get(connectionIndex); } @Override - public Point getWireArrayConnectionPoint(int connectionIndex) + public Point getWireEndConnectionPoint(int connectionIndex) { return new Point(0, 0); }