📄 colorbutton.java
字号:
/*
* 08/10/2005
*
* ColorButton.java - Button used by property sheets to display a color.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* This program 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 2
* of the License, or any later version.
*
* This program 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.ui.propertysheet;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;
/**
* A button that displays a color. This is used by property sheets to display
* a color.
*
* @author Robert Futrell
* @version 1.0
*/
public class ColorButton extends PropertySheetButton {
/**
*
*/
private static final long serialVersionUID = -8772214766920823412L;
private ColorIcon colorIcon;
/*****************************************************************************/
/**
* Constructor.
*/
public ColorButton() {
colorIcon = new ColorIcon(Color.RED, 10,10);
setIcon(colorIcon);
}
/*****************************************************************************/
/**
* Returns the color displayed by this button.
*
* @return The color displayed.
* @see #setColor
*/
public Color getColor() {
return colorIcon.getColor();
}
/*****************************************************************************/
/**
* Returns the text for the button.
*
* @param c The color the button is displaying.
* @return A text representation of the color.
*/
private static final String getColorString(Color c) {
return "RGB: (" + c.getRed() + "," + c.getGreen() + "," +
c.getBlue() + ")";
}
/*****************************************************************************/
/**
* Sets the color used by this color button.
*
* @param color The new color.
* @see #getColor
*/
public void setColor(Color color) {
if (!color.equals(colorIcon.getColor())) {
colorIcon.setColor(color);
setText(getColorString(color));
}
}
/*****************************************************************************/
/************************ INNER CLASSES **************************************/
/*****************************************************************************/
/**
* An icon that displays a color.
*/
/*
* FIXME: Pull me out into my own class, and use me in RColorButtons.
*/
public static class ColorIcon implements Icon {
public int width;
public int height;
private Color color;
public ColorIcon(Color color, int width, int height) {
this.width = width;
this.height = height;
setColor(color);
}
public Color getColor() {
return color;
}
public int getIconHeight() {
return height;
}
public int getIconWidth() {
return width;
}
public void setColor(Color color) {
this.color = color;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(color);
g.fillRect(x,y, width,height);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -