Implemented GUIMerger + GUISplitter
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 17 Aug 2019 22:04:51 +0000 (00:04 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 17 Aug 2019 22:06:12 +0000 (00:06 +0200)
net.mograsim.logic.model/oldsrc/GUIMerger.java [deleted file]
net.mograsim.logic.model/oldsrc/GUIMux.java [deleted file]
net.mograsim.logic.model/oldsrc/GUISplitter.java [deleted file]
net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIMerger.java [new file with mode: 0644]
net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUISplitter.java [new file with mode: 0644]
net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/MergerAdapter.java [new file with mode: 0644]
net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/SplitterAdapter.java [new file with mode: 0644]

diff --git a/net.mograsim.logic.model/oldsrc/GUIMerger.java b/net.mograsim.logic.model/oldsrc/GUIMerger.java
deleted file mode 100644 (file)
index 64fd0aa..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-package era.mi.gui.components;
-
-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.Wire.ReadEnd;
-import era.mi.logic.wires.Wire.ReadWriteEnd;
-import net.haspamelodica.swt.helper.gcs.GeneralGC;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-
-public class GUIMerger extends Merger implements GUIComponent
-{
-       private final int inputCount;
-       private final double height;
-       private final List<ReadEnd> connectedWireEnds;
-       private final List<Point> WireEndConnectionPoints;
-
-       public GUIMerger(ReadWriteEnd union, ReadEnd... inputs)
-       {
-               super(union, inputs);
-
-               List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();
-               List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();
-
-               this.inputCount = inputs.length;
-               this.height = (inputCount - 1) * 10;
-
-               {
-                       connectedWireEndsModifiable.addAll(Arrays.asList(inputs));
-                       double inputHeight = 0;
-                       for (int i = 0; i < inputCount; i++, inputHeight += 10)
-                               WireEndConnectionPointsModifiable.add(new Point(0, inputHeight));
-               }
-
-               connectedWireEndsModifiable.add(union);
-               WireEndConnectionPointsModifiable.add(new Point(20, height / 2));
-
-               this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
-               this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);
-       }
-
-       @Override
-       public Rectangle getBounds()
-       {
-               return new Rectangle(0, 0, 20, height);
-       }
-
-       @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 getConnectedWireEndsCount()
-       {
-               return connectedWireEnds.size();
-       }
-
-       @Override
-       public ReadEnd getConnectedWireEnd(int connectionIndex)
-       {
-               return connectedWireEnds.get(connectionIndex);
-       }
-
-       @Override
-       public Point getWireEndConnectionPoint(int connectionI)
-       {
-               return WireEndConnectionPoints.get(connectionI);
-       }
-}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/oldsrc/GUIMux.java b/net.mograsim.logic.model/oldsrc/GUIMux.java
deleted file mode 100644 (file)
index d004d90..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-package era.mi.gui.components;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import era.mi.logic.components.Mux;
-import era.mi.logic.wires.Wire.ReadEnd;
-import era.mi.logic.wires.Wire.ReadWriteEnd;
-import net.haspamelodica.swt.helper.gcs.GeneralGC;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-
-public class GUIMux extends Mux implements GUIComponent
-{
-       private final double height;
-       private final List<ReadEnd> connectedWireEnds;
-       private final List<Point> WireEndConnectionPoints;
-
-       public GUIMux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)
-       {
-               super(processTime, out, select, inputs);
-
-               double height = inputs.length * 5;
-               if (height < 10)
-                       height = 10;
-               this.height = height;
-
-               List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();
-               List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();
-
-               connectedWireEndsModifiable.add(out);
-               WireEndConnectionPointsModifiable.add(new Point(20, 10 + height / 2));
-
-               connectedWireEndsModifiable.add(select);
-               WireEndConnectionPointsModifiable.add(new Point(10, 5));
-
-               {
-                       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)
-                               WireEndConnectionPointsModifiable.add(new Point(0, inputHeight));
-               }
-
-               this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
-               this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);
-       }
-
-       @Override
-       public Rectangle getBounds()
-       {
-               return new Rectangle(0, 0, 20, height + 20);
-       }
-
-       @Override
-       public void render(GeneralGC gc)
-       {
-               gc.drawPolygon(new double[] { 0, 0, 20, 10, 20, height + 10, 0, height + 20 });
-       }
-
-       @Override
-       public int getConnectedWireEndsCount()
-       {
-               return connectedWireEnds.size();
-       }
-
-       @Override
-       public ReadEnd getConnectedWireEnd(int connectionIndex)
-       {
-               return connectedWireEnds.get(connectionIndex);
-       }
-
-       @Override
-       public Point getWireEndConnectionPoint(int connectionI)
-       {
-               return WireEndConnectionPoints.get(connectionI);
-       }
-}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/oldsrc/GUISplitter.java b/net.mograsim.logic.model/oldsrc/GUISplitter.java
deleted file mode 100644 (file)
index 1bff424..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package era.mi.gui.components;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import era.mi.gui.ViewModel;
-import era.mi.logic.components.Splitter;
-import era.mi.logic.wires.Wire.ReadEnd;
-import era.mi.logic.wires.Wire.ReadWriteEnd;
-import net.haspamelodica.swt.helper.gcs.GeneralGC;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-
-public class GUISplitter extends GUIComponent
-{
-       public GUISplitter(ViewModel model)
-       {
-               super(model);
-
-               this.outputCount = outputs.length;
-               this.height = (outputCount - 1) * 10;
-
-               connectedWireEndsModifiable.add(input);
-               WireEndConnectionPointsModifiable.add(new Point(0, height / 2));
-
-               {
-                       connectedWireEndsModifiable.addAll(Arrays.asList(outputs));
-                       double outputHeight = 0;
-                       for (int i = 0; i < outputCount; i++, outputHeight += 10)
-                               WireEndConnectionPointsModifiable.add(new Point(20, outputHeight));
-               }
-
-               this.connectedWireEnds = Collections.unmodifiableList(connectedWireEndsModifiable);
-               this.WireEndConnectionPoints = Collections.unmodifiableList(WireEndConnectionPointsModifiable);
-       }
-
-       @Override
-       public Rectangle getBounds()
-       {
-               return new Rectangle(0, 0, 20, height);
-       }
-
-       @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 getConnectedWireEndsCount()
-       {
-               return connectedWireEnds.size();
-       }
-
-       @Override
-       public ReadEnd getConnectedWireEnd(int connectionIndex)
-       {
-               return connectedWireEnds.get(connectionIndex);
-       }
-
-       @Override
-       public Point getWireEndConnectionPoint(int connectionI)
-       {
-               return WireEndConnectionPoints.get(connectionI);
-       }
-}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIMerger.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIMerger.java
new file mode 100644 (file)
index 0000000..cee4b74
--- /dev/null
@@ -0,0 +1,69 @@
+package net.mograsim.logic.model.model.components.atomic;
+
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.core.types.BitVectorFormatter;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
+import net.mograsim.logic.model.modeladapter.componentadapters.MergerAdapter;
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.ColorManager;
+import net.mograsim.preferences.Preferences;
+
+public class GUIMerger extends GUIComponent
+{
+       private static final double width = 20;
+       private static final double heightPerPin = 10;
+
+       public final int logicWidth;
+
+       private ReadEnd[] inputEnds;
+       private ReadEnd outputEnd;
+
+       public GUIMerger(ViewModelModifiable model, int logicWidth, String name)
+       {
+               super(model, name);
+               this.logicWidth = logicWidth;
+               setSize(width, logicWidth * heightPerPin);
+               double inputHeight = 0;
+               for (int i = 0; i < logicWidth; i++, inputHeight += 10)
+                       addPin(new Pin(this, "I" + i, 1, 0, inputHeight));
+               addPin(new Pin(this, "O", logicWidth, width, logicWidth * heightPerPin / 2));
+       }
+
+       @Override
+       public void render(GeneralGC gc, Rectangle visibleRegion)
+       {
+               double posX = getPosX();
+               double posY = getPosY();
+
+               double inputHeight = posY;
+               for (int i = 0; i < logicWidth; i++, inputHeight += 10)
+               {
+                       ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnds[i]);
+                       if (c != null)
+                               gc.setForeground(ColorManager.current().toColor(c));
+                       gc.drawLine(posX, inputHeight, posX + width / 2, inputHeight);
+               }
+               gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
+               gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
+               ColorDefinition c = BitVectorFormatter.formatAsColor(outputEnd);
+               if (c != null)
+                       gc.setForeground(ColorManager.current().toColor(c));
+               gc.drawLine(posX + width / 2, posY + heightPerPin * logicWidth / 2, posX + width, posY + heightPerPin * logicWidth / 2);
+       }
+
+       public void setLogicModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
+       {
+               this.inputEnds = inputEnds;
+               this.outputEnd = outputEnd;
+       }
+
+       static
+       {
+               ViewLogicModelAdapter.addComponentAdapter(new MergerAdapter());
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUISplitter.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUISplitter.java
new file mode 100644 (file)
index 0000000..1dc11d1
--- /dev/null
@@ -0,0 +1,69 @@
+package net.mograsim.logic.model.model.components.atomic;
+
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.core.types.BitVectorFormatter;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
+import net.mograsim.logic.model.modeladapter.componentadapters.SplitterAdapter;
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.ColorManager;
+import net.mograsim.preferences.Preferences;
+
+public class GUISplitter extends GUIComponent
+{
+       private static final double width = 20;
+       private static final double heightPerPin = 10;
+
+       public final int logicWidth;
+
+       private ReadEnd inputEnd;
+       private ReadEnd[] outputEnds;
+
+       public GUISplitter(ViewModelModifiable model, int logicWidth, String name)
+       {
+               super(model, name);
+               this.logicWidth = logicWidth;
+               setSize(width, logicWidth * heightPerPin);
+               addPin(new Pin(this, "I", logicWidth, 0, logicWidth * heightPerPin / 2));
+               double outputHeight = 0;
+               for (int i = 0; i < logicWidth; i++, outputHeight += 10)
+                       addPin(new Pin(this, "O" + i, 1, width, outputHeight));
+       }
+
+       @Override
+       public void render(GeneralGC gc, Rectangle visibleRegion)
+       {
+               double posX = getPosX();
+               double posY = getPosY();
+
+               ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnd);
+               if (c != null)
+                       gc.setForeground(ColorManager.current().toColor(c));
+               gc.drawLine(posX, posY + heightPerPin * logicWidth / 2, posX + width / 2, posY + heightPerPin * logicWidth / 2);
+               gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
+               gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
+               double outputHeight = posY;
+               for (int i = 0; i < logicWidth; i++, outputHeight += 10)
+               {
+                       c = BitVectorFormatter.formatAsColor(outputEnds[i]);
+                       if (c != null)
+                               gc.setForeground(ColorManager.current().toColor(c));
+                       gc.drawLine(posX + width / 2, outputHeight, posX + width, outputHeight);
+               }
+       }
+
+       public void setLogicModelBinding(ReadEnd inputEnd, ReadEnd[] outputEnds)
+       {
+               this.inputEnd = inputEnd;
+               this.outputEnds = outputEnds;
+       }
+
+       static
+       {
+               ViewLogicModelAdapter.addComponentAdapter(new SplitterAdapter());
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/MergerAdapter.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/MergerAdapter.java
new file mode 100644 (file)
index 0000000..a94118b
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.model.modeladapter.componentadapters;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.Wire;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.model.model.components.atomic.GUIMerger;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.LogicModelParameters;
+
+public class MergerAdapter implements ComponentAdapter<GUIMerger>
+{
+       @Override
+       public Class<GUIMerger> getSupportedClass()
+       {
+               return GUIMerger.class;
+       }
+
+       @Override
+       public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUIMerger guiComponent,
+                       Map<Pin, Wire> logicWiresPerPin)
+       {
+               Wire output = logicWiresPerPin.get(guiComponent.getPin("O"));
+               ReadEnd[] inputEnds = new ReadEnd[guiComponent.logicWidth];
+               for (int i = 0; i < guiComponent.logicWidth; i++)
+               {
+                       Wire input = logicWiresPerPin.get(guiComponent.getPin("I" + i));
+                       Wire.fuse(input, output, 0, i, 1);
+                       inputEnds[i] = input.createReadOnlyEnd();
+               }
+               guiComponent.setLogicModelBinding(inputEnds, output.createReadOnlyEnd());
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/SplitterAdapter.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/SplitterAdapter.java
new file mode 100644 (file)
index 0000000..a262340
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.model.modeladapter.componentadapters;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.wires.Wire;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.model.model.components.atomic.GUISplitter;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.LogicModelParameters;
+
+public class SplitterAdapter implements ComponentAdapter<GUISplitter>
+{
+       @Override
+       public Class<GUISplitter> getSupportedClass()
+       {
+               return GUISplitter.class;
+       }
+
+       @Override
+       public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUISplitter guiComponent,
+                       Map<Pin, Wire> logicWiresPerPin)
+       {
+               Wire input = logicWiresPerPin.get(guiComponent.getPin("I"));
+               ReadEnd[] outputEnds = new ReadEnd[guiComponent.logicWidth];
+               for (int i = 0; i < guiComponent.logicWidth; i++)
+               {
+                       Wire output = logicWiresPerPin.get(guiComponent.getPin("O" + i));
+                       Wire.fuse(input, output, i, 0, 1);
+                       outputEnds[i] = output.createReadOnlyEnd();
+               }
+               guiComponent.setLogicModelBinding(input.createReadOnlyEnd(), outputEnds);
+       }
+}
\ No newline at end of file