Manual merge with main-silver due to conflict in JarWithModuleAttributes
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 14 Sep 2009 17:56:24 +0200
changeset 9381d7c2379e6ac
parent 937 da971c243f7f
parent 823 adc74c06e60e
child 939 737729a8b9e6
Manual merge with main-silver due to conflict in JarWithModuleAttributes
     1.1 --- a/openide.util/apichanges.xml	Tue Sep 01 05:00:29 2009 +0400
     1.2 +++ b/openide.util/apichanges.xml	Mon Sep 14 17:56:24 2009 +0200
     1.3 @@ -49,6 +49,23 @@
     1.4      <apidef name="actions">Actions API</apidef>
     1.5  </apidefs>
     1.6  <changes>
     1.7 +    <change id="ImageUtilities.createDisabled">
     1.8 +        <api name="util"/>
     1.9 +        <summary><code>ImageUtilities.createDisabledIcon</code> and <code>ImageUtilities.createDisabledImage</code> added.</summary>
    1.10 +        <version major="7" minor="28"/>
    1.11 +        <date day="10" month="9" year="2009"/>
    1.12 +        <author login="t_h"/>
    1.13 +        <compatibility addition="yes"/>
    1.14 +        <description>
    1.15 +            <p>
    1.16 +                <code>ImageUtilities.createDisabledIcon</code> now can be used
    1.17 +                to create low color saturation icon for disabled buttons. Also
    1.18 +                <code>ImageUtilities.createDisabledImage</code> was added.
    1.19 +            </p>
    1.20 +        </description>
    1.21 +        <class package="org.openide.util" name="ImageUtilities"/>
    1.22 +        <issue number="171400"/>
    1.23 +    </change>
    1.24      <change id="NbBundle.varargs">
    1.25          <api name="util"/>
    1.26          <summary><code>NbBundle.getMessage</code> can take arbitrarily many format arguments</summary>
     2.1 --- a/openide.util/nbproject/project.properties	Tue Sep 01 05:00:29 2009 +0400
     2.2 +++ b/openide.util/nbproject/project.properties	Mon Sep 14 17:56:24 2009 +0200
     2.3 @@ -42,7 +42,7 @@
     2.4  module.jar.dir=lib
     2.5  cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
     2.6  
     2.7 -spec.version.base=7.27.0
     2.8 +spec.version.base=7.28.0
     2.9  
    2.10  # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
    2.11  
     3.1 --- a/openide.util/src/org/openide/util/ImageUtilities.java	Tue Sep 01 05:00:29 2009 +0400
     3.2 +++ b/openide.util/src/org/openide/util/ImageUtilities.java	Mon Sep 14 17:56:24 2009 +0200
     3.3 @@ -50,8 +50,11 @@
     3.4  import java.awt.Transparency;
     3.5  import java.awt.image.BufferedImage;
     3.6  import java.awt.image.ColorModel;
     3.7 +import java.awt.image.FilteredImageSource;
     3.8  import java.awt.image.ImageObserver;
     3.9 +import java.awt.image.ImageProducer;
    3.10  import java.awt.image.IndexColorModel;
    3.11 +import java.awt.image.RGBImageFilter;
    3.12  import java.awt.image.WritableRaster;
    3.13  import java.io.IOException;
    3.14  import java.lang.ref.SoftReference;
    3.15 @@ -276,8 +279,31 @@
    3.16          } else {
    3.17              return assignToolTipToImage(image, text);
    3.18          }
    3.19 -    }    
    3.20 -    
    3.21 +    }
    3.22 +
    3.23 +    /**
    3.24 +     * Creates disabled (color saturation lowered) icon.
    3.25 +     * Icon image conversion is performed lazily.
    3.26 +     * @param icon original icon used for conversion
    3.27 +     * @return less saturated Icon
    3.28 +     * @since 7.28
    3.29 +     */
    3.30 +    public static Icon createDisabledIcon(Icon icon)  {
    3.31 +        Parameters.notNull("icon", icon);
    3.32 +        return new LazyDisabledIcon(icon2Image(icon));
    3.33 +    }
    3.34 +
    3.35 +    /**
    3.36 +     * Creates disabled (color saturation lowered) image.
    3.37 +     * @param image original image used for conversion
    3.38 +     * @return less saturated Image
    3.39 +     * @since 7.28
    3.40 +     */
    3.41 +    public static Image createDisabledImage(Image image)  {
    3.42 +        Parameters.notNull("image", image);
    3.43 +        return LazyDisabledIcon.createDisabledImage(image);
    3.44 +    }
    3.45 +
    3.46      /**
    3.47       * Get the class loader from lookup.
    3.48       * Since this is done very frequently, it is wasteful to query lookup each time.
    3.49 @@ -763,4 +789,61 @@
    3.50              g.drawImage(this, x, y, null);
    3.51          }
    3.52      }
    3.53 +
    3.54 +    private static class LazyDisabledIcon implements Icon {
    3.55 +
    3.56 +        /** Shared instance of filter for disabled icons */
    3.57 +        private static final RGBImageFilter DISABLED_BUTTON_FILTER = new DisabledButtonFilter();
    3.58 +        private Image img;
    3.59 +        private Icon disabledIcon;
    3.60 +
    3.61 +        public LazyDisabledIcon(Image img) {
    3.62 +            assert null != img;
    3.63 +            this.img = img;
    3.64 +        }
    3.65 +
    3.66 +        public void paintIcon(Component c, Graphics g, int x, int y) {
    3.67 +            getDisabledIcon().paintIcon(c, g, x, y);
    3.68 +        }
    3.69 +
    3.70 +        public int getIconWidth() {
    3.71 +            return getDisabledIcon().getIconWidth();
    3.72 +        }
    3.73 +
    3.74 +        public int getIconHeight() {
    3.75 +            return getDisabledIcon().getIconHeight();
    3.76 +        }
    3.77 +
    3.78 +        private synchronized Icon getDisabledIcon() {
    3.79 +            if (null == disabledIcon) {
    3.80 +                disabledIcon = new ImageIcon(createDisabledImage(img));
    3.81 +            }
    3.82 +            return disabledIcon;
    3.83 +        }
    3.84 +
    3.85 +        static Image createDisabledImage(Image img) {
    3.86 +            ImageProducer prod = new FilteredImageSource(img.getSource(), DISABLED_BUTTON_FILTER);
    3.87 +            return Toolkit.getDefaultToolkit().createImage(prod);
    3.88 +        }
    3.89 +    }
    3.90 +
    3.91 +    private static class DisabledButtonFilter extends RGBImageFilter {
    3.92 +
    3.93 +        DisabledButtonFilter() {
    3.94 +            canFilterIndexColorModel = true;
    3.95 +        }
    3.96 +
    3.97 +        public int filterRGB(int x, int y, int rgb) {
    3.98 +            // Reduce the color bandwidth in quarter (>> 2) and Shift 0x88.
    3.99 +            return (rgb & 0xff000000) + 0x888888 + ((((rgb >> 16) & 0xff) >> 2) << 16) + ((((rgb >> 8) & 0xff) >> 2) << 8) + (((rgb) & 0xff) >> 2);
   3.100 +        }
   3.101 +
   3.102 +        // override the superclass behaviour to not pollute
   3.103 +        // the heap with useless properties strings. Saves tens of KBs
   3.104 +        @Override
   3.105 +        public void setProperties(Hashtable props) {
   3.106 +            props = (Hashtable) props.clone();
   3.107 +            consumer.setProperties(props);
   3.108 +        }
   3.109 +    }
   3.110  }