From: Antti Villberg Date: Mon, 2 Oct 2017 13:38:46 +0000 (+0300) Subject: Supply SVG text editor with element measurement context X-Git-Tag: v1.31.0~152 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=89ab765d5dd075d172740ffb3d321803558436e9;p=simantics%2Fplatform.git Supply SVG text editor with element measurement context refs #7520 Change-Id: Iea98f28077efb628fee588df4d8cab64906add30 --- diff --git a/bundles/org.simantics.diagram/scl/Simantics/Diagram/SVGNode.scl b/bundles/org.simantics.diagram/scl/Simantics/Diagram/SVGNode.scl index 9c5d43c4f..25aa798b1 100644 --- a/bundles/org.simantics.diagram/scl/Simantics/Diagram/SVGNode.scl +++ b/bundles/org.simantics.diagram/scl/Simantics/Diagram/SVGNode.scl @@ -4,6 +4,7 @@ type BoundingBox = (Double,Double,Double,Double) importJava "org.simantics.diagram.elements.SVGMeasurementContext" where data SVGMeasurementContext getBoundingBox :: SVGMeasurementContext -> String -> Maybe BoundingBox + modifyText :: SVGMeasurementContext -> String -> String -> () getBoundingBoxX :: BoundingBox -> Double getBoundingBoxX (x,_,_,_) = x diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java index 1223d8eaf..bc01793cd 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java @@ -53,6 +53,7 @@ class EditorStateManager { public SVGMeasurementContextImpl(SVGNode node) { this.node = node; } + @Override public Tuple4 getBoundingBox(String id) { try { @@ -63,6 +64,11 @@ class EditorStateManager { return null; } } + + @Override + public void modifyText(String id, String newText) { + node.modifyTextElement(id, newText); + } } EditorStateManager(SVGNode node) { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGMeasurementContext.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGMeasurementContext.java index 19175a833..70030a561 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGMeasurementContext.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGMeasurementContext.java @@ -19,4 +19,5 @@ import org.simantics.scl.runtime.tuple.Tuple4; */ public interface SVGMeasurementContext { Tuple4 getBoundingBox(String id); + void modifyText(String id, String newText); } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java index bccba4aa7..4d6547919 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2017 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -28,13 +28,19 @@ import org.simantics.scenegraph.g2d.events.command.CommandEvent; import org.simantics.scenegraph.g2d.nodes.SVGNodeAssignment; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; import org.simantics.scenegraph.utils.NodeUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.kitfox.svg.SVGDiagram; import com.kitfox.svg.SVGException; +import com.kitfox.svg.Text; +import com.kitfox.svg.Tspan; @RasterOutputWidget public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode { + private static final Logger LOGGER = LoggerFactory.getLogger(SVGNode.class); + private static final long serialVersionUID = 4735066193941274186L; transient EditorStateManager esm = null; @@ -150,4 +156,22 @@ public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode { return EventTypes.KeyPressedMask | EventTypes.MouseClickMask | EventTypes.CommandMask; } + public void modifyTextElement(String id, String newText) { + Text text = (Text) diagramCache.getElement(id); + + EditorState es = new EditorState(); + es.base = new EditorStateStatic(); + es.base.textElementId = text.getId(); + + Tspan span = (Tspan)text.getContent().get(0); + + try { + span.setText(newText); + text.rebuild(); + diagramCache.updateTime(0); + } catch (SVGException e) { + LOGGER.error("Failed to update text span element " + id + " with text " + newText, e); + } + } + }