X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Futils%2FCompoundStroke.java;fp=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Futils%2FCompoundStroke.java;h=3f7c7e4f7f830e92a75a977b33c55920e5a93585;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/CompoundStroke.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/CompoundStroke.java new file mode 100644 index 000000000..3f7c7e4f7 --- /dev/null +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/CompoundStroke.java @@ -0,0 +1,61 @@ +/* +Copyright 2006 Jerry Huxtable + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +package org.simantics.scenegraph.utils; + +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.Area; + +/** + * Taken from http://www.jhlabs.com/java/java2d/strokes/ + */ +public class CompoundStroke implements Stroke { + public final static int ADD = 0; + public final static int SUBTRACT = 1; + public final static int INTERSECT = 2; + public final static int DIFFERENCE = 3; + + private final Stroke stroke1, stroke2; + private final int operation; + + public CompoundStroke( Stroke stroke1, Stroke stroke2, int operation ) { + this.stroke1 = stroke1; + this.stroke2 = stroke2; + this.operation = operation; + } + + @Override + public Shape createStrokedShape( Shape shape ) { + Area area1 = new Area( stroke1.createStrokedShape( shape ) ); + Area area2 = new Area( stroke2.createStrokedShape( shape ) ); + switch ( operation ) { + case ADD: + area1.add( area2 ); + break; + case SUBTRACT: + area1.subtract( area2 ); + break; + case INTERSECT: + area1.intersect( area2 ); + break; + case DIFFERENCE: + area1.exclusiveOr( area2 ); + break; + } + return area1; + } +}