X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FGUITriStateBuffer.java;fp=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FGUITriStateBuffer.java;h=bfc49d84f0a340dff91ccbb3ae766036d014417d;hb=46f282c4df36a8d734518d6517e05f44a32372bf;hp=75178087704ffb3d08cdb2d2fe3812483941a596;hpb=813aa8a53a4377eb3875752aa3569bdadb971930;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java index 75178087..bfc49d84 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java @@ -2,10 +2,8 @@ package net.mograsim.logic.model.model.components.atomic; import org.eclipse.swt.graphics.Color; +import com.google.gson.Gson; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import net.haspamelodica.swt.helper.gcs.GeneralGC; @@ -27,32 +25,35 @@ public class GUITriStateBuffer extends GUIComponent private Pin input; private Pin output; private Pin enable; - private Orientation orientation; private double[] path; - public GUITriStateBuffer(ViewModelModifiable model, int logicWidth, Orientation orientation) + private GUITriStateBufferParams params; + + public GUITriStateBuffer(ViewModelModifiable model, GUITriStateBufferParams params) { - this(model, logicWidth, orientation, null); + this(model, params, null); } - public GUITriStateBuffer(ViewModelModifiable model, int logicWidth, Orientation orientation, String name) + public GUITriStateBuffer(ViewModelModifiable model, GUITriStateBufferParams params, String name) { super(model, name); - this.orientation = orientation; + this.params = params; double wHalf = width / 2; double hHalf = height / 2; double wQuar = width / 4; double hQuar = height / 4; - int ordi = orientation.ordinal(); + int ordi = params.orientation.ordinal(); int isVerti = (ordi % 4) / 2; int isHori = 1 ^ isVerti; int isAlt = ordi / 4; int isInv = ordi % 2; int isStd = 1 ^ isInv; - this.input = new Pin(this, "IN", logicWidth, width * isInv * isHori + wHalf * isVerti, height * isVerti * isStd + hHalf * isHori); - this.output = new Pin(this, "OUT", logicWidth, width * isStd * isHori + wHalf * isVerti, height * isVerti * isInv + hHalf * isHori); + this.input = new Pin(this, "IN", params.logicWidth, width * isInv * isHori + wHalf * isVerti, + height * isVerti * isStd + hHalf * isHori); + this.output = new Pin(this, "OUT", params.logicWidth, width * isStd * isHori + wHalf * isVerti, + height * isVerti * isInv + hHalf * isHori); this.enable = new Pin(this, "EN", 1, wQuar * isVerti + wHalf * (isAlt | isHori), hQuar * isHori + hHalf * (isAlt | isVerti)); this.path = new double[] { width * (isStd ^ isHori), height * (isStd ^ isHori), width * isInv, height * isStd, width * isStd * isHori + wHalf * isVerti, height * isVerti * isInv + hHalf * isHori }; @@ -86,10 +87,7 @@ public class GUITriStateBuffer extends GUIComponent @Override public JsonElement getParamsForSerializing(IdentifierGetter idGetter) { - JsonObject jo = new JsonObject(); - jo.addProperty("logicWidth", input.logicWidth); - jo.addProperty("orientation", orientation.name()); - return jo; + return new Gson().toJsonTree(params); } static @@ -97,14 +95,19 @@ public class GUITriStateBuffer extends GUIComponent ViewLogicModelAdapter.addComponentAdapter(new TriStateBufferAdapter()); IndirectGUIComponentCreator.setComponentSupplier(GUITriStateBuffer.class.getName(), (m, p, n) -> { - if (!p.isJsonObject()) - throw new JsonSyntaxException("TriStateBuffer Params are not a JsonObject"); - JsonObject jo = p.getAsJsonObject(); - return new GUITriStateBuffer(m, jo.getAsJsonPrimitive("logicWidth").getAsInt(), - Orientation.valueOf(jo.getAsJsonPrimitive("orientation").getAsString()), n); + GUITriStateBufferParams params = new Gson().fromJson(p, GUITriStateBufferParams.class); + if (params == null) + throw new JsonSyntaxException("Invalid!!!"); + return new GUITriStateBuffer(m, params, n); }); } + private static class GUITriStateBufferParams + { + int logicWidth; + Orientation orientation; + } + public enum Orientation { RIGHT, LEFT, UP, DOWN, RIGHT_ALT, LEFT_ALT, UP_ALT, DOWN_ALT;