GUIComponents now have names
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / wires / WireCrossPoint.java
index 3abf9f7..da0a450 100644 (file)
@@ -1,6 +1,7 @@
 package net.mograsim.logic.ui.model.wires;
 
-import java.util.Map;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
 
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
@@ -9,7 +10,7 @@ import net.mograsim.logic.core.types.BitVectorFormatter;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUIComponent;
-import net.mograsim.logic.ui.model.components.atomic.SimpleRectangularGUIGate;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
 import net.mograsim.preferences.ColorDefinition;
 import net.mograsim.preferences.ColorManager;
 
@@ -22,7 +23,7 @@ import net.mograsim.preferences.ColorManager;
  * 
  * @author Daniel Kirschten
  */
-public class WireCrossPoint extends GUIComponent implements ConnectionPoint
+public class WireCrossPoint extends GUIComponent
 {
        private static final int CIRCLE_RADIUS = 1;
        private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2;
@@ -45,7 +46,12 @@ public class WireCrossPoint extends GUIComponent implements ConnectionPoint
 
        public WireCrossPoint(ViewModelModifiable model, int logicWidth)
        {
-               super(model);
+               this(model, logicWidth, null);
+       }
+
+       public WireCrossPoint(ViewModelModifiable model, int logicWidth, String name)
+       {
+               super(model, name);
                logicObs = (i) -> requestRedraw();
 
                setSize(CIRCLE_DIAM, CIRCLE_DIAM);
@@ -54,7 +60,6 @@ public class WireCrossPoint extends GUIComponent implements ConnectionPoint
 
        // pins
 
-       @Override
        public Pin getPin()
        {
                return pin;
@@ -110,10 +115,14 @@ public class WireCrossPoint extends GUIComponent implements ConnectionPoint
        // serializing
 
        @Override
-       public Map<String, Object> getInstantiationParameters()
+       public JsonElement getParams()
+       {
+               return new JsonPrimitive(pin.logicWidth);
+       }
+
+       static
        {
-               Map<String, Object> m = super.getInstantiationParameters();
-               m.put(SimpleRectangularGUIGate.kLogicWidth, pin.logicWidth);
-               return m;
+               IndirectGUIComponentCreator.setComponentSupplier(WireCrossPoint.class.getCanonicalName(),
+                               (m, p, n) -> new WireCrossPoint(m, p.getAsInt(), n));
        }
 }
\ No newline at end of file