< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/nimbus/DerivedColor.java

Print this page




  84             // apply offsets
  85             tmp[0] = clamp(tmp[0] + hOffset);
  86             tmp[1] = clamp(tmp[1] + sOffset);
  87             tmp[2] = clamp(tmp[2] + bOffset);
  88             int alpha = clamp(src.getAlpha() + aOffset);
  89             argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
  90         } else {
  91             float[] tmp = new float[3];
  92             tmp[0] = clamp(hOffset);
  93             tmp[1] = clamp(sOffset);
  94             tmp[2] = clamp(bOffset);
  95             int alpha = clamp(aOffset);
  96             argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
  97         }
  98     }
  99 
 100     /**
 101      * Returns the RGB value representing the color in the default sRGB {@link java.awt.image.ColorModel}. (Bits 24-31
 102      * are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
 103      *
 104      * @return the RGB value of the color in the default sRGB <code>ColorModel</code>.
 105      * @see java.awt.image.ColorModel#getRGBdefault
 106      * @see #getRed
 107      * @see #getGreen
 108      * @see #getBlue
 109      * @since 1.0
 110      */
 111     @Override public int getRGB() {
 112         return argbValue;
 113     }
 114 
 115     @Override
 116     public boolean equals(Object o) {
 117         if (this == o) return true;
 118         if (!(o instanceof DerivedColor)) return false;
 119         DerivedColor that = (DerivedColor) o;
 120         if (aOffset != that.aOffset) return false;
 121         if (Float.compare(that.bOffset, bOffset) != 0) return false;
 122         if (Float.compare(that.hOffset, hOffset) != 0) return false;
 123         if (Float.compare(that.sOffset, sOffset) != 0) return false;
 124         if (!uiDefaultParentName.equals(that.uiDefaultParentName)) return false;


 140 
 141     private float clamp(float value) {
 142         if (value < 0) {
 143             value = 0;
 144         } else if (value > 1) {
 145             value = 1;
 146         }
 147         return value;
 148     }
 149 
 150     private int clamp(int value) {
 151         if (value < 0) {
 152             value = 0;
 153         } else if (value > 255) {
 154             value = 255;
 155         }
 156         return value;
 157     }
 158 
 159     /**
 160      * Returns a string representation of this <code>Color</code>. This method
 161      * is intended to be used only for debugging purposes. The content and
 162      * format of the returned string might vary between implementations. The
 163      * returned string might be empty but cannot be <code>null</code>.
 164      *
 165      * @return a String representation of this <code>Color</code>.
 166      */
 167     @Override
 168     public String toString() {
 169         Color src = UIManager.getColor(uiDefaultParentName);
 170         String s = "DerivedColor(color=" + getRed() + "," + getGreen() + "," + getBlue() +
 171                 " parent=" + uiDefaultParentName +
 172                 " offsets=" + getHueOffset() + "," + getSaturationOffset() + ","
 173                 + getBrightnessOffset() + "," + getAlphaOffset();
 174         return src == null ? s : s + " pColor=" + src.getRed() + "," + src.getGreen() + "," + src.getBlue();
 175     }
 176 
 177     @SuppressWarnings("serial") // Same-version serialization only
 178     static class UIResource extends DerivedColor implements javax.swing.plaf.UIResource {
 179         UIResource(String uiDefaultParentName, float hOffset, float sOffset,
 180                    float bOffset, int aOffset) {
 181             super(uiDefaultParentName, hOffset, sOffset, bOffset, aOffset);
 182         }
 183 
 184         @Override
 185         public boolean equals(Object o) {


  84             // apply offsets
  85             tmp[0] = clamp(tmp[0] + hOffset);
  86             tmp[1] = clamp(tmp[1] + sOffset);
  87             tmp[2] = clamp(tmp[2] + bOffset);
  88             int alpha = clamp(src.getAlpha() + aOffset);
  89             argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
  90         } else {
  91             float[] tmp = new float[3];
  92             tmp[0] = clamp(hOffset);
  93             tmp[1] = clamp(sOffset);
  94             tmp[2] = clamp(bOffset);
  95             int alpha = clamp(aOffset);
  96             argbValue = (Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24);
  97         }
  98     }
  99 
 100     /**
 101      * Returns the RGB value representing the color in the default sRGB {@link java.awt.image.ColorModel}. (Bits 24-31
 102      * are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
 103      *
 104      * @return the RGB value of the color in the default sRGB {@code ColorModel}.
 105      * @see java.awt.image.ColorModel#getRGBdefault
 106      * @see #getRed
 107      * @see #getGreen
 108      * @see #getBlue
 109      * @since 1.0
 110      */
 111     @Override public int getRGB() {
 112         return argbValue;
 113     }
 114 
 115     @Override
 116     public boolean equals(Object o) {
 117         if (this == o) return true;
 118         if (!(o instanceof DerivedColor)) return false;
 119         DerivedColor that = (DerivedColor) o;
 120         if (aOffset != that.aOffset) return false;
 121         if (Float.compare(that.bOffset, bOffset) != 0) return false;
 122         if (Float.compare(that.hOffset, hOffset) != 0) return false;
 123         if (Float.compare(that.sOffset, sOffset) != 0) return false;
 124         if (!uiDefaultParentName.equals(that.uiDefaultParentName)) return false;


 140 
 141     private float clamp(float value) {
 142         if (value < 0) {
 143             value = 0;
 144         } else if (value > 1) {
 145             value = 1;
 146         }
 147         return value;
 148     }
 149 
 150     private int clamp(int value) {
 151         if (value < 0) {
 152             value = 0;
 153         } else if (value > 255) {
 154             value = 255;
 155         }
 156         return value;
 157     }
 158 
 159     /**
 160      * Returns a string representation of this {@code Color}. This method
 161      * is intended to be used only for debugging purposes. The content and
 162      * format of the returned string might vary between implementations. The
 163      * returned string might be empty but cannot be {@code null}.
 164      *
 165      * @return a String representation of this {@code Color}.
 166      */
 167     @Override
 168     public String toString() {
 169         Color src = UIManager.getColor(uiDefaultParentName);
 170         String s = "DerivedColor(color=" + getRed() + "," + getGreen() + "," + getBlue() +
 171                 " parent=" + uiDefaultParentName +
 172                 " offsets=" + getHueOffset() + "," + getSaturationOffset() + ","
 173                 + getBrightnessOffset() + "," + getAlphaOffset();
 174         return src == null ? s : s + " pColor=" + src.getRed() + "," + src.getGreen() + "," + src.getBlue();
 175     }
 176 
 177     @SuppressWarnings("serial") // Same-version serialization only
 178     static class UIResource extends DerivedColor implements javax.swing.plaf.UIResource {
 179         UIResource(String uiDefaultParentName, float hOffset, float sOffset,
 180                    float bOffset, int aOffset) {
 181             super(uiDefaultParentName, hOffset, sOffset, bOffset, aOffset);
 182         }
 183 
 184         @Override
 185         public boolean equals(Object o) {
< prev index next >