X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Felements%2FSVGNode.java;h=4d654791925080230f51a9b525cc777a1f7760d7;hp=bccba4aa769ad96ebcc47080187846e4e3f2db22;hb=89ab765d5dd075d172740ffb3d321803558436e9;hpb=7ddecc6d133eff61144784e1b67013a4ed19fc90 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); + } + } + }