01: /*
02: * Copyright 2006 Jerry Huxtable.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
15:
16: package it.businesslogic.ireport.util;
17:
18: /**
19: *
20: * @author gtoffoli
21: */
22: import java.awt.Shape;
23: import java.awt.Stroke;
24: import java.awt.geom.Area;
25:
26: /**
27: * @author Jerry Huxtable
28: * @author Andres Almiray <aalmiray@users.sourceforge.net>
29: */
30: public class CompoundStroke implements Stroke {
31: public final static int ADD = 0;
32: public final static int DIFFERENCE = 3;
33: public final static int INTERSECT = 2;
34: public final static int SUBTRACT = 1;
35:
36: private int operation = ADD;
37: private Stroke stroke1, stroke2;
38:
39: public CompoundStroke() {
40: }
41:
42: public CompoundStroke(Stroke stroke1, Stroke stroke2, int operation) {
43: this .stroke1 = stroke1;
44: this .stroke2 = stroke2;
45: this .operation = operation;
46: }
47:
48: public Shape createStrokedShape(Shape shape) {
49: if (stroke1 == null) {
50: throw new IllegalArgumentException("stroke1 is null");
51: }
52: if (stroke2 == null) {
53: throw new IllegalArgumentException("stroke2 is null");
54: }
55:
56: Area area1 = new Area(stroke1.createStrokedShape(shape));
57: Area area2 = new Area(stroke2.createStrokedShape(shape));
58: switch (operation) {
59: case ADD:
60: area1.add(area2);
61: break;
62: case SUBTRACT:
63: area1.subtract(area2);
64: break;
65: case INTERSECT:
66: area1.intersect(area2);
67: break;
68: case DIFFERENCE:
69: area1.exclusiveOr(area2);
70: break;
71: }
72: return area1;
73: }
74:
75: public int getOperation() {
76: return operation;
77: }
78:
79: public Stroke getStroke1() {
80: return stroke1;
81: }
82:
83: public Stroke getStroke2() {
84: return stroke2;
85: }
86:
87: public void setOperation(int operation) {
88: this .operation = operation;
89: }
90:
91: public void setStroke1(Stroke stroke1) {
92: this .stroke1 = stroke1;
93: }
94:
95: public void setStroke2(Stroke stroke2) {
96: this.stroke2 = stroke2;
97: }
98: }
|