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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.image.impl;
\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
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
27 * @author Tuukka Lehtonen
\r
29 public class ShapeImage extends AbstractImage implements Image {
\r
31 private static final EnumSet<Feature> defaultFeats = VECTOR;
\r
36 EnumSet<Feature> feats;
\r
37 boolean scaleStroke = false;
\r
39 public ShapeImage(Shape shape, Paint fill, Stroke stroke) {
\r
40 this(shape, fill, stroke, defaultFeats);
\r
43 public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) {
\r
44 this(shape, fill, stroke, scaleStroke, defaultFeats);
\r
47 public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet<Feature> features) {
\r
48 this(shape, fill, stroke, false, features);
\r
51 public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke, EnumSet<Feature> features) {
\r
54 this.stroke = stroke;
\r
55 this.scaleStroke = scaleStroke;
\r
56 this.feats = features;
\r
60 public Rectangle2D getBounds() {
\r
61 return shape.getBounds2D();
\r
65 public EnumSet<Feature> getFeatures() {
\r
70 public Shape getOutline() {
\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