+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
package org.simantics.diagram.elements;
import java.awt.geom.Point2D;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;
import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
import org.simantics.scl.runtime.function.Function1;
-import org.simantics.scl.runtime.function.Function2;
+import org.simantics.scl.runtime.function.Function3;
+import org.simantics.scl.runtime.tuple.Tuple4;
import com.kitfox.svg.SVGDiagram;
import com.kitfox.svg.SVGElement;
private LinkedList<EditorState> editorState = null;
private int editorStateIndex = 0;
+ static class SVGMeasurementContextImpl implements SVGMeasurementContext {
+ private SVGNode node;
+ public SVGMeasurementContextImpl(SVGNode node) {
+ this.node = node;
+ }
+
+ @Override
+ public Tuple4 getBoundingBox(String id) {
+ try {
+ Rectangle2D rect = node.getElementBounds(id);
+ if(rect == null) return null;
+ return new Tuple4(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
+ } catch (SVGException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void modifyText(String id, String newText) {
+ node.modifyTextElement(id, newText);
+ }
+ }
+
EditorStateManager(SVGNode node) {
this.node = node;
}
String currentText = span.getText();
SingleElementNode sne = node.getSingleElementNode();
+ if (sne == null)
+ return;
+
Function1<String,String> fullTextFunction = sne.getParameter("textEditorFullText");
if(fullTextFunction != null)
es.currentText = fullTextFunction.apply(es.base.textElementId);
void applyEdit() {
SingleElementNode sne = node.getSingleElementNode();
- EditorState es = currentState();
- Function2<String,String,Object> editor = sne.getParameter("textEditor");
- if(editor != null) {
- editor.apply(es.base.textElementId, es.currentText);
+ if (sne != null) {
+ EditorState es = currentState();
+ Function3<SVGMeasurementContext,String,String,Object> editor = sne.getParameter("textEditor");
+ if(editor != null) {
+ editor.apply(new SVGMeasurementContextImpl(node), es.base.textElementId, es.currentText);
+ }
}
}