home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.ColorChooserPanel;
- import com.sun.java.swing.UIManager;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.LayoutManager;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.io.Serializable;
- import java.util.EventObject;
-
- public class BasicHSVChooserPanel extends ColorChooserPanel implements PropertyChangeListener, Serializable {
- static int preferredWidth = 300;
- static int preferredHeight = 200;
- static Dimension preferredSize;
- static int butGap;
- protected Spinner hue;
- protected Spinner saturation;
- protected Spinner brightness;
- protected ColorPatch resultColor;
- protected HueLightnessPatch hlp;
- protected ColorWheel wheel;
- Color color;
-
- public BasicHSVChooserPanel() {
- this.color = Color.red;
- }
-
- public BasicHSVChooserPanel(Color var1) {
- this.color = Color.red;
- this.color = var1;
- }
-
- public int[] getHSBColor() {
- Color var1 = this.getColor();
- int[] var2 = new int[3];
- float[] var3 = Color.RGBtoHSB(var1.getRed(), var1.getGreen(), var1.getBlue(), (float[])null);
- var2[0] = (int)((double)(var3[0] * 100.0F) + (double)0.5F);
- var2[1] = (int)((double)(var3[1] * 100.0F) + (double)0.5F);
- var2[2] = (int)((double)(var3[2] * 100.0F) + (double)0.5F);
- return var2;
- }
-
- public Color getColor() {
- return this.color;
- }
-
- public void setColor(Color var1) {
- this.color = var1;
- float[] var2 = Color.RGBtoHSB(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), (float[])null);
- int var3 = Color.HSBtoRGB(var2[0], var2[1], var2[2]);
- this.hlp.setColor(var3);
- this.setSpinners(var2);
- this.wheel.setTheta((double)(var2[0] * 360.0F) + (double)0.5F);
- this.resultColor.setColor(var3);
- }
-
- public void installChooserPanel() {
- ((Container)this).setLayout(new ColorChooserLayout(this));
- int[] var1 = this.getHSBColor();
- this.resultColor = new ColorPatch();
- this.resultColor.setBorder(UIManager.getBorder("ColorChooser.selectedColorBorder"));
- this.hue = new Spinner(var1[0], "┬░ H");
- this.hue.setMinimum(0);
- this.hue.setMaximum(100);
- this.saturation = new Spinner(var1[1], "% S");
- this.saturation.setMinimum(0);
- this.saturation.setMaximum(100);
- this.brightness = new Spinner(var1[2], "% B");
- this.brightness.setMinimum(0);
- this.brightness.setMaximum(100);
- this.hlp = new HueLightnessPatch(this.resultColor, this.hue, this.saturation, this.brightness);
- ((Container)this).add(this.hlp);
- this.saturation.addAdjustmentListener(this.hlp);
- this.brightness.addAdjustmentListener(this.hlp);
- this.wheel = new ColorWheel(this.hlp, this.hue);
- this.hue.setWrap(true);
- ((Container)this).add(this.wheel);
- ((Container)this).add(this.resultColor);
- ((Container)this).add(this.hue);
- ((Container)this).add(this.saturation);
- ((Container)this).add(this.brightness);
- this.resultColor.addPropertyChangeListener(this);
- }
-
- public void uninstallChooserPanel() {
- this.resultColor.removePropertyChangeListener(this);
- ((Container)this).setLayout((LayoutManager)null);
- ((Container)this).remove(this.hlp);
- ((Container)this).remove(this.wheel);
- ((Container)this).remove(this.resultColor);
- ((Container)this).remove(this.hue);
- ((Container)this).remove(this.saturation);
- ((Container)this).remove(this.brightness);
- this.hlp = null;
- this.wheel = null;
- this.resultColor = null;
- this.hue = this.saturation = this.brightness = null;
- }
-
- public void propertyChange(PropertyChangeEvent var1) {
- if (((EventObject)var1).getSource() == this.resultColor && var1.getPropertyName().equals("color")) {
- Color var2 = (Color)var1.getNewValue();
- Color var3 = this.getColor();
- ((ColorChooserPanel)this).fireColorPropertyChange(var3, var2);
- }
-
- }
-
- protected void setSpinners(float[] var1) {
- float var2 = (float)this.hue.getValue();
- float var3 = (float)this.saturation.getValue();
- float var4 = (float)this.brightness.getValue();
- if (var2 != var1[0]) {
- this.hue.setValue((int)((double)(var1[0] * 360.0F) + (double)0.5F));
- }
-
- if (var3 != var1[1]) {
- this.saturation.setValue((int)((double)(var1[1] * 100.0F) + (double)0.5F));
- }
-
- if (var4 != var1[2]) {
- this.brightness.setValue((int)((double)(var1[2] * 100.0F) + (double)0.5F));
- }
-
- }
-
- static {
- preferredSize = new Dimension(preferredWidth, preferredHeight);
- butGap = 2;
- }
- }
-