Added two SymbolRendererProviders
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 4 Jul 2019 08:24:44 +0000 (10:24 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 4 Jul 2019 08:24:44 +0000 (10:24 +0200)
39 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
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentDeserializer.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentParams.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json

index 4431f34..35ebc03 100644 (file)
@@ -206,5 +206,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "_rsLatch",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 0687592..d717447 100644 (file)
@@ -131,5 +131,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "and",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index cb1608a..2e9d953 100644 (file)
@@ -309,5 +309,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "and41",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index d585785..0a9f264 100644 (file)
@@ -473,5 +473,13 @@ mograsim version: 0.1.3
         ]
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "andor414",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 04df7d0..07bf5ad 100644 (file)
@@ -485,5 +485,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "demux2",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index df4e0a1..4902e6c 100644 (file)
@@ -308,5 +308,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "dff",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 84e635f..a5c6b43 100644 (file)
@@ -221,5 +221,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "dlatch",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 2458b25..8dddd05 100644 (file)
@@ -309,5 +309,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "dlatch4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index d739628..34cc7ea 100644 (file)
@@ -173,5 +173,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "fulladder",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 5cffb3d..36885ac 100644 (file)
@@ -298,5 +298,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "halfadder",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index c341226..90e9013 100644 (file)
@@ -212,5 +212,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "mux1",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 35f9c2f..d4f23ba 100644 (file)
@@ -449,5 +449,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "mux1_4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 7177e91..be95065 100644 (file)
@@ -188,5 +188,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "nand3",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 5df0c82..ff9a8da 100644 (file)
@@ -354,5 +354,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "not4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 9eb7216..92e54aa 100644 (file)
@@ -498,5 +498,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "or4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 06aa13f..53ad0d6 100644 (file)
@@ -814,5 +814,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "or_4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index c1d00ea..dd05167 100644 (file)
@@ -2770,5 +2770,13 @@ mograsim version: 0.1.3
         ]
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "ram2",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 87c2892..16f912e 100644 (file)
@@ -3142,5 +3142,13 @@ mograsim version: 0.1.3
         ]
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "ram4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index b3845c4..6fa6d3a 100644 (file)
@@ -782,5 +782,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "sel2_4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index fdcbfaf..e5b5d46 100644 (file)
@@ -853,5 +853,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "sel3_4",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 6b74a5c..001f554 100644 (file)
@@ -248,5 +248,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "xor",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index d773d7b..9fc9e8d 100644 (file)
@@ -3179,5 +3179,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index cf9f5a6..b30dcdd 100644 (file)
@@ -651,5 +651,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901ALUFuncDecode",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 1984f63..39aac79 100644 (file)
@@ -1415,5 +1415,13 @@ mograsim version: 0.1.3
         }
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901ALUInclDecode",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 3481904..6c9e6d3 100644 (file)
@@ -1293,5 +1293,13 @@ mograsim version: 0.1.3
         ]
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901ALUInclSourceDecodeInclFunctionDecode",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 84f1a12..5c6215d 100644 (file)
@@ -499,5 +499,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901ALUOneBit",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 20dbfb0..621fccd 100644 (file)
@@ -994,5 +994,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901DestDecode",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index b277225..6bc113d 100644 (file)
@@ -388,5 +388,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901QReg",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index e72cc9f..33b3ff1 100644 (file)
@@ -1033,5 +1033,13 @@ mograsim version: 0.1.3
         "path": []
       }
     ]
+  },
+  "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer",
+  "symbolRendererParams": {
+    "centerText": "Am2901SourceDecode",
+    "horizontalComponentCenter": 17.5,
+    "centerTextHeight": 5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
   }
 }
\ No newline at end of file
index 4c7b5d9..397592e 100644 (file)
@@ -3,6 +3,8 @@ 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;
@@ -57,6 +59,15 @@ 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 65114b6..2bc062e 100644 (file)
@@ -93,6 +93,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
        @Override
        protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion)
        {
+               // TODO code duplication: see SimpleRectagularLikeSymbolRendererProvider
                Font oldFont = gc.getFont();
                gc.setFont(new Font(oldFont.getName(), labelFontHeight, oldFont.getStyle()));
                Point textExtent = gc.textExtent(label);
index 62014ca..8c13e96 100644 (file)
@@ -7,14 +7,11 @@ import java.util.Map;
 
 import com.google.gson.JsonElement;
 
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.ui.serializing.snippets.Renderer;
 import net.mograsim.logic.ui.serializing.snippets.RendererProvider;
+import net.mograsim.logic.ui.serializing.snippets.outlinerenderers.DefaultOutlineRendererProvider;
+import net.mograsim.logic.ui.serializing.snippets.symbolrenderers.DefaultSymbolRendererProvider;
 import net.mograsim.logic.ui.util.JsonHandler;
-import net.mograsim.preferences.ColorDefinition;
-import net.mograsim.preferences.ColorManager;
-import net.mograsim.preferences.Preferences;
 
 public class CodeSnippetSupplier
 {
@@ -27,24 +24,8 @@ public class CodeSnippetSupplier
        private static final RendererProvider defaultSymbolRendererProvider;
        static
        {
-               // TODO this code does not belong here
-               defaultOutlineRendererProvider = (comp, params) -> (gc, visReg) ->
-               {
-                       ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.foreground");
-                       if (fg != null)
-                               gc.setForeground(ColorManager.current().toColor(fg));
-                       gc.drawRectangle(comp.getBounds());
-               };
-               defaultSymbolRendererProvider = (comp, params) -> (gc, visReg) ->
-               {
-                       ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
-                       if (fg != null)
-                               gc.setForeground(ColorManager.current().toColor(fg));
-                       String id = "TODO";// TODO add an ID of sorts to DeserializedSubmodelComponent
-                       Point idSize = gc.textExtent(id);
-                       Rectangle bounds = comp.getBounds();
-                       gc.drawText(id, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true);
-               };
+               defaultOutlineRendererProvider = new DefaultOutlineRendererProvider();
+               defaultSymbolRendererProvider = new DefaultSymbolRendererProvider();
        }
 
        static
@@ -105,12 +86,13 @@ public class CodeSnippetSupplier
                                        return specializedCode;
                        }
                }
+               System.err.println("Couldn't load snippet " + id + "; using default");
                return defaultSnippet;
        }
 
        private static void tryLoadSnippetClass(String snippetClassName)
        {
-               tryInvokeStaticInitializer(snippetClassName, "Error getting snippet code for component class: %s: %s\n");
+               tryInvokeStaticInitializer(snippetClassName, "Error getting snippet class: %s: %s\n");
        }
 
        public static void tryInvokeStaticInitializer(String className, String errorMessageFormat)
index ffb120d..e997ad2 100644 (file)
@@ -62,9 +62,8 @@ public final class SubmodelComponentDeserializer
                DeserializedSubmodelComponent comp = new DeserializedSubmodelComponent(model);
                comp.setSubmodelScale(params.submodel.innerScale);
                comp.setOutlineRenderer(
-                               CodeSnippetSupplier.createOutlineRenderer(params.outlineRendererSnippetClass, comp, params.outlineRendererParams));
-               comp.setSymbolRenderer(
-                               CodeSnippetSupplier.createSymbolRenderer(params.symbolRendererSnippetClass, comp, params.symbolRendererParams));
+                               CodeSnippetSupplier.createOutlineRenderer(params.outlineRendererSnippetID, comp, params.outlineRendererParams));
+               comp.setSymbolRenderer(CodeSnippetSupplier.createSymbolRenderer(params.symbolRendererSnippetID, comp, params.symbolRendererParams));
                // TODO high level states
                comp.setSize(params.width, params.height);
                for (InterfacePinParams iPinParams : params.interfacePins)
index a1f2c82..e2a0e48 100644 (file)
@@ -19,10 +19,10 @@ public class SubmodelComponentParams
        public SubmodelParameters submodel;
 
        // functionality that needs to be expressed in Java code
-       public String outlineRendererSnippetClass;
+       public String outlineRendererSnippetID;
        public JsonElement outlineRendererParams;
 
-       public String symbolRendererSnippetClass;
+       public String symbolRendererSnippetID;
        public JsonElement symbolRendererParams;
 
        public static class InterfacePinParams
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java
new file mode 100644 (file)
index 0000000..b236aa8
--- /dev/null
@@ -0,0 +1,26 @@
+package net.mograsim.logic.ui.serializing.snippets.outlinerenderers;
+
+import com.google.gson.JsonElement;
+
+import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent;
+import net.mograsim.logic.ui.serializing.snippets.Renderer;
+import net.mograsim.logic.ui.serializing.snippets.RendererProvider;
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.ColorManager;
+import net.mograsim.preferences.Preferences;
+
+public class DefaultOutlineRendererProvider implements RendererProvider
+{
+       @Override
+       public Renderer create(DeserializedSubmodelComponent component, JsonElement params)
+       {
+               return (gc, visReg) ->
+               {
+                       ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.foreground");
+                       if (fg != null)
+                               gc.setForeground(ColorManager.current().toColor(fg));
+                       gc.drawRectangle(component.getBounds());
+               };
+
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java
new file mode 100644 (file)
index 0000000..de1551b
--- /dev/null
@@ -0,0 +1,57 @@
+package net.mograsim.logic.ui.serializing.snippets.symbolrenderers;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+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.serializing.CodeSnippetSupplier;
+import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent;
+import net.mograsim.logic.ui.serializing.snippets.Renderer;
+import net.mograsim.logic.ui.serializing.snippets.RendererProvider;
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.ColorManager;
+import net.mograsim.preferences.Preferences;
+
+/**
+ * Renders a text (<code>"text"</code>) with a given font height (<code>"height"</code>) in the center of the component.<br>
+ * Parameter format:
+ * 
+ * <pre>
+ * {
+ *   "text": [String]
+ *   "height": [int]
+ * }
+ * </pre>
+ * 
+ * @author Daniel Kirschten
+ */
+public class CenteredTextSymbolRendererProvider implements RendererProvider
+{
+       @Override
+       public Renderer create(DeserializedSubmodelComponent component, JsonElement params)
+       {
+               JsonObject asJsonObject = params.getAsJsonObject();
+               String text = asJsonObject.getAsJsonPrimitive("text").getAsString();
+               int fontHeight = asJsonObject.getAsJsonPrimitive("height").getAsInt();
+               return (gc, visReg) ->
+               {
+                       Font oldFont = gc.getFont();
+                       gc.setFont(new Font(oldFont.getName(), fontHeight, oldFont.getStyle()));
+                       ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
+                       if (fg != null)
+                               gc.setForeground(ColorManager.current().toColor(fg));
+                       Point idSize = gc.textExtent(text);
+                       Rectangle bounds = component.getBounds();
+                       gc.drawText(text, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true);
+                       gc.setFont(oldFont);
+               };
+       }
+
+       static
+       {
+               CodeSnippetSupplier.setSymbolRendererProvider(CenteredTextSymbolRendererProvider.class.getCanonicalName(),
+                               new CenteredTextSymbolRendererProvider());
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java
new file mode 100644 (file)
index 0000000..4d445d6
--- /dev/null
@@ -0,0 +1,31 @@
+package net.mograsim.logic.ui.serializing.snippets.symbolrenderers;
+
+import com.google.gson.JsonElement;
+
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent;
+import net.mograsim.logic.ui.serializing.snippets.Renderer;
+import net.mograsim.logic.ui.serializing.snippets.RendererProvider;
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.ColorManager;
+import net.mograsim.preferences.Preferences;
+
+public class DefaultSymbolRendererProvider implements RendererProvider
+{
+       private static final String id = "<Symbol\nunknown>";
+
+       @Override
+       public Renderer create(DeserializedSubmodelComponent component, JsonElement params)
+       {
+               return (gc, visReg) ->
+               {
+                       ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
+                       if (fg != null)
+                               gc.setForeground(ColorManager.current().toColor(fg));
+                       Point idSize = gc.textExtent(id);
+                       Rectangle bounds = component.getBounds();
+                       gc.drawText(id, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true);
+               };
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java
new file mode 100644 (file)
index 0000000..a47c47f
--- /dev/null
@@ -0,0 +1,83 @@
+package net.mograsim.logic.ui.serializing.snippets.symbolrenderers;
+
+import java.util.Map.Entry;
+
+import org.eclipse.swt.graphics.Color;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.logic.ui.serializing.CodeSnippetSupplier;
+import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent;
+import net.mograsim.logic.ui.serializing.snippets.Renderer;
+import net.mograsim.logic.ui.serializing.snippets.RendererProvider;
+import net.mograsim.preferences.Preferences;
+
+/**
+ * Renders a text (<code>"centerText"</code>) with a given font height (<code>"centerTextHeight"</code>) in the center of the component and
+ * draws a label for each pin with a given font height (<code>"pinLabelHeight"</code>). The labels of pins to the left of a given x
+ * coordinate (<code>"horizontalComponentCenter"</code>) are drawn to the right of the respective pin; labels of pins to the right are drawn
+ * left. A margin (<code>"pinLabelMargin"</code>) is applied for pin label drawing.<br>
+ * Parameter format:
+ * 
+ * <pre>
+ * {
+ *   "centerText": [String]
+ *   "centerTextHeight": [double]
+ *   "horizontalComponentCenter": [double]
+ *   "pinLabelHeight": [double]
+ *   "pinLabelMargin": [double]
+ * }
+ * </pre>
+ * 
+ * @author Daniel Kirschten
+ */
+public class SimpleRectangularLikeSymbolRendererProvider implements RendererProvider
+{
+       @Override
+       public Renderer create(DeserializedSubmodelComponent component, JsonElement params)
+       {
+               JsonObject asJsonObject = params.getAsJsonObject();
+               String centerText = asJsonObject.getAsJsonPrimitive("centerText").getAsString();
+               double centerTextHeight = asJsonObject.getAsJsonPrimitive("centerTextHeight").getAsDouble();
+               double horizontalComponentCenter = asJsonObject.getAsJsonPrimitive("horizontalComponentCenter").getAsDouble();
+               double pinLabelHeight = asJsonObject.getAsJsonPrimitive("pinLabelHeight").getAsDouble();
+               double pinLabelMargin = asJsonObject.getAsJsonPrimitive("pinLabelMargin").getAsDouble();
+               return (gc, visReg) ->
+               {
+                       double posX = component.getPosX();
+                       double posY = component.getPosY();
+                       double width = component.getWidth();
+                       double height = component.getHeight();
+
+                       Font oldFont = gc.getFont();
+                       gc.setFont(new Font(oldFont.getName(), centerTextHeight, oldFont.getStyle()));
+                       Point textExtent = gc.textExtent(centerText);
+                       Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+                       if (textColor != null)
+                               gc.setForeground(textColor);
+                       gc.drawText(centerText, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true);
+                       gc.setFont(new Font(oldFont.getName(), pinLabelHeight, oldFont.getStyle()));
+                       for (Entry<String, Pin> pinEntry : component.getPins().entrySet())
+                       {
+                               String pinName = pinEntry.getKey();
+                               Pin pin = pinEntry.getValue();
+                               double pinX = pin.getRelX();
+                               double pinY = posY + pin.getRelY();
+                               textExtent = gc.textExtent(pinName);
+                               gc.drawText(pinName, posX + pinX + (pinX > horizontalComponentCenter ? -textExtent.x - pinLabelMargin : pinLabelMargin),
+                                               pinY - textExtent.y / 2, true);
+                       }
+                       gc.setFont(oldFont);
+               };
+       }
+
+       static
+       {
+               CodeSnippetSupplier.setSymbolRendererProvider(SimpleRectangularLikeSymbolRendererProvider.class.getCanonicalName(),
+                               new SimpleRectangularLikeSymbolRendererProvider());
+       }
+}
\ No newline at end of file
index 8224951..850d54c 100644 (file)
@@ -1,3 +1,5 @@
 mograsim version: 0.1.3
 {
+  "CenteredTextSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.CenteredTextSymbolRendererProvider",
+  "SimpleRectangularLikeSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.SimpleRectangularLikeSymbolRendererProvider"
 }
\ No newline at end of file