From 07bf5ce891decbab7673505cf0a1a55ab11855c9 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 8 Sep 2011 07:57:07 +0000 Subject: [PATCH] Use affine transform to move valve name below valve symbol, because node initial transformation parameters have been disabled git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22149 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/elements2/HoverTextElementNoBounds.java | 3 ++- .../sysdyn/ui/elements2/ValveFactory.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java index 1495974b..61a7a398 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java @@ -166,10 +166,11 @@ public class HoverTextElementNoBounds extends TextElementNoBounds { Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); String text = ElementUtils.getText(e); AffineTransform at = ElementUtils.getTransform(e); + Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, horizontalAlignment); node.init(text, font, color, originX, originY, 0.235); node.setBackgroundColor(fillColor); node.setBorderColor(borderColor); - node.setHorizontalAlignment((byte) horizontalAlignment.ordinal()); + node.setHorizontalAlignment((byte) hAlign.ordinal()); node.setPadding(paddingX, paddingY); node.setBorderWidth((float) borderWidth); node.setEditable(editable); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java index 6293a91e..4824b40e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java @@ -19,6 +19,7 @@ import java.awt.geom.Rectangle2D; import java.util.Collection; import org.simantics.db.Resource; +import org.simantics.diagram.elements.TextNode; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.ElementUtils; @@ -112,7 +113,8 @@ public class ValveFactory extends SysdynElementFactory { private IHintListener hoverHintListener; public ValveSceneGraph() { - super(0, VALVE_SIZE + 3.0, Alignment.CENTER); +// super(0, VALVE_SIZE + 3.0, Alignment.CENTER); // Move with affine transformation in init() + super(0, 0, Alignment.CENTER); } @Override public void init(IElement e, G2DParentNode parent) { @@ -128,9 +130,18 @@ public class ValveFactory extends SysdynElementFactory { Boolean hover = e.getHint(ElementHints.KEY_HOVER); node.setHover(hover != null ? hover : false); - if(at != null) + if(at != null) { node.setTransform(at); + // Use affinetransform to move the name of the valve below the valve symbol + TextNode name = (TextNode) e.getHint(SG_NODE); + if(name != null) { + AffineTransform at2 = (AffineTransform) at.clone(); + at2.translate(0, VALVE_SIZE + 3.0); + name.setTransform(at2); + } + } + hoverHintListener = new IHintListener() { @Override -- 2.47.1