home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / basic / BasicHSVChooserPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.6 KB  |  135 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.ColorChooserPanel;
  4. import com.sun.java.swing.UIManager;
  5. import java.awt.Color;
  6. import java.awt.Container;
  7. import java.awt.Dimension;
  8. import java.awt.LayoutManager;
  9. import java.beans.PropertyChangeEvent;
  10. import java.beans.PropertyChangeListener;
  11. import java.io.Serializable;
  12. import java.util.EventObject;
  13.  
  14. public class BasicHSVChooserPanel extends ColorChooserPanel implements PropertyChangeListener, Serializable {
  15.    static int preferredWidth = 300;
  16.    static int preferredHeight = 200;
  17.    static Dimension preferredSize;
  18.    static int butGap;
  19.    protected Spinner hue;
  20.    protected Spinner saturation;
  21.    protected Spinner brightness;
  22.    protected ColorPatch resultColor;
  23.    protected HueLightnessPatch hlp;
  24.    protected ColorWheel wheel;
  25.    Color color;
  26.  
  27.    public BasicHSVChooserPanel() {
  28.       this.color = Color.red;
  29.    }
  30.  
  31.    public BasicHSVChooserPanel(Color var1) {
  32.       this.color = Color.red;
  33.       this.color = var1;
  34.    }
  35.  
  36.    public int[] getHSBColor() {
  37.       Color var1 = this.getColor();
  38.       int[] var2 = new int[3];
  39.       float[] var3 = Color.RGBtoHSB(var1.getRed(), var1.getGreen(), var1.getBlue(), (float[])null);
  40.       var2[0] = (int)((double)(var3[0] * 100.0F) + (double)0.5F);
  41.       var2[1] = (int)((double)(var3[1] * 100.0F) + (double)0.5F);
  42.       var2[2] = (int)((double)(var3[2] * 100.0F) + (double)0.5F);
  43.       return var2;
  44.    }
  45.  
  46.    public Color getColor() {
  47.       return this.color;
  48.    }
  49.  
  50.    public void setColor(Color var1) {
  51.       this.color = var1;
  52.       float[] var2 = Color.RGBtoHSB(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), (float[])null);
  53.       int var3 = Color.HSBtoRGB(var2[0], var2[1], var2[2]);
  54.       this.hlp.setColor(var3);
  55.       this.setSpinners(var2);
  56.       this.wheel.setTheta((double)(var2[0] * 360.0F) + (double)0.5F);
  57.       this.resultColor.setColor(var3);
  58.    }
  59.  
  60.    public void installChooserPanel() {
  61.       ((Container)this).setLayout(new ColorChooserLayout(this));
  62.       int[] var1 = this.getHSBColor();
  63.       this.resultColor = new ColorPatch();
  64.       this.resultColor.setBorder(UIManager.getBorder("ColorChooser.selectedColorBorder"));
  65.       this.hue = new Spinner(var1[0], "┬░ H");
  66.       this.hue.setMinimum(0);
  67.       this.hue.setMaximum(100);
  68.       this.saturation = new Spinner(var1[1], "% S");
  69.       this.saturation.setMinimum(0);
  70.       this.saturation.setMaximum(100);
  71.       this.brightness = new Spinner(var1[2], "% B");
  72.       this.brightness.setMinimum(0);
  73.       this.brightness.setMaximum(100);
  74.       this.hlp = new HueLightnessPatch(this.resultColor, this.hue, this.saturation, this.brightness);
  75.       ((Container)this).add(this.hlp);
  76.       this.saturation.addAdjustmentListener(this.hlp);
  77.       this.brightness.addAdjustmentListener(this.hlp);
  78.       this.wheel = new ColorWheel(this.hlp, this.hue);
  79.       this.hue.setWrap(true);
  80.       ((Container)this).add(this.wheel);
  81.       ((Container)this).add(this.resultColor);
  82.       ((Container)this).add(this.hue);
  83.       ((Container)this).add(this.saturation);
  84.       ((Container)this).add(this.brightness);
  85.       this.resultColor.addPropertyChangeListener(this);
  86.    }
  87.  
  88.    public void uninstallChooserPanel() {
  89.       this.resultColor.removePropertyChangeListener(this);
  90.       ((Container)this).setLayout((LayoutManager)null);
  91.       ((Container)this).remove(this.hlp);
  92.       ((Container)this).remove(this.wheel);
  93.       ((Container)this).remove(this.resultColor);
  94.       ((Container)this).remove(this.hue);
  95.       ((Container)this).remove(this.saturation);
  96.       ((Container)this).remove(this.brightness);
  97.       this.hlp = null;
  98.       this.wheel = null;
  99.       this.resultColor = null;
  100.       this.hue = this.saturation = this.brightness = null;
  101.    }
  102.  
  103.    public void propertyChange(PropertyChangeEvent var1) {
  104.       if (((EventObject)var1).getSource() == this.resultColor && var1.getPropertyName().equals("color")) {
  105.          Color var2 = (Color)var1.getNewValue();
  106.          Color var3 = this.getColor();
  107.          ((ColorChooserPanel)this).fireColorPropertyChange(var3, var2);
  108.       }
  109.  
  110.    }
  111.  
  112.    protected void setSpinners(float[] var1) {
  113.       float var2 = (float)this.hue.getValue();
  114.       float var3 = (float)this.saturation.getValue();
  115.       float var4 = (float)this.brightness.getValue();
  116.       if (var2 != var1[0]) {
  117.          this.hue.setValue((int)((double)(var1[0] * 360.0F) + (double)0.5F));
  118.       }
  119.  
  120.       if (var3 != var1[1]) {
  121.          this.saturation.setValue((int)((double)(var1[1] * 100.0F) + (double)0.5F));
  122.       }
  123.  
  124.       if (var4 != var1[2]) {
  125.          this.brightness.setValue((int)((double)(var1[2] * 100.0F) + (double)0.5F));
  126.       }
  127.  
  128.    }
  129.  
  130.    static {
  131.       preferredSize = new Dimension(preferredWidth, preferredHeight);
  132.       butGap = 2;
  133.    }
  134. }
  135.