X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.ui%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fui%2FSheetClass.java;h=1df4a90e54c045f902845db5d8144f06e2047734;hp=7c9cd844fb2d49e46b038eff9aa218181cd22e3d;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetClass.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetClass.java index 7c9cd844f..1df4a90e5 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetClass.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetClass.java @@ -1,125 +1,125 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.spreadsheet.ui; - -import java.awt.Shape; -import java.awt.geom.Rectangle2D; - -import org.simantics.db.Resource; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.ElementHints; -import org.simantics.g2d.element.ElementUtils; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.SceneGraphNodeKey; -import org.simantics.g2d.element.handler.InternalSize; -import org.simantics.g2d.element.handler.Outline; -import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.g2d.element.handler.impl.BorderColorImpl; -import org.simantics.g2d.element.handler.impl.DefaultTransform; -import org.simantics.g2d.element.handler.impl.SimpleElementLayers; -import org.simantics.scenegraph.Node; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.spreadsheet.Adaptable; -import org.simantics.utils.datastructures.Callback; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; - -/** - * @author Antti Villberg - */ -public class SheetClass { - - public static final Key KEY_SERVER_INTERFACE = new KeyOf(Adaptable.class, "SERVER_INTERFACE"); - - public static final Key KEY_SHEET = new KeyOf(Resource.class, "SHEET"); - public static final Key KEY_RVI = new KeyOf(String.class, "RVI"); - public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE"); - - public static class SheetSGNode implements SceneGraph, InternalSize, Outline { - - private static final long serialVersionUID = -5823585015844593347L; - - static final SheetSGNode INSTANCE = new SheetSGNode(); - - @Override - public void init(final IElement e, final G2DParentNode parent) { - - // Create node if it doesn't exist yet - SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); - if(node == null || node.getBounds() == null || node.getParent() != parent) { - - node = parent.addNode(ElementUtils.generateNodeId(e), SheetNode.class); - - e.setHint(KEY_SG_NODE, node); - - Adaptable serverInterface = e.getHint(KEY_SERVER_INTERFACE); - node.init(serverInterface); - - Callback callback = e.getHint(ElementHints.KEY_SG_CALLBACK); - if(callback != null) - callback.run(node); - - System.out.println("SHEET PARENT NODE: " + parent); - node.setBounds(new Rectangle2D.Double(0, 0, 400, 200)); - - } - - update(e); - - } - - public void update(IElement e) { - } - - @Override - public void cleanup(IElement e) { - SheetNode node = (SheetNode)e.removeHint(KEY_SG_NODE); - if (node != null) - node.remove(); - } - - @Override - public Rectangle2D getBounds(IElement e, Rectangle2D size) { - Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0); - - SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); - if(node != null && node.getBounds() != null) { - shape = node.getBounds().getBounds2D(); - } - - if(size != null) size.setRect(shape); - return shape; - } - - @Override - public Shape getElementShape(IElement e) { - Shape shape = new Rectangle2D.Double(0, 0, 0, 0); - - SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); - if(node != null && node.getBounds() != null) { - shape = node.getBounds(); - } - - return shape; - } - - } - - - public static final ElementClass INSTANCE = - ElementClass.compile( - DefaultTransform.INSTANCE, - BorderColorImpl.BLACK, - SheetSGNode.INSTANCE, - SimpleElementLayers.INSTANCE - ); - -} +/******************************************************************************* + * Copyright (c) 2007- VTT Technical Research Centre of Finland. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.spreadsheet.ui; + +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.simantics.db.Resource; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.Outline; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.element.handler.impl.BorderColorImpl; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.scenegraph.Node; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.spreadsheet.Adaptable; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +/** + * @author Antti Villberg + */ +public class SheetClass { + + public static final Key KEY_SERVER_INTERFACE = new KeyOf(Adaptable.class, "SERVER_INTERFACE"); + + public static final Key KEY_SHEET = new KeyOf(Resource.class, "SHEET"); + public static final Key KEY_RVI = new KeyOf(String.class, "RVI"); + public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE"); + + public static class SheetSGNode implements SceneGraph, InternalSize, Outline { + + private static final long serialVersionUID = -5823585015844593347L; + + static final SheetSGNode INSTANCE = new SheetSGNode(); + + @Override + public void init(final IElement e, final G2DParentNode parent) { + + // Create node if it doesn't exist yet + SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); + if(node == null || node.getBounds() == null || node.getParent() != parent) { + + node = parent.addNode(ElementUtils.generateNodeId(e), SheetNode.class); + + e.setHint(KEY_SG_NODE, node); + + Adaptable serverInterface = e.getHint(KEY_SERVER_INTERFACE); + node.init(serverInterface); + + Callback callback = e.getHint(ElementHints.KEY_SG_CALLBACK); + if(callback != null) + callback.run(node); + + System.out.println("SHEET PARENT NODE: " + parent); + node.setBounds(new Rectangle2D.Double(0, 0, 400, 200)); + + } + + update(e); + + } + + public void update(IElement e) { + } + + @Override + public void cleanup(IElement e) { + SheetNode node = (SheetNode)e.removeHint(KEY_SG_NODE); + if (node != null) + node.remove(); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0); + + SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); + if(node != null && node.getBounds() != null) { + shape = node.getBounds().getBounds2D(); + } + + if(size != null) size.setRect(shape); + return shape; + } + + @Override + public Shape getElementShape(IElement e) { + Shape shape = new Rectangle2D.Double(0, 0, 0, 0); + + SheetNode node = (SheetNode)e.getHint(KEY_SG_NODE); + if(node != null && node.getBounds() != null) { + shape = node.getBounds(); + } + + return shape; + } + + } + + + public static final ElementClass INSTANCE = + ElementClass.compile( + DefaultTransform.INSTANCE, + BorderColorImpl.BLACK, + SheetSGNode.INSTANCE, + SimpleElementLayers.INSTANCE + ); + +}