]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / image / impl / ShapeImage.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.image.impl;\r
13 \r
14 import java.awt.Color;\r
15 import java.awt.Paint;\r
16 import java.awt.Shape;\r
17 import java.awt.Stroke;\r
18 import java.awt.geom.Rectangle2D;\r
19 import java.util.EnumSet;\r
20 \r
21 import org.simantics.g2d.image.Image;\r
22 import org.simantics.scenegraph.Node;\r
23 import org.simantics.scenegraph.g2d.G2DParentNode;\r
24 import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
25 \r
26 /**\r
27  * @author Tuukka Lehtonen\r
28  */\r
29 public class ShapeImage extends AbstractImage implements Image {\r
30 \r
31     private static final EnumSet<Feature> defaultFeats = VECTOR;\r
32 \r
33     Shape shape;\r
34     Paint paint;\r
35     Stroke stroke;\r
36     EnumSet<Feature> feats;\r
37     boolean scaleStroke = false;\r
38 \r
39     public ShapeImage(Shape shape, Paint fill, Stroke stroke) {\r
40         this(shape, fill, stroke, defaultFeats);\r
41     }\r
42 \r
43     public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) {\r
44         this(shape, fill, stroke, scaleStroke, defaultFeats);\r
45     }\r
46 \r
47     public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet<Feature> features) {\r
48         this(shape, fill, stroke, false, features);\r
49     }\r
50 \r
51     public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke, EnumSet<Feature> features) {\r
52         this.shape = shape;\r
53         this.paint = fill;\r
54         this.stroke = stroke;\r
55         this.scaleStroke = scaleStroke;\r
56         this.feats = features;\r
57     }\r
58 \r
59     @Override\r
60     public Rectangle2D getBounds() {\r
61         return shape.getBounds2D();\r
62     }\r
63 \r
64     @Override\r
65     public EnumSet<Feature> getFeatures() {\r
66         return feats;\r
67     }\r
68 \r
69     @Override\r
70     public Shape getOutline() {\r
71         return shape;\r
72     }\r
73 \r
74     @Override\r
75     public Node init(G2DParentNode parent) {\r
76         ShapeNode shapeNode = parent.getOrCreateNode("ShapeImage", ShapeNode.class);\r
77         shapeNode.setShape(shape);\r
78         shapeNode.setStroke(stroke);\r
79         shapeNode.setFill(paint != null);\r
80         shapeNode.setColor(paint != null ? paint : Color.BLACK);\r
81         shapeNode.setScaleStroke(scaleStroke);\r
82         return shapeNode;\r
83     }\r
84 \r
85 };\r