001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: ColorSwatch.java,v $ 023 Revision 1.4 2004/05/12 19:12:18 markl 024 comment block updates 025 026 Revision 1.3 2003/01/19 09:50:52 markl 027 Javadoc & comment header updates. 028 029 Revision 1.2 2001/03/12 09:27:52 markl 030 Source code and Javadoc cleanup. 031 032 Revision 1.1 2000/10/11 10:52:35 markl 033 New class. 034 ---------------------------------------------------------------------------- 035*/ 036 037package kiwi.ui; 038 039import java.awt.*; 040import javax.swing.*; 041 042/** A simple component that renders a color swatch--a filled rectangle with 043 * a thin black border. 044 * 045 * @author Mark Lindner 046 */ 047 048public class ColorSwatch implements Icon 049 { 050 private Color color; 051 private int w, h; 052 /** The default swatch width. */ 053 public static final int DEFAULT_WIDTH = 50; 054 /** The default swatch height. */ 055 public static final int DEFAULT_HEIGHT = 15; 056 /** The default swatch color. */ 057 public static final Color DEFAULT_COLOR = Color.gray; 058 059 /** Construct a new <code>ColorSwatch</code> with a default color, width, 060 * and height. 061 */ 062 063 public ColorSwatch() 064 { 065 this(DEFAULT_COLOR, DEFAULT_WIDTH, DEFAULT_HEIGHT); 066 } 067 068 /** Construct a new <code>ColorSwatch</code> with the specified color and 069 * geometry. 070 * 071 * @param color The color for the swatch. 072 * @param width The width, in pixels. 073 * @param height The height, in pixels. 074 */ 075 076 public ColorSwatch(Color color, int width, int height) 077 { 078 this.color = color; 079 this.w = width; 080 this.h = height; 081 } 082 083 /** Get the color of this swatch. 084 * 085 * @return The current color of the swatch. 086 */ 087 088 public Color getColor() 089 { 090 return(color); 091 } 092 093 /** Set the color of this swatch. 094 * 095 * @param color The new color for the swatch. 096 */ 097 098 public void setColor(Color color) 099 { 100 this.color = color; 101 } 102 103 /** Get the width of the swatch. 104 * 105 * @return The width, in pixels. 106 */ 107 108 public int getIconWidth() 109 { 110 return(w); 111 } 112 113 /** Get the height of the swatch. 114 * 115 * @return The height, in pixels. 116 */ 117 118 public int getIconHeight() 119 { 120 return(h); 121 } 122 123 /** Paint the swatch (as an icon). 124 * 125 * @param c The component to paint the swatch in. 126 * @param gc The graphics context. 127 * @param x The x-coordinate. 128 * @param y The y-coordinate. 129 */ 130 131 public void paintIcon(Component c, Graphics gc, int x, int y) 132 { 133 gc.setColor(Color.black); 134 gc.drawRect(x, y, w - 1, h - 1); 135 gc.setColor(color); 136 gc.fillRect(x + 1, y + 1, w - 2, h - 2); 137 } 138 139 } 140 141/* end of source file */