01: /*
02: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
03: * http://www.jaspersoft.com.
04: *
05: * Unless you have purchased a commercial license agreement from JasperSoft,
06: * the following license terms apply:
07: *
08: * This program is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU General Public License version 2 as published by
10: * the Free Software Foundation.
11: *
12: * This program is distributed WITHOUT ANY WARRANTY; and without the
13: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14: * See the GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18: * or write to:
19: *
20: * Free Software Foundation, Inc.,
21: * 59 Temple Place - Suite 330,
22: * Boston, MA USA 02111-1307
23: *
24: *
25: *
26: *
27: * Java2DUtil.java
28: *
29: */
30:
31: package it.businesslogic.ireport.util;
32:
33: import java.awt.*;
34: import java.awt.geom.*;
35: import java.util.*;
36:
37: public class Java2DUtil {
38: private static Stack clipBoundsStack = new Stack();
39: private static Stack transforms = new Stack();
40:
41: public static void setClip(Graphics g, int x, int y, int width,
42: int height) {
43: setClip(g, new Rectangle(x, y, width, height));
44: }
45:
46: public static void setClip(Graphics g, Rectangle clipBounds) {
47: Rectangle currentClipBounds;
48:
49: clipBounds = new Rectangle(clipBounds);
50: clipBounds.width += 1;
51: clipBounds.height += 1;
52:
53: currentClipBounds = g.getClipBounds();
54: if (currentClipBounds != null) {
55: clipBounds = clipBounds.intersection(g.getClipBounds());
56: }
57:
58: clipBoundsStack.push(currentClipBounds);
59: g.setClip(clipBounds);
60: }
61:
62: public static void resetClip(Graphics g) {
63: g.setClip((Shape) clipBoundsStack.pop());
64: }
65:
66: public static void setTransform(Graphics2D g2,
67: AffineTransform transform) {
68: AffineTransform current;
69:
70: current = g2.getTransform();
71: transforms.push(current);
72: g2.setTransform(transform);
73: }
74:
75: public static void resetTransform(Graphics2D g2) {
76: if (transforms.empty()) {
77: return;
78: }
79:
80: g2.setTransform((AffineTransform) transforms.pop());
81: }
82: }
|