private void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
      myColor = color;
      myHue = hsb[0];
      mySaturation = hsb[1];
      myBrightness = hsb[2];
      myOpacity = color.getAlpha();

      fireColorChanged(source);

      repaint();
    }
    public void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);

      myBrightnessComponent.setValue(255 - (int) (hsb[2] * 255));
      myBrightnessComponent.repaint();

      myColorWheel.dropImage();
      if (myOpacityComponent != null && source instanceof ColorPicker) {
        myOpacityComponent.setValue(color.getAlpha());
        myOpacityComponent.repaint();
      }

      myColorWheel.setColor(color, source);
    }
Example #3
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in HUE, SAT, or BRI mode, then this method converts these values to HSB
   * coordinates and calls <code>setHSB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param r the red value of the selected color.
   * @param g the green value of the selected color.
   * @param b the blue value of the selected color.
   */
  public void setRGB(int r, int g, int b) {
    if (r < 0 || r > 255)
      throw new IllegalArgumentException("The red value (" + r + ") must be between [0,255].");
    if (g < 0 || g > 255)
      throw new IllegalArgumentException("The green value (" + g + ") must be between [0,255].");
    if (b < 0 || b > 255)
      throw new IllegalArgumentException("The blue value (" + b + ") must be between [0,255].");

    if (red != r || green != g || blue != b) {
      if (mode == ColorPicker.RED || mode == ColorPicker.GREEN || mode == ColorPicker.BLUE) {
        int lastR = red;
        int lastG = green;
        int lastB = blue;
        red = r;
        green = g;
        blue = b;

        if (mode == ColorPicker.RED) {
          if (lastR != r) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.GREEN) {
          if (lastG != g) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BLUE) {
          if (lastB != b) {
            regenerateImage();
          }
        }
      } else {
        float[] hsb = new float[3];
        Color.RGBtoHSB(r, g, b, hsb);
        setHSB(hsb[0], hsb[1], hsb[2]);
        return;
      }
      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
 private void applyColorToHSB(final Color c) {
   final float[] hbs = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
   myRed.setText(String.valueOf(((int) (360f * hbs[0]))));
   myGreen.setText(String.valueOf(((int) (100f * hbs[1]))));
   myBlue.setText(String.valueOf(((int) (100f * hbs[2]))));
 }