Renamed core components to have the common prefix Core
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / atomic / SimpleRectangularGUIGate.java
index b14aaec..9b72cb6 100644 (file)
@@ -5,7 +5,6 @@ import java.util.List;
 
 import org.eclipse.swt.graphics.Color;
 
-import com.google.gson.JsonElement;
 import com.google.gson.JsonPrimitive;
 
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
@@ -16,6 +15,8 @@ import net.mograsim.logic.model.model.ViewModelModifiable;
 import net.mograsim.logic.model.model.components.GUIComponent;
 import net.mograsim.logic.model.model.wires.MovablePin;
 import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.PinUsage;
+import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.preferences.Preferences;
 
 public class SimpleRectangularGUIGate extends GUIComponent
@@ -25,6 +26,8 @@ public class SimpleRectangularGUIGate extends GUIComponent
        private static final double fontHeight = 5;
        private static final double invertedCircleDiam = 3.5;
 
+       private final String id;
+
        private final String label;
        private final boolean isInverted;
        protected final int logicWidth;
@@ -33,14 +36,15 @@ public class SimpleRectangularGUIGate extends GUIComponent
        private MovablePin outputPin;
        private final List<Pin> inputPins;
 
-       protected SimpleRectangularGUIGate(ViewModelModifiable model, String label, boolean isInverted, int logicWidth, String name)
+       protected SimpleRectangularGUIGate(ViewModelModifiable model, String id, String label, boolean isInverted, int logicWidth, String name)
        {
                super(model, name);
+               this.id = id;
                this.label = label;
                this.logicWidth = logicWidth;
                this.isInverted = isInverted;
                this.rectWidth = width - (isInverted ? invertedCircleDiam : 0);
-               this.outputPin = new MovablePin(this, "Y", logicWidth, width, 0);
+               this.outputPin = new MovablePin(this, "Y", logicWidth, PinUsage.OUTPUT, width, 0);
                addPin(outputPin);
                this.inputPins = new ArrayList<>();
                setInputCount(1);
@@ -57,7 +61,7 @@ public class SimpleRectangularGUIGate extends GUIComponent
                        for (int i = oldInputCount; i < inputCount; i++)
                        {
                                // TODO what for more than 24 input pins?
-                               Pin pin = new Pin(this, String.valueOf((char) ('A' + i)), logicWidth, 0, pinDistance / 2 + i * pinDistance);
+                               Pin pin = new Pin(this, String.valueOf((char) ('A' + i)), logicWidth, PinUsage.INPUT, 0, pinDistance / 2 + i * pinDistance);
                                inputPins.add(pin);
                                addPin(pin);
                        }
@@ -87,6 +91,12 @@ public class SimpleRectangularGUIGate extends GUIComponent
 
        // serializing
 
+       @Override
+       public String getIDForSerializing(IdentifyParams idParams)
+       {
+               return id;
+       }
+
        /**
         * {@link SimpleRectangularGUIGate}s implementation returns a {@link JsonPrimitive} of type int containing the {@link #logicWidth} of
         * this component.
@@ -94,8 +104,8 @@ public class SimpleRectangularGUIGate extends GUIComponent
         * @see GUIComponent#getParamsForSerializing()
         */
        @Override
-       public JsonElement getParamsForSerializing()
+       public Integer getParamsForSerializing(IdentifyParams idParams)
        {
-               return new JsonPrimitive(logicWidth);
+               return logicWidth;
        }
 }
\ No newline at end of file