X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FSimpleRectangularGUIGate.java;h=9b72cb6c10cc632285b9fc98734e565244428e84;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=c7c26072f6ccdfc52d33988c66d2f327e9c2f7a9;hpb=47ea68ed5c444dd14864412639f6a6fd60ab8a0f;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java index c7c26072..9b72cb6c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularGUIGate.java @@ -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 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); } @@ -67,7 +71,7 @@ public class SimpleRectangularGUIGate extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground"); + Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground"); if (foreground != null) gc.setForeground(foreground); double height = (getPins().size() - 1) * pinDistance; @@ -78,7 +82,7 @@ public class SimpleRectangularGUIGate extends GUIComponent Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text"); + Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); if (textColor != null) gc.setForeground(textColor); gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); @@ -87,15 +91,21 @@ 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. * - * @see GUIComponent#getParams() + * @see GUIComponent#getParamsForSerializing() */ @Override - public JsonElement getParams() + public Integer getParamsForSerializing(IdentifyParams idParams) { - return new JsonPrimitive(logicWidth); + return logicWidth; } } \ No newline at end of file