/** * 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(); } }