]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/FilmClass.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / FilmClass.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.elementclass;
13
14 import java.awt.Color;
15 import java.awt.geom.Rectangle2D;
16
17 import org.simantics.g2d.element.ElementClass;
18 import org.simantics.g2d.element.ElementUtils;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.g2d.element.handler.SceneGraph;
21 import org.simantics.g2d.element.handler.impl.DefaultTransform;
22 import org.simantics.g2d.element.handler.impl.FillColorImpl;
23 import org.simantics.g2d.element.handler.impl.Resizeable;
24 import org.simantics.scenegraph.g2d.G2DParentNode;
25 import org.simantics.scenegraph.g2d.nodes.ShapeNode;
26
27 /**
28  * Transparent film
29  * 
30  * @author Toni Kalajainen
31  */
32 public class FilmClass {
33
34         public static final Color FILM_COLOR =
35                 new Color(0.f, 0.f, 0.f, 0.5f);
36         
37         public static final ElementClass FILM_CLASS =
38                 ElementClass.compile(
39                                 DefaultTransform.INSTANCE,
40                                 Resizeable.UNCONSTRICTED,
41                                 //HandleMouseEvent.EVENT_CONSUMER,
42                                 FillColorImpl.handlerOf(FILM_COLOR), 
43                                 new FilmSGNode()
44                                 );
45         
46         static class FilmSGNode implements SceneGraph {
47                 /**
48                  * 
49                  */
50                 private static final long serialVersionUID = -7763377402727204557L;
51                 private ShapeNode node = null;
52                 
53                 @Override
54                 public void cleanup(IElement e) {
55                         if(node != null) {
56                                 node.remove();
57                         }
58                         node = null;
59                 }
60
61                 @Override
62                 public void init(IElement e, G2DParentNode parent) {
63                         if(node == null) {
64                                 node = parent.addNode(ShapeNode.class);
65                         }
66                         Color           fillColor       = ElementUtils.getFillColor(e);                 
67                         Rectangle2D rect                = ElementUtils.getElementBounds(e);             
68                         
69                         node.setColor(fillColor);
70                         node.setFill(true);
71                         node.setShape(rect);
72                 }               
73         }
74         
75 }