--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.spreadsheet.ui;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.element.handler.Outline;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.impl.BorderColorImpl;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
+import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
+import org.simantics.scenegraph.Node;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.spreadsheet.Adaptable;\r
+import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+/**\r
+ * @author Antti Villberg\r
+ */\r
+public class SheetClass {\r
+\r
+ public static final Key KEY_SERVER_INTERFACE = new KeyOf(Adaptable.class, "SERVER_INTERFACE");\r
+\r
+ public static final Key KEY_SHEET = new KeyOf(Resource.class, "SHEET");\r
+ public static final Key KEY_RVI = new KeyOf(String.class, "RVI");\r
+ public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE");\r
+\r
+ public static class SheetSGNode implements SceneGraph, InternalSize, Outline {\r
+\r
+ private static final long serialVersionUID = -5823585015844593347L;\r
+\r
+ static final SheetSGNode INSTANCE = new SheetSGNode();\r
+\r
+ @Override\r
+ public void init(final IElement e, final G2DParentNode parent) {\r
+\r
+ // Create node if it doesn't exist yet\r
+ SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);\r
+ if(node == null || node.getBounds() == null || node.getParent() != parent) {\r
+\r
+ node = parent.addNode(ElementUtils.generateNodeId(e), SheetNode.class);\r
+\r
+ e.setHint(KEY_SG_NODE, node);\r
+\r
+ Adaptable serverInterface = e.getHint(KEY_SERVER_INTERFACE);\r
+ node.init(serverInterface);\r
+\r
+ Callback<Node> callback = e.getHint(ElementHints.KEY_SG_CALLBACK);\r
+ if(callback != null)\r
+ callback.run(node);\r
+\r
+ System.out.println("SHEET PARENT NODE: " + parent);\r
+ node.setBounds(new Rectangle2D.Double(0, 0, 400, 200));\r
+\r
+ }\r
+\r
+ update(e);\r
+\r
+ }\r
+\r
+ public void update(IElement e) {\r
+ }\r
+\r
+ @Override\r
+ public void cleanup(IElement e) {\r
+ SheetNode node = (SheetNode)e.removeHint(KEY_SG_NODE);\r
+ if (node != null)\r
+ node.remove();\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+ Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0);\r
+\r
+ SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);\r
+ if(node != null && node.getBounds() != null) {\r
+ shape = node.getBounds().getBounds2D();\r
+ }\r
+\r
+ if(size != null) size.setRect(shape);\r
+ return shape;\r
+ }\r
+\r
+ @Override\r
+ public Shape getElementShape(IElement e) {\r
+ Shape shape = new Rectangle2D.Double(0, 0, 0, 0);\r
+\r
+ SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);\r
+ if(node != null && node.getBounds() != null) {\r
+ shape = node.getBounds();\r
+ }\r
+\r
+ return shape;\r
+ }\r
+\r
+ }\r
+\r
+\r
+ public static final ElementClass INSTANCE =\r
+ ElementClass.compile(\r
+ DefaultTransform.INSTANCE,\r
+ BorderColorImpl.BLACK,\r
+ SheetSGNode.INSTANCE,\r
+ SimpleElementLayers.INSTANCE\r
+ );\r
+\r
+}\r