001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.*;
029:
030: import javax.swing.*;
031:
032: /**
033: *
034: *
035: * @author $author$
036: * @version $Revision: 1.13 $
037: */
038: public class ColorIcon implements Icon {
039: // Private instance variables
040: private Dimension size;
041: private Color color;
042: private Color borderColor;
043:
044: /**
045: * Creates a new ColorIcon object.
046: */
047: public ColorIcon() {
048: this (null);
049: }
050:
051: /**
052: * Creates a new ColorIcon object.
053: *
054: * @param color
055: */
056: public ColorIcon(Color color) {
057: this (color, null);
058: }
059:
060: /**
061: * Creates a new ColorIcon object.
062: *
063: * @param color
064: * @param borderColor
065: */
066: public ColorIcon(Color color, Color borderColor) {
067: this (color, null, borderColor);
068: }
069:
070: /**
071: * Creates a new ColorIcon object.
072: *
073: * @param color
074: * @param size
075: * @param borderColor
076: */
077: public ColorIcon(Color color, Dimension size, Color borderColor) {
078: setColor(color);
079: setSize(size);
080: setBorderColor(borderColor);
081: }
082:
083: /**
084: *
085: *
086: * @param c
087: * @param g
088: * @param x
089: * @param y
090: */
091: public void paintIcon(Component c, Graphics g, int x, int y) {
092: g.setColor((color == null) ? Color.black : color);
093: g.fillRect(x, y, getIconWidth(), getIconHeight());
094:
095: if (borderColor != null) {
096: g.setColor(borderColor);
097: g.drawRect(x, y, getIconWidth(), getIconHeight());
098: }
099: }
100:
101: /**
102: *
103: *
104: * @param size
105: */
106: public void setSize(Dimension size) {
107: this .size = size;
108: }
109:
110: /**
111: *
112: *
113: * @param color
114: */
115: public void setColor(Color color) {
116: this .color = color;
117: }
118:
119: /**
120: *
121: *
122: * @param borderColor
123: */
124: public void setBorderColor(Color borderColor) {
125: this .borderColor = borderColor;
126: }
127:
128: /**
129: *
130: *
131: * @return
132: */
133: public int getIconWidth() {
134: return (size == null) ? 16 : size.width;
135: }
136:
137: /**
138: *
139: *
140: * @return
141: */
142: public int getIconHeight() {
143: return (size == null) ? 16 : size.height;
144: }
145: }
|