testbench.setOutlineRenderer(new Renderer()
{
@Override
- public Object getParamsForSerializing(IdentifierGetter idGetter)
+ public Void getParamsForSerializing(IdentifierGetter idGetter)
{
return null;
}
public Optional<ComponentInfo> reqCopy(Point refPoint)
{
return Optional.of(new ComponentInfo(parent.getPosX() - refPoint.x, parent.getPosY() - refPoint.y, Editor.getIdentifier(parent),
- parent.getParamsForSerializing(new IdentifierGetter())));
+ parent.getParamsForSerializingJSON(new IdentifierGetter())));
}
@Override
import java.util.Map;
import java.util.function.Consumer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonNull;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.model.model.ViewModelModifiable;
// serializing
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Object getParamsForSerializing(IdentifierGetter idGetter)
{
- return JsonNull.INSTANCE;
+ return null;
}
// listeners
import org.eclipse.swt.graphics.Color;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
static
import org.eclipse.swt.graphics.Color;
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.mograsim.logic.model.modeladapter.componentadapters.ClockAdapter;
import net.mograsim.logic.model.serializing.IdentifierGetter;
import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.util.JsonHandler;
import net.mograsim.preferences.Preferences;
public class GUIClock extends GUIComponent
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public GUIClockParams getParamsForSerializing(IdentifierGetter idGetter)
{
- return new Gson().toJsonTree(params);
+ return params;
}
static
ViewLogicModelAdapter.addComponentAdapter(new ClockAdapter());
IndirectGUIComponentCreator.setComponentSupplier(GUIClock.class.getName(), (m, p, n) ->
{
- GUIClockParams params = new Gson().fromJson(p, GUIClockParams.class);
+ GUIClockParams params = JsonHandler.fromJsonTree(p, GUIClockParams.class);
if (params == null)
throw new JsonSyntaxException("Invalid!!!");
return new GUIClock(m, params, n);
import org.eclipse.swt.graphics.Color;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
static
import org.eclipse.swt.SWT;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.core.types.BitVectorFormatter;
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
public void setLogicModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
import org.eclipse.swt.SWT;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.core.types.BitVectorFormatter;
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
public void setLogicModelBinding(ReadEnd inputEnd, ReadEnd[] outputEnds)
import org.eclipse.swt.graphics.Color;
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.mograsim.logic.model.modeladapter.componentadapters.TriStateBufferAdapter;
import net.mograsim.logic.model.serializing.IdentifierGetter;
import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.util.JsonHandler;
import net.mograsim.preferences.Preferences;
public class GUITriStateBuffer extends GUIComponent
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public GUITriStateBufferParams getParamsForSerializing(IdentifierGetter idGetter)
{
- return new Gson().toJsonTree(params);
+ return params;
}
static
ViewLogicModelAdapter.addComponentAdapter(new TriStateBufferAdapter());
IndirectGUIComponentCreator.setComponentSupplier(GUITriStateBuffer.class.getName(), (m, p, n) ->
{
- GUITriStateBufferParams params = new Gson().fromJson(p, GUITriStateBufferParams.class);
+ GUITriStateBufferParams params = JsonHandler.fromJsonTree(p, GUITriStateBufferParams.class);
if (params == null)
throw new JsonSyntaxException("Invalid!!!");
return new GUITriStateBuffer(m, params, n);
import org.eclipse.swt.graphics.Color;
-import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
* @see GUIComponent#getParamsForSerializing()
*/
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
}
\ No newline at end of file
import org.eclipse.swt.graphics.Color;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
// serializing
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public String getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(text);
+ return text;
}
static
package net.mograsim.logic.model.model.wires;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.core.LogicObserver;
// serializing
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public Integer getParamsForSerializing(IdentifierGetter idGetter)
{
- return new JsonPrimitive(logicWidth);
+ return logicWidth;
}
static
} else
{
innerComponentParams.id = idGetter.componentIDs.apply(innerComponent);
- innerComponentParams.params = innerComponent.getParamsForSerializing(idGetter);
+ innerComponentParams.params = innerComponent.getParamsForSerializingJSON(idGetter);
}
innerComponentParams.name = innerComponent.name;
i1++;
} else
{
compParams.id = idGetter.componentIDs.apply(component);
- compParams.params = component.getParamsForSerializing(idGetter);
+ compParams.params = component.getParamsForSerializingJSON(idGetter);
}
compParams.name = component.name;
}
return parser.fromJson(rawJson, type);
}
+ public static <T> T fromJsonTree(JsonElement src, Class<T> type)
+ {
+ return parser.fromJson(src, type);
+ }
+
public static void writeJson(Object o, String path) throws IOException
{
try (FileWriter writer = new FileWriter(path))
import org.eclipse.swt.graphics.Color;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.model.serializing.IdentifierGetter;
import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.util.JsonHandler;
import net.mograsim.machine.MainMemoryDefinition;
-import net.mograsim.machine.standard.memory.WordAddressableMemoryComponent;
import net.mograsim.preferences.Preferences;
public class GUIMemoryWA extends GUIComponent
{
- private final MainMemoryDefinition definition;
- private final Pin addrPin, dataPin, rWPin;
- private WordAddressableMemoryComponent memory;
- private final static int width = 100, height = 300;
-
- private final static String addrKey = "addrBits", cellWidthKey = "cellWidth", minAddrKey = "minAddr", maxAddrKey = "maxAddr";
+ private final MainMemoryDefinition definition;
+ private final Pin addrPin, dataPin, rWPin;
+ private WordAddressableMemoryComponent memory;
+ private final static int width = 100, height = 300;
public GUIMemoryWA(ViewModelModifiable model, MainMemoryDefinition definition, String name)
{
{
return rWPin;
}
-
+
public void setLogicModelBinding(WordAddressableMemoryComponent memory)
{
this.memory = memory;
}
-
+
public MainMemoryDefinition getDefinition()
{
return definition;
}
-
+
public WordAddressableMemoryComponent getMemory()
{
return memory;
{
// TODO This is copied from SimpleRectangularGUIGate; do this via delegation instead
Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");
- if (foreground != null)
+ if(foreground != null)
gc.setForeground(foreground);
gc.drawRectangle(getPosX(), getPosY(), width, height);
Font oldFont = gc.getFont();
String label = "RAM";
Point textExtent = gc.textExtent(label);
Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");
- if (textColor != null)
+ if(textColor != null)
gc.setForeground(textColor);
gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
gc.setFont(oldFont);
}
@Override
- public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
+ public GUIMemoryWAParams getParamsForSerializing(IdentifierGetter idGetter)
{
- JsonObject o = new JsonObject();
- o.addProperty(addrKey, definition.getMemoryAddressBits());
- o.addProperty(cellWidthKey, definition.getCellWidth());
- o.addProperty(maxAddrKey, definition.getMaximalAddress());
- o.addProperty(minAddrKey, definition.getMinimalAddress());
- return o;
+ GUIMemoryWAParams params = new GUIMemoryWAParams();
+ params.addrBits = definition.getMemoryAddressBits();
+ params.cellWidth = definition.getCellWidth();
+ params.minAddr = definition.getMinimalAddress();
+ params.maxAddr = definition.getMaximalAddress();
+ return params;
}
static
ViewLogicModelAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
IndirectGUIComponentCreator.setComponentSupplier(GUIAndGate.class.getCanonicalName(), (m, p, n) ->
{
- JsonObject o = (JsonObject) p;
- int addressBits = o.get(addrKey).getAsInt();
- int cellWidth = o.get(cellWidthKey).getAsInt();
- long maxAddr = o.get(maxAddrKey).getAsLong();
- long minAddr = o.get(minAddrKey).getAsLong();
- return new GUIMemoryWA(m, MainMemoryDefinition.create(addressBits, cellWidth, minAddr, maxAddr), n);
+ GUIMemoryWAParams params = JsonHandler.fromJsonTree(p, GUIMemoryWAParams.class);
+ return new GUIMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n);
});
}
+
+ public static class GUIMemoryWAParams
+ {
+ public int addrBits;
+ public int cellWidth;
+ public long minAddr;
+ public long maxAddr;
+ }
}