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

Print this page


   1 /*
   2  * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.plaf.nimbus;
  26 
  27 import javax.swing.UIManager;
  28 import java.awt.Color;
  29 import java.beans.PropertyChangeSupport;
  30 import java.beans.PropertyChangeListener;
  31 
  32 /**
  33  * DerivedColor - A color implementation that is derived from a UIManager
  34  * defaults table color and a set of offsets. It can be rederived at any point
  35  * by calling rederiveColor(). For example when its parent color changes and it
  36  * value will update to reflect the new derived color. Property change events
  37  * are fired for the "rgb" property when the derived color changes.
  38  *
  39  * @author Jasper Potts
  40  */

  41 class DerivedColor extends Color {
  42     private final String uiDefaultParentName;
  43     private final float hOffset, sOffset, bOffset;
  44     private final int aOffset;
  45     private int argbValue;
  46 
  47     DerivedColor(String uiDefaultParentName, float hOffset, float sOffset, float bOffset, int aOffset) {
  48         super(0);
  49         this.uiDefaultParentName = uiDefaultParentName;
  50         this.hOffset = hOffset;
  51         this.sOffset = sOffset;
  52         this.bOffset = bOffset;
  53         this.aOffset = aOffset;
  54     }
  55 
  56     public String getUiDefaultParentName() {
  57         return uiDefaultParentName;
  58     }
  59 
  60     public float getHueOffset() {


 156     }
 157 
 158     /**
 159      * Returns a string representation of this <code>Color</code>. This method
 160      * is intended to be used only for debugging purposes. The content and
 161      * format of the returned string might vary between implementations. The
 162      * returned string might be empty but cannot be <code>null</code>.
 163      *
 164      * @return a String representation of this <code>Color</code>.
 165      */
 166     @Override
 167     public String toString() {
 168         Color src = UIManager.getColor(uiDefaultParentName);
 169         String s = "DerivedColor(color=" + getRed() + "," + getGreen() + "," + getBlue() +
 170                 " parent=" + uiDefaultParentName +
 171                 " offsets=" + getHueOffset() + "," + getSaturationOffset() + ","
 172                 + getBrightnessOffset() + "," + getAlphaOffset();
 173         return src == null ? s : s + " pColor=" + src.getRed() + "," + src.getGreen() + "," + src.getBlue();
 174     }
 175 

 176     static class UIResource extends DerivedColor implements javax.swing.plaf.UIResource {
 177         UIResource(String uiDefaultParentName, float hOffset, float sOffset,
 178                    float bOffset, int aOffset) {
 179             super(uiDefaultParentName, hOffset, sOffset, bOffset, aOffset);
 180         }
 181 
 182         @Override
 183         public boolean equals(Object o) {
 184             return (o instanceof UIResource) && super.equals(o);
 185         }
 186 
 187         @Override
 188         public int hashCode() {
 189             return super.hashCode() + 7;
 190         }
 191     }
 192 }
   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.plaf.nimbus;
  26 
  27 import javax.swing.UIManager;
  28 import java.awt.Color;
  29 import java.beans.PropertyChangeSupport;
  30 import java.beans.PropertyChangeListener;
  31 
  32 /**
  33  * DerivedColor - A color implementation that is derived from a UIManager
  34  * defaults table color and a set of offsets. It can be rederived at any point
  35  * by calling rederiveColor(). For example when its parent color changes and it
  36  * value will update to reflect the new derived color. Property change events
  37  * are fired for the "rgb" property when the derived color changes.
  38  *
  39  * @author Jasper Potts
  40  */
  41 @SuppressWarnings("serial") // Same-version serialization only
  42 class DerivedColor extends Color {
  43     private final String uiDefaultParentName;
  44     private final float hOffset, sOffset, bOffset;
  45     private final int aOffset;
  46     private int argbValue;
  47 
  48     DerivedColor(String uiDefaultParentName, float hOffset, float sOffset, float bOffset, int aOffset) {
  49         super(0);
  50         this.uiDefaultParentName = uiDefaultParentName;
  51         this.hOffset = hOffset;
  52         this.sOffset = sOffset;
  53         this.bOffset = bOffset;
  54         this.aOffset = aOffset;
  55     }
  56 
  57     public String getUiDefaultParentName() {
  58         return uiDefaultParentName;
  59     }
  60 
  61     public float getHueOffset() {


 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) {
 186             return (o instanceof UIResource) && super.equals(o);
 187         }
 188 
 189         @Override
 190         public int hashCode() {
 191             return super.hashCode() + 7;
 192         }
 193     }
 194 }