Moved code serializing a symbol renderer to where it belongs
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 4 Jul 2019 08:30:35 +0000 (10:30 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 4 Jul 2019 08:30:35 +0000 (10:30 +0200)
31 files changed:
net.mograsim.logic.ui.am2900/components/GUI_rsLatch.json
net.mograsim.logic.ui.am2900/components/GUIand.json
net.mograsim.logic.ui.am2900/components/GUIand41.json
net.mograsim.logic.ui.am2900/components/GUIandor414.json
net.mograsim.logic.ui.am2900/components/GUIdemux2.json
net.mograsim.logic.ui.am2900/components/GUIdff.json
net.mograsim.logic.ui.am2900/components/GUIdlatch.json
net.mograsim.logic.ui.am2900/components/GUIdlatch4.json
net.mograsim.logic.ui.am2900/components/GUIfulladder.json
net.mograsim.logic.ui.am2900/components/GUIhalfadder.json
net.mograsim.logic.ui.am2900/components/GUImux1.json
net.mograsim.logic.ui.am2900/components/GUImux1_4.json
net.mograsim.logic.ui.am2900/components/GUInand3.json
net.mograsim.logic.ui.am2900/components/GUInot4.json
net.mograsim.logic.ui.am2900/components/GUIor4.json
net.mograsim.logic.ui.am2900/components/GUIor_4.json
net.mograsim.logic.ui.am2900/components/GUIram2.json
net.mograsim.logic.ui.am2900/components/GUIram4.json
net.mograsim.logic.ui.am2900/components/GUIsel2_4.json
net.mograsim.logic.ui.am2900/components/GUIsel3_4.json
net.mograsim.logic.ui.am2900/components/GUIxor.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUFuncDecode.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclDecode.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUOneBit.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901DestDecode.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901QReg.json
net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901SourceDecode.json
net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/ComponenetSerializer.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/submodels/SimpleRectangularSubmodelComponent.java

index 35ebc03..39ef290 100644 (file)
@@ -211,7 +211,7 @@ mograsim version: 0.1.3
   "symbolRendererParams": {
     "centerText": "_rsLatch",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index d717447..9e801e1 100644 (file)
@@ -134,9 +134,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "and",
+    "centerText": "GUIand",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 2e9d953..c3157e9 100644 (file)
@@ -312,9 +312,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "and41",
+    "centerText": "GUIand41",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 0a9f264..5021dba 100644 (file)
@@ -476,9 +476,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "andor414",
+    "centerText": "GUIandor414",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 07bf5ad..13ff969 100644 (file)
@@ -488,9 +488,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "demux2",
+    "centerText": "GUIdemux2",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 4902e6c..cc8ed5e 100644 (file)
@@ -311,9 +311,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "dff",
+    "centerText": "GUIdff",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index a5c6b43..4b39347 100644 (file)
@@ -224,9 +224,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "dlatch",
+    "centerText": "GUIdlatch",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 8dddd05..a1d560c 100644 (file)
@@ -312,9 +312,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "dlatch4",
+    "centerText": "GUIdlatch4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 34cc7ea..aef6aee 100644 (file)
@@ -176,9 +176,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "fulladder",
+    "centerText": "GUIfulladder",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 36885ac..948192b 100644 (file)
@@ -301,9 +301,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "halfadder",
+    "centerText": "GUIhalfadder",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 90e9013..4cc997c 100644 (file)
@@ -215,9 +215,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "mux1",
+    "centerText": "GUImux1",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index d4f23ba..b7a8e71 100644 (file)
@@ -452,9 +452,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "mux1_4",
+    "centerText": "GUImux1_4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index be95065..559238d 100644 (file)
@@ -191,9 +191,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "nand3",
+    "centerText": "GUInand3",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index ff9a8da..a6268de 100644 (file)
@@ -357,9 +357,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "not4",
+    "centerText": "GUInot4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 92e54aa..54933c4 100644 (file)
@@ -501,9 +501,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "or4",
+    "centerText": "GUIor4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 53ad0d6..7db8660 100644 (file)
@@ -817,9 +817,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "or_4",
+    "centerText": "GUIor_4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index dd05167..f748b0b 100644 (file)
@@ -2773,9 +2773,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "ram2",
+    "centerText": "GUIram2",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 16f912e..976f09c 100644 (file)
@@ -3145,9 +3145,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "ram4",
+    "centerText": "GUIram4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 6fa6d3a..9f7babe 100644 (file)
@@ -785,9 +785,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "sel2_4",
+    "centerText": "GUIsel2_4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index e5b5d46..f999b22 100644 (file)
@@ -856,9 +856,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "sel3_4",
+    "centerText": "GUIsel3_4",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 001f554..8f589d5 100644 (file)
@@ -251,9 +251,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "xor",
+    "centerText": "GUIxor",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 9fc9e8d..af06681 100644 (file)
@@ -3182,9 +3182,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901",
+    "centerText": "GUIAm2901",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index b30dcdd..dfa954a 100644 (file)
@@ -654,9 +654,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901ALUFuncDecode",
+    "centerText": "GUIAm2901ALUFuncDecode",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 39aac79..9d6395c 100644 (file)
@@ -1418,9 +1418,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901ALUInclDecode",
+    "centerText": "GUIAm2901ALUInclDecode",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 6c9e6d3..fb6e911 100644 (file)
@@ -1296,9 +1296,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901ALUInclSourceDecodeInclFunctionDecode",
+    "centerText": "GUIAm2901ALUInclSourceDecodeInclFunctionDecode",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 5c6215d..ac53c55 100644 (file)
@@ -502,9 +502,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901ALUOneBit",
+    "centerText": "GUIAm2901ALUOneBit",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 621fccd..613b9b9 100644 (file)
@@ -997,9 +997,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901DestDecode",
+    "centerText": "GUIAm2901DestDecode",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 6bc113d..7188972 100644 (file)
@@ -391,9 +391,9 @@ mograsim version: 0.1.3
   },
   "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
   "symbolRendererParams": {
-    "centerText": "Am2901QReg",
+    "centerText": "GUIAm2901QReg",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 33b3ff1..75b5f70 100644 (file)
@@ -1038,7 +1038,7 @@ mograsim version: 0.1.3
   "symbolRendererParams": {
     "centerText": "Am2901SourceDecode",
     "horizontalComponentCenter": 17.5,
-    "centerTextHeight": 5,
+    "centerTextHeight": 5.0,
     "pinLabelHeight": 3.5,
     "pinLabelMargin": 0.5
   }
index 397592e..4c7b5d9 100644 (file)
@@ -3,8 +3,6 @@ package net.mograsim.logic.ui.examples;
 import java.io.IOException;
 import java.util.function.Function;
 
-import com.google.gson.JsonObject;
-
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUIComponent;
 import net.mograsim.logic.ui.model.components.mi.nandbased.GUI_rsLatch;
@@ -59,15 +57,6 @@ public class ComponenetSerializer
                for (SubmodelComponent comp : components)
                {
                        SubmodelComponentParams params = comp.calculateParams(getIdentifier);
-                       JsonObject symbolRendererParams = new JsonObject();
-                       symbolRendererParams.addProperty("centerText", comp.getClass().getSimpleName().substring(3)); // cut away the "GUI" part
-                       symbolRendererParams.addProperty("horizontalComponentCenter", comp.getWidth() / 2);
-                       // use the defaults from SimpleRectangularSubmodelComponent
-                       symbolRendererParams.addProperty("centerTextHeight", 5);
-                       symbolRendererParams.addProperty("pinLabelHeight", 3.5);
-                       symbolRendererParams.addProperty("pinLabelMargin", .5);
-                       params.symbolRendererSnippetID = "SimpleRectangularLikeSymbolRenderer";
-                       params.symbolRendererParams = symbolRendererParams;
                        JsonHandler.writeJson(params, "components/"
                                        + comp.getClass().getName().substring("net.mograsim.logic.ui.model.components.mi.nandbased.".length()).replace('.', '/')
                                        + ".json");
index 2bc062e..529767e 100644 (file)
@@ -5,16 +5,21 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.function.Function;
 
 import org.eclipse.swt.graphics.Color;
 
+import com.google.gson.JsonObject;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
+import net.mograsim.logic.ui.model.components.GUIComponent;
 import net.mograsim.logic.ui.model.wires.MovablePin;
 import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.logic.ui.serializing.SubmodelComponentParams;
 import net.mograsim.preferences.Preferences;
 
 public class SimpleRectangularSubmodelComponent extends SubmodelComponent
@@ -127,6 +132,23 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
                gc.drawRectangle(getBounds());
        }
 
+       // serializing
+
+       @Override
+       public SubmodelComponentParams calculateParams(Function<GUIComponent, String> getIdentifier)
+       {
+               SubmodelComponentParams params = super.calculateParams(getIdentifier);
+               JsonObject symbolRendererParams = new JsonObject();
+               symbolRendererParams.addProperty("centerText", label);
+               symbolRendererParams.addProperty("horizontalComponentCenter", getWidth() / 2);
+               symbolRendererParams.addProperty("centerTextHeight", labelFontHeight);
+               symbolRendererParams.addProperty("pinLabelHeight", pinNameFontHeight);
+               symbolRendererParams.addProperty("pinLabelMargin", pinNameMargin);
+               params.symbolRendererSnippetID = "SimpleRectangularLikeSymbolRenderer";
+               params.symbolRendererParams = symbolRendererParams;
+               return params;
+       }
+
        @Override
        protected Pin addSubmodelInterface(MovablePin supermodelPin)
        {