]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/CompoundStroke.java
Removed print
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / utils / CompoundStroke.java
1 /*
2 Copyright 2006 Jerry Huxtable
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15  */
16
17 package org.simantics.scenegraph.utils;
18
19 import java.awt.Shape;
20 import java.awt.Stroke;
21 import java.awt.geom.Area;
22
23 /**
24  * Taken from http://www.jhlabs.com/java/java2d/strokes/
25  */
26 public class CompoundStroke implements Stroke {
27     public final static int ADD = 0;
28     public final static int SUBTRACT = 1;
29     public final static int INTERSECT = 2;
30     public final static int DIFFERENCE = 3;
31
32     private final Stroke stroke1, stroke2;
33     private final int operation;
34
35     public CompoundStroke( Stroke stroke1, Stroke stroke2, int operation ) {
36         this.stroke1 = stroke1;
37         this.stroke2 = stroke2;
38         this.operation = operation;
39     }
40
41     @Override
42     public Shape createStrokedShape( Shape shape ) {
43         Area area1 = new Area( stroke1.createStrokedShape( shape ) );
44         Area area2 = new Area( stroke2.createStrokedShape( shape ) );
45         switch ( operation ) {
46             case ADD:
47                 area1.add( area2 );
48                 break;
49             case SUBTRACT:
50                 area1.subtract( area2 );
51                 break;
52             case INTERSECT:
53                 area1.intersect( area2 );
54                 break;
55             case DIFFERENCE:
56                 area1.exclusiveOr( area2 );
57                 break;
58         }
59         return area1;
60     }
61 }