]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java
Automatically import also SCLMain modules of dependent index roots
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / image / impl / ShapeImage.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.image.impl;
13
14 import java.awt.Color;
15 import java.awt.Paint;
16 import java.awt.Shape;
17 import java.awt.Stroke;
18 import java.awt.geom.Rectangle2D;
19 import java.util.EnumSet;
20
21 import org.simantics.g2d.image.Image;
22 import org.simantics.scenegraph.Node;
23 import org.simantics.scenegraph.g2d.G2DParentNode;
24 import org.simantics.scenegraph.g2d.nodes.ShapeNode;
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public class ShapeImage extends AbstractImage implements Image {
30
31     private static final EnumSet<Feature> defaultFeats = VECTOR;
32
33     Shape shape;
34     Paint paint;
35     Stroke stroke;
36     EnumSet<Feature> feats;
37     boolean scaleStroke = false;
38
39     public ShapeImage(Shape shape, Paint fill, Stroke stroke) {
40         this(shape, fill, stroke, defaultFeats);
41     }
42
43     public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) {
44         this(shape, fill, stroke, scaleStroke, defaultFeats);
45     }
46
47     public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet<Feature> features) {
48         this(shape, fill, stroke, false, features);
49     }
50
51     public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke, EnumSet<Feature> features) {
52         this.shape = shape;
53         this.paint = fill;
54         this.stroke = stroke;
55         this.scaleStroke = scaleStroke;
56         this.feats = features;
57     }
58
59     @Override
60     public Rectangle2D getBounds() {
61         return shape.getBounds2D();
62     }
63
64     @Override
65     public EnumSet<Feature> getFeatures() {
66         return feats;
67     }
68
69     @Override
70     public Shape getOutline() {
71         return shape;
72     }
73
74     @Override
75     public Node init(G2DParentNode parent) {
76         ShapeNode shapeNode = parent.getOrCreateNode("ShapeImage", ShapeNode.class);
77         shapeNode.setShape(shape);
78         shapeNode.setStroke(stroke);
79         shapeNode.setFill(paint != null);
80         shapeNode.setColor(paint != null ? paint : Color.BLACK);
81         shapeNode.setScaleStroke(scaleStroke);
82         return shapeNode;
83     }
84
85 };