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%2FTextNode.java;h=77eb789220d3118e5d8c370c2889b731450e060f;hp=4fe3b51d898183c882b81b1feb14d7abd665ad44;hb=b9331aba5aa5157e581e5038ff401c525ac18305;hpb=e75a2a68817ab088db4f84419c2e988ec83fbd39 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java index 4fe3b51d8..77eb78922 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java @@ -62,7 +62,6 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; -import org.simantics.scenegraph.g2d.events.NodeEventHandler; import org.simantics.scenegraph.g2d.events.command.CommandEvent; import org.simantics.scenegraph.g2d.events.command.Commands; import org.simantics.scenegraph.utils.GeometryUtils; @@ -411,6 +410,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L this.scaleRecip = 1.0 / scale; this.caret = 0; this.selectionTail = 0; + resetCaches(); } @@ -858,6 +858,18 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L protected void renderSelectedHover(Graphics2D g, boolean isSelected, boolean isHovering) { } + public String editText(String text) { + + String error = validator != null ? validator.apply(text) : null; + if (error == null) { + this.text = text; + if (textListener != null) { + textListener.textEditingEnded(); + } + } + return error; + } + /** * Replaces the current selection with the content or inserts * the content at caret. After the insertion the caret @@ -1426,6 +1438,9 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L y += line.layout.getDescent() + line.layout.getLeading() + line.layout.getAscent(); Rectangle2D bbox = line.layout.getLogicalHighlightShape(0, lineText.length()).getBounds2D(); + // HighlightShape is not large enough, if font is italic. + Rectangle2D bbox2 = line.layout.getBounds(); + bbox.add(bbox2); bbox.setFrame(bbox.getX(), bbox.getY() + line.drawPosY, bbox.getWidth(), bbox.getHeight()); line.bbox = bbox; } @@ -1806,7 +1821,6 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L protected boolean mouseDragged(MouseDragBegin e) { if (isHovering() && (isControlDown(e) || isShiftDown(e)) - && e.context instanceof NodeEventHandler && (dataRVI != null || text != null)) { List trs = new ArrayList<>(2);