1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.spreadsheet.ui;
\r
13 import java.awt.Shape;
\r
14 import java.awt.geom.Rectangle2D;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.g2d.element.ElementClass;
\r
18 import org.simantics.g2d.element.ElementHints;
\r
19 import org.simantics.g2d.element.ElementUtils;
\r
20 import org.simantics.g2d.element.IElement;
\r
21 import org.simantics.g2d.element.SceneGraphNodeKey;
\r
22 import org.simantics.g2d.element.handler.InternalSize;
\r
23 import org.simantics.g2d.element.handler.Outline;
\r
24 import org.simantics.g2d.element.handler.SceneGraph;
\r
25 import org.simantics.g2d.element.handler.impl.BorderColorImpl;
\r
26 import org.simantics.g2d.element.handler.impl.DefaultTransform;
\r
27 import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
\r
28 import org.simantics.scenegraph.Node;
\r
29 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
30 import org.simantics.spreadsheet.Adaptable;
\r
31 import org.simantics.utils.datastructures.Callback;
\r
32 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
33 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
36 * @author Antti Villberg
\r
38 public class SheetClass {
\r
40 public static final Key KEY_SERVER_INTERFACE = new KeyOf(Adaptable.class, "SERVER_INTERFACE");
\r
42 public static final Key KEY_SHEET = new KeyOf(Resource.class, "SHEET");
\r
43 public static final Key KEY_RVI = new KeyOf(String.class, "RVI");
\r
44 public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE");
\r
46 public static class SheetSGNode implements SceneGraph, InternalSize, Outline {
\r
48 private static final long serialVersionUID = -5823585015844593347L;
\r
50 static final SheetSGNode INSTANCE = new SheetSGNode();
\r
53 public void init(final IElement e, final G2DParentNode parent) {
\r
55 // Create node if it doesn't exist yet
\r
56 SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);
\r
57 if(node == null || node.getBounds() == null || node.getParent() != parent) {
\r
59 node = parent.addNode(ElementUtils.generateNodeId(e), SheetNode.class);
\r
61 e.setHint(KEY_SG_NODE, node);
\r
63 Adaptable serverInterface = e.getHint(KEY_SERVER_INTERFACE);
\r
64 node.init(serverInterface);
\r
66 Callback<Node> callback = e.getHint(ElementHints.KEY_SG_CALLBACK);
\r
67 if(callback != null)
\r
70 System.out.println("SHEET PARENT NODE: " + parent);
\r
71 node.setBounds(new Rectangle2D.Double(0, 0, 400, 200));
\r
79 public void update(IElement e) {
\r
83 public void cleanup(IElement e) {
\r
84 SheetNode node = (SheetNode)e.removeHint(KEY_SG_NODE);
\r
90 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
\r
91 Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0);
\r
93 SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);
\r
94 if(node != null && node.getBounds() != null) {
\r
95 shape = node.getBounds().getBounds2D();
\r
98 if(size != null) size.setRect(shape);
\r
103 public Shape getElementShape(IElement e) {
\r
104 Shape shape = new Rectangle2D.Double(0, 0, 0, 0);
\r
106 SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE);
\r
107 if(node != null && node.getBounds() != null) {
\r
108 shape = node.getBounds();
\r
117 public static final ElementClass INSTANCE =
\r
118 ElementClass.compile(
\r
119 DefaultTransform.INSTANCE,
\r
120 BorderColorImpl.BLACK,
\r
121 SheetSGNode.INSTANCE,
\r
122 SimpleElementLayers.INSTANCE
\r