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: TreeIcon.java,v 1.6 2005/12/04 13:46:03 jesper Exp $
23: package net.infonode.gui.icon.button;
24:
25: import net.infonode.gui.GraphicsUtil;
26:
27: import javax.swing.*;
28: import java.awt.*;
29:
30: /**
31: * @author Jesper Nordenberg
32: * @version $Revision: 1.6 $ $Date: 2005/12/04 13:46:03 $
33: */
34: public class TreeIcon implements Icon {
35: public static final int PLUS = 1;
36: public static final int MINUS = 2;
37:
38: private int type;
39: private int width;
40: private int height;
41: private Color color;
42: private Color bgColor;
43: private boolean border = true;
44:
45: public TreeIcon(int type, int width, int height, boolean border,
46: Color color, Color bgColor) {
47: this .type = type;
48: this .width = width;
49: this .height = height;
50: this .border = border;
51: this .color = color;
52: this .bgColor = bgColor;
53: }
54:
55: public TreeIcon(int type, int width, int height) {
56: this (type, width, height, true, Color.BLACK, null);
57: }
58:
59: public void paintIcon(Component c, Graphics g, int x, int y) {
60: if (bgColor != null) {
61: g.setColor(bgColor);
62: g.fillRect(x + 1, y + 1, width - 2, height - 2);
63: }
64:
65: g.setColor(color);
66:
67: if (border) {
68: g.drawRect(x + 1, y + 1, width - 2, height - 2);
69: }
70:
71: GraphicsUtil.drawOptimizedLine(g, x + 3, y + height / 2, x
72: + width - 3, y + height / 2);
73:
74: if (type == PLUS)
75: GraphicsUtil.drawOptimizedLine(g, x + width / 2, y + 3, x
76: + width / 2, y + height - 3);
77: }
78:
79: public int getIconWidth() {
80: return width;
81: }
82:
83: public int getIconHeight() {
84: return height;
85: }
86: }
|