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: BorderIcon.java,v 1.6 2005/02/16 11:28:11 jesper Exp $
23: package net.infonode.gui.icon.button;
24:
25: import javax.swing.*;
26: import java.awt.*;
27:
28: public class BorderIcon implements Icon {
29: private Icon icon;
30: private Color color;
31: private Insets insets;
32:
33: public BorderIcon(Icon icon, int borderSize) {
34: this (icon, null, new Insets(borderSize, borderSize, borderSize,
35: borderSize));
36: }
37:
38: public BorderIcon(Icon icon, Color color, Insets insets) {
39: this .icon = icon;
40: this .color = color;
41: this .insets = insets;
42: }
43:
44: public void paintIcon(Component c, Graphics g, int x, int y) {
45: if (color != null) {
46: Color oldColor = g.getColor();
47: g.setColor(color);
48: g.fillRect(x, y, getIconWidth(), insets.top);
49: g.fillRect(x, y + getIconHeight() - insets.bottom,
50: getIconWidth(), insets.bottom);
51: g.fillRect(x, y + insets.top, insets.left, getIconHeight()
52: - insets.top - insets.bottom);
53: g.fillRect(x + getIconWidth() - insets.right, y
54: + insets.top, insets.right, getIconHeight()
55: - insets.top - insets.bottom);
56: g.setColor(oldColor);
57: }
58:
59: icon.paintIcon(c, g, x + insets.left, y + insets.top);
60: }
61:
62: public int getIconWidth() {
63: return insets.left + insets.right + icon.getIconWidth();
64: }
65:
66: public int getIconHeight() {
67: return insets.top + insets.bottom + icon.getIconHeight();
68: }
69: }
|