01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * 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, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: AbstractComponentPainter.java,v 1.7 2005/02/16 11:28:11 jesper Exp $
23: package net.infonode.gui.componentpainter;
24:
25: import net.infonode.util.Direction;
26: import net.infonode.util.ImageUtils;
27:
28: import java.awt.*;
29: import java.awt.geom.AffineTransform;
30: import java.io.Serializable;
31:
32: /**
33: * An abstract base class for {@link ComponentPainter}'s. Default implementations for both paint methods are provided,
34: * but becuase they call each other a sub class must override one or both methods.
35: *
36: * @author $Author: jesper $
37: * @version $Revision: 1.7 $
38: * @since IDW 1.2.0
39: */
40: abstract public class AbstractComponentPainter implements
41: ComponentPainter, Serializable {
42: private static final long serialVersionUID = 1;
43:
44: protected AbstractComponentPainter() {
45: }
46:
47: public void paint(Component component, Graphics g, int x, int y,
48: int width, int height) {
49: paint(component, g, x, y, width, height, Direction.RIGHT,
50: false, false);
51: }
52:
53: public void paint(Component component, Graphics g, int x, int y,
54: int width, int height, Direction direction,
55: boolean horizontalFlip, boolean verticalFlip) {
56: if (direction != Direction.RIGHT || horizontalFlip
57: || verticalFlip) {
58: Graphics2D g2 = (Graphics2D) g;
59: AffineTransform t = g2.getTransform();
60:
61: try {
62: int w = direction.isHorizontal() ? width : height;
63: int h = direction.isHorizontal() ? height : width;
64: AffineTransform nt = ImageUtils.createTransform(
65: direction, horizontalFlip, verticalFlip, w, h);
66: g2.translate(x, y);
67: g2.transform(nt);
68: // Point p = new Point(x, y);
69: // nt.transform(p, p);
70: paint(component, g, 0, 0, w, h);
71: } finally {
72: g2.setTransform(t);
73: }
74: } else {
75: paint(component, g, x, y, width, height);
76: }
77: }
78:
79: public boolean isOpaque(Component component) {
80: return true;
81: }
82:
83: }
|