001/* 002 * $Id: BackgroundPainter.java 3954 2011-03-15 16:34:38Z kschaefe $ 003 * 004 * Copyright 2010 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021package org.jdesktop.swingx; 022 023import java.awt.Color; 024import java.awt.Graphics2D; 025import java.io.Serializable; 026 027import javax.swing.JComponent; 028import javax.swing.UIManager; 029 030import org.jdesktop.swingx.painter.Painter; 031 032/** 033 * A painter for handling backgrounds. 034 * 035 * @author kschaefer 036 */ 037class BackgroundPainter implements Painter<JComponent>, Serializable { 038 private final Color color; 039 040 public BackgroundPainter(Color color) { 041 this.color = color; 042 } 043 044 /** 045 * {@inheritDoc} 046 */ 047 @Override 048 public void paint(Graphics2D g, JComponent object, int width, int height) { 049 if (color == null) { 050 return; 051 } 052 053 if (object.isOpaque() || object instanceof AlphaPaintable || UIManager.getLookAndFeel().getID().equals("Nimbus")) { 054 g.setColor(color); 055 g.fillRect(0, 0, width, height); 056 } 057 } 058}