001 /* $Id: LabeledColorButton.java 12 2007-07-27 09:48:53Z ringler $
002 * This class is part of the de.mospace.swing library.
003 * Copyright (C) 2005-2006 Moritz Ringler
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program 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
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019 package de.mospace.swing;
020
021 import java.awt.Color;
022
023 /** A {@link JColorButton} with a title.
024 *
025 * @version $Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
026 * @author Moritz Ringler
027 */
028 public class LabeledColorButton extends JColorButton{
029 /** Sets the background of this button to c and its foreground
030 * to the complementary color of c .**/
031 public void setBackground(Color c){
032 super.setBackground(c);
033 if(c != null){
034 setForeground(invert(c));
035 }
036 }
037
038 private static Color invert(Color c){
039 return new Color(255-c.getRed(),255-c.getGreen(),
040 255-c.getBlue());
041 }
042
043 /** Constructs a new ColorButton with no name and white as its
044 associated color. **/
045 public LabeledColorButton(){
046 super();
047 }
048
049 /** Constructs a new ColorButton with the given name and color. **/
050 public LabeledColorButton(String name, Color c){
051 super(name,c);
052 setText(name);
053 }
054
055 /** Constructs a new ColorButton with the given name and color. **/
056 public LabeledColorButton(String name, Color c, boolean foreground){
057 super(name,c,foreground);
058 setText(name);
059 }
060
061 /** Constructs a new ColorButton with the given name and color.
062 * @param c the combined RGB components of the color
063 * @see java.awt.Color#Color(int rgb)
064 **/
065 public LabeledColorButton(String name, int c){
066 super(name,c);
067 setText(name);
068 }
069
070 /** Constructs a new ColorButton with the given name and white as its
071 * associated color. **/
072 public LabeledColorButton(String name){
073 super(name);
074 setText(name);
075 }
076 }