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