GUIComponents now have names
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / atomic / TextComponent.java
index e1fdc6c..c204dca 100644 (file)
@@ -2,6 +2,9 @@ package net.mograsim.logic.ui.model.components.atomic;
 
 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;
@@ -9,6 +12,7 @@ import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUIComponent;
 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
 import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;
+import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator;
 import net.mograsim.preferences.Preferences;
 
 //TODO clean size calculation mess
@@ -18,7 +22,12 @@ public class TextComponent extends GUIComponent
 
        public TextComponent(ViewModelModifiable model, String text)
        {
-               super(model);
+               this(model, text, null);
+       }
+
+       public TextComponent(ViewModelModifiable model, String text, String name)
+       {
+               super(model, name);
                this.text = text;
                // If size is unset, it defaults to 0, which could prohibit this component from being rendered, which would prohibit the size being
                // set to a better guess
@@ -37,8 +46,18 @@ public class TextComponent extends GUIComponent
                gc.drawText(text, getPosX(), getPosY(), true);
        }
 
+       // serializing
+
+       @Override
+       public JsonElement getParams()
+       {
+               return new JsonPrimitive(text);
+       }
+
        static
        {
                ViewLogicModelAdapter.addComponentAdapter(new NoLogicAdapter<>(TextComponent.class));
+               IndirectGUIComponentCreator.setComponentSupplier(TextComponent.class.getName(),
+                               (m, p, n) -> new TextComponent(m, p.getAsString(), n));
        }
 }