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.ShapeNode2;
27 * @author Tuukka Lehtonen
29 public class ShapeImage extends AbstractImage implements Image {
31 private static final EnumSet<Feature> defaultFeats = VECTOR;
37 EnumSet<Feature> feats;
38 boolean scaleStroke = false;
40 public ShapeImage(Shape shape, Paint fill, Stroke stroke) {
41 this(shape, fill, stroke, defaultFeats);
44 public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) {
45 this(shape, fill, stroke, fill, scaleStroke, defaultFeats);
48 public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet<Feature> features) {
49 this(shape, fill, stroke, fill, false, features);
51 public ShapeImage(Shape shape, Paint fill, Stroke stroke, Paint strokeColor, boolean scaleStroke) {
52 this(shape, fill, stroke, strokeColor, scaleStroke, defaultFeats);
55 public ShapeImage(Shape shape, Paint fill, Stroke stroke, Paint strokeColor, boolean scaleStroke, EnumSet<Feature> features) {
57 this.fillPaint = fill;
58 this.strokePaint = strokeColor;
60 this.scaleStroke = scaleStroke;
61 this.feats = features;
65 public Rectangle2D getBounds() {
66 return shape.getBounds2D();
70 public EnumSet<Feature> getFeatures() {
75 public Shape getOutline() {
80 public Node init(G2DParentNode parent) {
81 ShapeNode2 shapeNode = parent.getOrCreateNode("ShapeImage", ShapeNode2.class);
82 shapeNode.setShape(shape);
83 shapeNode.setStroke(stroke);
84 shapeNode.setFillColor(fillPaint);
85 shapeNode.setStrokeColor(strokePaint != null ? strokePaint : Color.BLACK);
86 shapeNode.setScaleStroke(scaleStroke);