001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: RectangleComponentPainter.java,v 1.7 2005/02/16 11:28:11 jesper Exp $
023: package net.infonode.gui.componentpainter;
024:
025: import net.infonode.gui.InsetsUtil;
026: import net.infonode.gui.colorprovider.ColorProvider;
027: import net.infonode.gui.colorprovider.FixedColorProvider;
028: import net.infonode.util.Direction;
029:
030: import java.awt.*;
031: import java.io.Serializable;
032:
033: /**
034: * @author $Author: jesper $
035: * @version $Revision: 1.7 $
036: */
037: public class RectangleComponentPainter extends AbstractComponentPainter
038: implements Serializable {
039: private static final long serialVersionUID = 1;
040:
041: private ColorProvider color;
042: private ColorProvider xorColor;
043: private Insets insets;
044:
045: public RectangleComponentPainter(Color color, int lineWidth) {
046: this (new FixedColorProvider(color), lineWidth);
047: }
048:
049: public RectangleComponentPainter(Color color, Color xorColor,
050: int lineWidth) {
051: this (new FixedColorProvider(color), new FixedColorProvider(
052: xorColor), lineWidth);
053: }
054:
055: public RectangleComponentPainter(ColorProvider color, int lineWidth) {
056: this (color, null, lineWidth);
057: }
058:
059: public RectangleComponentPainter(ColorProvider color,
060: ColorProvider xorColor, int lineWidth) {
061: this (color, xorColor, new Insets(lineWidth, lineWidth,
062: lineWidth, lineWidth));
063: }
064:
065: public RectangleComponentPainter(ColorProvider color,
066: ColorProvider xorColor, Insets insets) {
067: this .color = color;
068: this .xorColor = xorColor;
069: this .insets = (Insets) insets.clone();
070: }
071:
072: public void paint(Component component, Graphics g, int x, int y,
073: int width, int height, Direction direction,
074: boolean horizontalFlip, boolean verticalFlip) {
075: Color xc = null;
076: g.setColor(color.getColor(component));
077:
078: if (xorColor != null) {
079: xc = xorColor.getColor(component);
080:
081: if (xc != null)
082: g.setXORMode(xc);
083: }
084:
085: Insets i = InsetsUtil.rotate(direction, new Insets(
086: verticalFlip ? insets.bottom : insets.top,
087: horizontalFlip ? insets.right : insets.left,
088: verticalFlip ? insets.top : insets.bottom,
089: horizontalFlip ? insets.left : insets.right));
090:
091: g.fillRect(x + i.left, y, width - i.left - i.right, i.top);
092: g.fillRect(x + i.left, y + height - i.bottom, width - i.left
093: - i.right, i.bottom);
094: g.fillRect(x, y, i.left, height);
095: g.fillRect(x + width - i.right, y, i.right, height);
096:
097: if (xc != null)
098: g.setPaintMode();
099: }
100:
101: public boolean isOpaque(Component component) {
102: return false;
103: }
104:
105: public Color getColor(Component component) {
106: return color.getColor(component);
107: }
108: }
|