From 01d6a043fc7513dd93853f4fc2a7b326aee1f832 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 20 Feb 2020 11:17:37 +0200 Subject: [PATCH] Added alternative constructor for inputting text scaling factor gitlab #471 Change-Id: Ie1a394e41f4807bc99e0de3cef891730fa27be8e --- .../diagram/elements/TextElementHandler.java | 8 ++++++-- .../diagram/elements/TextElementNoBounds.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementHandler.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementHandler.java index a39ef4f57..192b0ea5d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementHandler.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementHandler.java @@ -52,10 +52,14 @@ public class TextElementHandler extends TextElementNoBounds implements InternalS super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); } + public TextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth, + double paddingX, double paddingY, boolean editable, double scale) { + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable, scale); + } - @Override + @Override public Rectangle2D getBounds(IElement e, Rectangle2D size) { - return calculateBounds(e, size, horizontalAlignment, SCALE, paddingX, paddingY); + return calculateBounds(e, size, horizontalAlignment, scale, paddingX, paddingY); } public static Rectangle2D calculateBounds( diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementNoBounds.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementNoBounds.java index 6959e8c43..376fadc06 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementNoBounds.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementNoBounds.java @@ -49,7 +49,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent { protected static final double DEFAULT_PADDING_X = 0.5; protected static final double DEFAULT_PADDING_Y = 0.5; - protected static final double SCALE = 0.235; + protected static final double DEFAULT_SCALE = 0.235; protected final double originX; protected final double originY; @@ -59,6 +59,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent { protected final boolean editable; protected final double paddingX; protected final double paddingY; + protected final double scale; public TextElementNoBounds() { @@ -74,6 +75,10 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent { } public TextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable) { + this(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable, DEFAULT_SCALE); + } + + public TextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable, double scale) { if (horizontalAlignment == null) throw new NullPointerException("null horizontal alignment"); @@ -85,9 +90,9 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent { this.editable = editable; this.paddingX = paddingX; this.paddingY = paddingY; + this.scale = scale; } - @Override public void init(final IElement e, G2DParentNode parent) { TextNode node = getOrCreateTextNode(e, parent); @@ -102,7 +107,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent { Alignment vAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, verticalAlignment); Double borderWidth = ElementUtils.getHintOrDefault(e, MonitorClass.KEY_BORDER_WIDTH, this.borderWidth); - node.init(text, font, color, originX, originY, SCALE); + node.init(text, font, color, originX, originY, scale); node.setBackgroundColor(fillColor); node.setBorderColor(borderColor); node.setHorizontalAlignment((byte) hAlign.ordinal()); -- 2.47.1