/* * Copyright (c) 2009, SQL Power Group Inc. * * This file is part of SQL Power Library. * * SQL Power Library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * SQL Power Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package ca.sqlpower.swingui; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; /** * This class converts a Color into an icon with the given width and height. */ public class ColorIcon implements Icon { private final int width; private final int height; private Color colour; public ColorIcon(int width, int height, Color colour) { this.width = width; this.height = height; this.colour = colour; } public int getIconHeight() { return height; } public int getIconWidth() { return width; } public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(colour); g.fillRect(x, y, width - 1, height - 1); } }