X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fsnippets%2Fsymbolrenderers%2FSimpleRectangularLikeSymbolRenderer.java;h=d57203ab62563c553592855a6d133c0e4316ba81;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=d31738510fa828ead7e476cd67b9e18258048750;hpb=c5c0d07286a29994a11ba8b01eaffb21964b6c1b;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java index d3173851..d57203ab 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/symbolrenderers/SimpleRectangularLikeSymbolRenderer.java @@ -8,9 +8,9 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; -import net.mograsim.logic.model.model.components.GUIComponent; -import net.mograsim.logic.model.model.components.submodels.SubmodelComponent; +import net.mograsim.logic.model.model.components.ModelComponent; import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.snippets.Renderer; import net.mograsim.logic.model.snippets.SnippetDefinintion; import net.mograsim.logic.model.snippets.SubmodelComponentSnippetSuppliers; @@ -26,13 +26,21 @@ import net.mograsim.preferences.Preferences; */ public class SimpleRectangularLikeSymbolRenderer implements Renderer { - private final GUIComponent component; - private final SimpleRectangularLikeParams params; + private final ModelComponent component; + private final String centerText; + private final double centerTextHeight; + private final double horizontalComponentCenter; + private final double pinLabelHeight; + private final double pinLabelMargin; - public SimpleRectangularLikeSymbolRenderer(SubmodelComponent component, SimpleRectangularLikeParams params) + public SimpleRectangularLikeSymbolRenderer(ModelComponent component, SimpleRectangularLikeParams params) { this.component = component; - this.params = params; + this.centerText = params.centerText; + this.centerTextHeight = params.centerTextHeight; + this.horizontalComponentCenter = params.horizontalComponentCenter; + this.pinLabelHeight = params.pinLabelHeight; + this.pinLabelMargin = params.pinLabelMargin; } @Override @@ -44,13 +52,13 @@ public class SimpleRectangularLikeSymbolRenderer implements Renderer double height = component.getHeight(); Font oldFont = gc.getFont(); - gc.setFont(new Font(oldFont.getName(), params.centerTextHeight, oldFont.getStyle())); - Point textExtent = gc.textExtent(params.centerText); - Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text"); + gc.setFont(new Font(oldFont.getName(), centerTextHeight, oldFont.getStyle())); + Point textExtent = gc.textExtent(centerText); + Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); if (textColor != null) gc.setForeground(textColor); - gc.drawText(params.centerText, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); - gc.setFont(new Font(oldFont.getName(), params.pinLabelHeight, oldFont.getStyle())); + gc.drawText(centerText, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + gc.setFont(new Font(oldFont.getName(), pinLabelHeight, oldFont.getStyle())); for (Entry pinEntry : component.getPins().entrySet()) { String pinName = pinEntry.getKey(); @@ -58,13 +66,30 @@ public class SimpleRectangularLikeSymbolRenderer implements Renderer double pinX = pin.getRelX(); double pinY = posY + pin.getRelY(); textExtent = gc.textExtent(pinName); - gc.drawText(pinName, - posX + pinX + (pinX > params.horizontalComponentCenter ? -textExtent.x - params.pinLabelMargin : params.pinLabelMargin), + gc.drawText(pinName, posX + pinX + (pinX > horizontalComponentCenter ? -textExtent.x - pinLabelMargin : pinLabelMargin), pinY - textExtent.y / 2, true); } gc.setFont(oldFont); } + @Override + public String getIDForSerializing(IdentifyParams idParams) + { + return "simpleRectangularLike"; + } + + @Override + public SimpleRectangularLikeParams getParamsForSerializing(IdentifyParams idParams) + { + SimpleRectangularLikeParams params = new SimpleRectangularLikeParams(); + params.centerText = centerText; + params.centerTextHeight = centerTextHeight; + params.horizontalComponentCenter = horizontalComponentCenter; + params.pinLabelHeight = pinLabelHeight; + params.pinLabelMargin = pinLabelMargin; + return params; + } + public static class SimpleRectangularLikeParams { public String centerText;