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.ui.model.ViewModelModifiable;
*/
public abstract void render(GeneralGC gc, Rectangle visibleRegion);
+ // serializing
+
+ @SuppressWarnings("static-method") // this method is intended to be overridden
+ public JsonElement getParams()
+ {
+ return JsonNull.INSTANCE;
+ }
+
// listeners
/**
import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.SimpleGateAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
public class GUIAndGate extends SimpleRectangularGUIGate
{
static
{
ViewLogicModelAdapter.addComponentAdapter(new SimpleGateAdapter<>(GUIAndGate.class, AndGate::new));
+ IndirectGUIComponentCreator.setComponentProvider(GUIAndGate.class.getCanonicalName(), (m, p) -> new GUIAndGate(m, p.getAsInt()));
}
}
\ No newline at end of file
import net.mograsim.logic.ui.model.wires.Pin;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.BitDisplayAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
import net.mograsim.preferences.Preferences;
public class GUIBitDisplay extends GUIComponent
static
{
ViewLogicModelAdapter.addComponentAdapter(new BitDisplayAdapter());
+ IndirectGUIComponentCreator.setComponentProvider(GUIBitDisplay.class.getCanonicalName(), (m, p) -> new GUIBitDisplay(m));
}
}
\ No newline at end of file
import net.mograsim.logic.ui.model.wires.Pin;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.ManualSwitchAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
import net.mograsim.preferences.Preferences;
public class GUIManualSwitch extends GUIComponent
static
{
ViewLogicModelAdapter.addComponentAdapter(new ManualSwitchAdapter());
+ IndirectGUIComponentCreator.setComponentProvider(GUIManualSwitch.class.getName(), (m, p) -> new GUIManualSwitch(m));
}
}
\ No newline at end of file
static
{
ViewLogicModelAdapter.addComponentAdapter(new SimpleGateAdapter<>(GUINandGate.class, NandGate::new));
- // TODO read params
- IndirectGUIComponentCreator.setComponentProvider(GUINandGate.class.getCanonicalName(), (m, p) -> new GUINandGate(m, 1));
+ IndirectGUIComponentCreator.setComponentProvider(GUINandGate.class.getCanonicalName(), (m, p) -> new GUINandGate(m, p.getAsInt()));
}
}
\ No newline at end of file
import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.SimpleGateAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
public class GUINotGate extends SimpleRectangularGUIGate
{
static
{
ViewLogicModelAdapter.addComponentAdapter(new SimpleGateAdapter<>(GUINotGate.class, (t, p, o, i) -> new NotGate(t, p, i[0], o)));
+ IndirectGUIComponentCreator.setComponentProvider(GUINotGate.class.getCanonicalName(), (m, p) -> new GUINotGate(m, p.getAsInt()));
}
}
\ No newline at end of file
import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.SimpleGateAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
public class GUIOrGate extends SimpleRectangularGUIGate
{
static
{
ViewLogicModelAdapter.addComponentAdapter(new SimpleGateAdapter<>(GUIOrGate.class, OrGate::new));
+ IndirectGUIComponentCreator.setComponentProvider(GUIOrGate.class.getCanonicalName(), (m, p) -> new GUIOrGate(m, p.getAsInt()));
}
}
\ 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.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
private MovablePin outputPin;
private final List<Pin> inputPins;
- public static final String kLogicWidth = "logicWidth";
-
protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted)
{
super(model);
gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
gc.setFont(oldFont);
}
+
+ // serializing
+
+ /**
+ * {@link SimpleRectangularGUIGate}s implementation returns a {@link JsonPrimitive} of type int containing the {@link #logicWidth} of
+ * this component.
+ *
+ * @see GUIComponent#getParams()
+ */
+ @Override
+ public JsonElement getParams()
+ {
+ return new JsonPrimitive(logicWidth);
+ }
}
\ No newline at end of file
\r
import org.eclipse.swt.graphics.Color;\r
\r
+import com.google.gson.JsonElement;\r
+import com.google.gson.JsonPrimitive;\r
+\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;\r
import net.mograsim.logic.ui.model.components.GUIComponent;\r
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;\r
import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;\r
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;\r
import net.mograsim.preferences.Preferences;\r
\r
//TODO clean size calculation mess\r
gc.drawText(text, getPosX(), getPosY(), true);\r
}\r
\r
+ // serializing\r
+\r
+ @Override\r
+ public JsonElement getParams()\r
+ {\r
+ return new JsonPrimitive(text);\r
+ }\r
+\r
static\r
{\r
ViewLogicModelAdapter.addComponentAdapter(new NoLogicAdapter<>(TextComponent.class));\r
+ IndirectGUIComponentCreator.setComponentProvider(TextComponent.class.getName(), (m, p) -> new TextComponent(m, p.getAsString()));\r
}\r
}\r
public class SimpleRectangularSubmodelComponent extends SubmodelComponent
{
- public static String kLabel = "label", kInCount = "input_count", kOutCount = "output_count", kLogicWidth = "logic_width";
-
private static final double width = 35;
private static final double pinDistance = 10;
private static final double pinNameMargin = .5;
return false;
}
- // serializing; TODO move to serializing classes
+ // serializing
+
+ // TODO move the methods below to serializing classes
public SubmodelComponentParams calculateParams()
{
comps[i] = inner;
inner.pos = new Point(component.getPosX(), component.getPosY());
inner.id = getIdentifier.apply(component);
+ inner.params = component.getParams();
i++;
}
params.subComps = comps;
package net.mograsim.logic.ui.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;
return end != null;
}
+ // serializing
+
+ @Override
+ public JsonElement getParams()
+ {
+ return new JsonPrimitive(pin.logicWidth);
+ }
+
static
{
- // TODO read params
- IndirectGUIComponentCreator.setComponentProvider(WireCrossPoint.class.getCanonicalName(), (m, p) -> new WireCrossPoint(m, 1));
+ IndirectGUIComponentCreator.setComponentProvider(WireCrossPoint.class.getCanonicalName(),
+ (m, p) -> new WireCrossPoint(m, p.getAsInt()));
}
}
\ No newline at end of file