X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FTextComponent.java;h=f2507022f867e766d79b4de9a06e201c45aa4212;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=ec91151d40971f5f2b5f1a16e950df83d7e1be09;hpb=a47c9b1f38bbb6d2f5a3c482f3b09d1f42270401;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java index ec91151d..f2507022 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/TextComponent.java @@ -2,9 +2,6 @@ package net.mograsim.logic.model.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; @@ -12,7 +9,7 @@ import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.NoLogicAdapter; -import net.mograsim.logic.model.serializing.IdentifierGetter; +import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; import net.mograsim.preferences.Preferences; @@ -20,6 +17,7 @@ import net.mograsim.preferences.Preferences; public class TextComponent extends GUIComponent { private final String text; + private boolean calculatedSize; public TextComponent(ViewModelModifiable model, String text) { @@ -38,8 +36,12 @@ public class TextComponent extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - Point textExtent = gc.textExtent(text); - setSize(textExtent.x, textExtent.y); + if (!calculatedSize) + { + calculatedSize = true; + Point textExtent = gc.textExtent(text); + setSize(textExtent.x, textExtent.y); + } Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); if (textColor != null) @@ -50,9 +52,15 @@ public class TextComponent extends GUIComponent // serializing @Override - public JsonElement getParamsForSerializing(IdentifierGetter idGetter) + public String getIDForSerializing(IdentifyParams idParams) + { + return "TextComponent"; + } + + @Override + public String getParamsForSerializing(IdentifyParams idParams) { - return new JsonPrimitive(text); + return text; } static