X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fimage%2Fimpl%2FShapeImage.java;h=90ceaa12af567f4d1f217bd35131b11c47bd6a9b;hp=18951c18a6f1669fc2f90b2fd12b3670ee34e007;hb=63adbfeaca69de231d77724366647ecea9d74bd8;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java index 18951c18a..90ceaa12a 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/ShapeImage.java @@ -1,85 +1,90 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.image.impl; - -import java.awt.Color; -import java.awt.Paint; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.geom.Rectangle2D; -import java.util.EnumSet; - -import org.simantics.g2d.image.Image; -import org.simantics.scenegraph.Node; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.g2d.nodes.ShapeNode; - -/** - * @author Tuukka Lehtonen - */ -public class ShapeImage extends AbstractImage implements Image { - - private static final EnumSet defaultFeats = VECTOR; - - Shape shape; - Paint paint; - Stroke stroke; - EnumSet feats; - boolean scaleStroke = false; - - public ShapeImage(Shape shape, Paint fill, Stroke stroke) { - this(shape, fill, stroke, defaultFeats); - } - - public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) { - this(shape, fill, stroke, scaleStroke, defaultFeats); - } - - public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet features) { - this(shape, fill, stroke, false, features); - } - - public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke, EnumSet features) { - this.shape = shape; - this.paint = fill; - this.stroke = stroke; - this.scaleStroke = scaleStroke; - this.feats = features; - } - - @Override - public Rectangle2D getBounds() { - return shape.getBounds2D(); - } - - @Override - public EnumSet getFeatures() { - return feats; - } - - @Override - public Shape getOutline() { - return shape; - } - - @Override - public Node init(G2DParentNode parent) { - ShapeNode shapeNode = parent.getOrCreateNode("ShapeImage", ShapeNode.class); - shapeNode.setShape(shape); - shapeNode.setStroke(stroke); - shapeNode.setFill(paint != null); - shapeNode.setColor(paint != null ? paint : Color.BLACK); - shapeNode.setScaleStroke(scaleStroke); - return shapeNode; - } - -}; +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.image.impl; + +import java.awt.Color; +import java.awt.Paint; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.Rectangle2D; +import java.util.EnumSet; + +import org.simantics.g2d.image.Image; +import org.simantics.scenegraph.Node; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.ShapeNode2; + +/** + * @author Tuukka Lehtonen + */ +public class ShapeImage extends AbstractImage implements Image { + + private static final EnumSet defaultFeats = VECTOR; + + Shape shape; + Paint fillPaint; + Paint strokePaint; + Stroke stroke; + EnumSet feats; + boolean scaleStroke = false; + + public ShapeImage(Shape shape, Paint fill, Stroke stroke) { + this(shape, fill, stroke, defaultFeats); + } + + public ShapeImage(Shape shape, Paint fill, Stroke stroke, boolean scaleStroke) { + this(shape, fill, stroke, fill, scaleStroke, defaultFeats); + } + + public ShapeImage(Shape shape, Paint fill, Stroke stroke, EnumSet features) { + this(shape, fill, stroke, fill, false, features); + } + public ShapeImage(Shape shape, Paint fill, Stroke stroke, Paint strokeColor, boolean scaleStroke) { + this(shape, fill, stroke, strokeColor, scaleStroke, defaultFeats); + } + + public ShapeImage(Shape shape, Paint fill, Stroke stroke, Paint strokeColor, boolean scaleStroke, EnumSet features) { + this.shape = shape; + this.fillPaint = fill; + this.strokePaint = strokeColor; + this.stroke = stroke; + this.scaleStroke = scaleStroke; + this.feats = features; + } + + @Override + public Rectangle2D getBounds() { + return shape.getBounds2D(); + } + + @Override + public EnumSet getFeatures() { + return feats; + } + + @Override + public Shape getOutline() { + return shape; + } + + @Override + public Node init(G2DParentNode parent) { + ShapeNode2 shapeNode = parent.getOrCreateNode("ShapeImage", ShapeNode2.class); + shapeNode.setShape(shape); + shapeNode.setStroke(stroke); + shapeNode.setFillColor(fillPaint); + shapeNode.setStrokeColor(strokePaint != null ? strokePaint : Color.BLACK); + shapeNode.setScaleStroke(scaleStroke); + return shapeNode; + } + +};