1.1 --- a/openide.util/apichanges.xml Sun Feb 15 11:31:37 2009 +0100
1.2 +++ b/openide.util/apichanges.xml Mon Feb 16 17:41:54 2009 +0100
1.3 @@ -49,6 +49,21 @@
1.4 <apidef name="actions">Actions API</apidef>
1.5 </apidefs>
1.6 <changes>
1.7 + <change id="ImageUtilities.loadImageIcon">
1.8 + <api name="util"/>
1.9 + <summary>Added <code>loadImageIcon(String resource, boolean localized)</code></summary>
1.10 + <version major="7" minor="22"/>
1.11 + <date day="26" month="1" year="2009"/>
1.12 + <author login="t_h"/>
1.13 + <compatibility addition="yes"/>
1.14 + <description>
1.15 + <p>
1.16 + Convenient method for loading icons.
1.17 + </p>
1.18 + </description>
1.19 + <class package="org.openide.util" name="ImageUtilities"/>
1.20 + <issue number="157254"/>
1.21 + </change>
1.22 <change id="Utilities.keyToString">
1.23 <api name="util"/>
1.24 <summary>Added <code>keyToString(KeyStroke stroke, boolean portable)</code></summary>
2.1 --- a/openide.util/arch.xml Sun Feb 15 11:31:37 2009 +0100
2.2 +++ b/openide.util/arch.xml Mon Feb 16 17:41:54 2009 +0100
2.3 @@ -1001,4 +1001,49 @@
2.4 <defaultanswer generate='here' />
2.5 </answer>
2.6
2.7 +
2.8 +
2.9 +
2.10 +<!--
2.11 + <question id="compat-deprecation" when="init">
2.12 + How the introduction of your project influences functionality
2.13 + provided by previous version of the product?
2.14 + <hint>
2.15 + If you are planning to deprecate/remove/change any existing APIs,
2.16 + list them here accompanied with the reason explaining why you
2.17 + are doing so.
2.18 + </hint>
2.19 + </question>
2.20 +-->
2.21 + <answer id="compat-deprecation">
2.22 + <p>
2.23 + XXX no answer for compat-deprecation
2.24 + </p>
2.25 + </answer>
2.26 +
2.27 +
2.28 +
2.29 +<!--
2.30 + <question id="resources-preferences" when="final">
2.31 + Does your module uses preferences via Preferences API? Does your module use NbPreferences or
2.32 + or regular JDK Preferences ? Does it read, write or both ?
2.33 + Does it share preferences with other modules ? If so, then why ?
2.34 + <hint>
2.35 + You may use
2.36 + <api type="export" group="preferences"
2.37 + name="preference node name" category="private">
2.38 + description of individual keys, where it is used, what it
2.39 + influences, whether the module reads/write it, etc.
2.40 + </api>
2.41 + Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
2.42 + Note that if you use NbPreferences this name will then be the same as the code name base of the module.
2.43 + </hint>
2.44 + </question>
2.45 +-->
2.46 + <answer id="resources-preferences">
2.47 + <p>
2.48 + XXX no answer for resources-preferences
2.49 + </p>
2.50 + </answer>
2.51 +
2.52 </api-answers>
3.1 --- a/openide.util/nbproject/project.properties Sun Feb 15 11:31:37 2009 +0100
3.2 +++ b/openide.util/nbproject/project.properties Mon Feb 16 17:41:54 2009 +0100
3.3 @@ -42,7 +42,7 @@
3.4 module.jar.dir=lib
3.5 cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
3.6
3.7 -spec.version.base=7.21.0
3.8 +spec.version.base=7.22.0
3.9
3.10 # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
3.11
4.1 --- a/openide.util/src/org/openide/util/ImageUtilities.java Sun Feb 15 11:31:37 2009 +0100
4.2 +++ b/openide.util/src/org/openide/util/ImageUtilities.java Mon Feb 16 17:41:54 2009 +0100
4.3 @@ -137,7 +137,20 @@
4.4 */
4.5 public static final Image loadImage(String resource, boolean localized) {
4.6 return getIcon(resource, localized);
4.7 - }
4.8 + }
4.9 +
4.10 + /**
4.11 + * Loads an icon based on resource path.
4.12 + * Similar to {@link #loadImage(String, boolean)}, returns ImageIcon instead of Image.
4.13 + * @param resource resource path of the icon (no initial slash)
4.14 + * @param localized localized resource should be used
4.15 + * @return ImageIcon or null, if the icon cannot be loaded.
4.16 + * @since 7.22
4.17 + */
4.18 + public static final ImageIcon loadImageIcon(String resource, boolean localized) {
4.19 + Image image = getIcon(resource, localized);
4.20 + return (ImageIcon) image2Icon(image);
4.21 + }
4.22
4.23 /** This method merges two images into the new one. The second image is drawn
4.24 * over the first one with its top-left corner at x, y. Images need not be of the same size.
4.25 @@ -175,16 +188,12 @@
4.26
4.27 /**
4.28 * Converts given image to an icon.
4.29 - * <p><strong>Warning:</strong> do not use this method if your icon is intended
4.30 - * to be used on an action which is not always enabled. Many look-and-feel
4.31 - * implementations are incapable of graying out any {@link Icon} which is not
4.32 - * actually an {@link ImageIcon}.
4.33 * @param image to be converted
4.34 * @return icon corresponding icon
4.35 */
4.36 public static final Icon image2Icon(Image image) {
4.37 if (image instanceof ToolTipImage) {
4.38 - return (Icon) image;
4.39 + return ((ToolTipImage) image).getIcon();
4.40 } else {
4.41 return new ImageIcon(image);
4.42 }
4.43 @@ -196,8 +205,8 @@
4.44 * @param icon {@link javax.swing.Icon} to be converted.
4.45 */
4.46 public static final Image icon2Image(Icon icon) {
4.47 - if (icon instanceof ToolTipImage) {
4.48 - return (Image) icon;
4.49 + if (icon instanceof ImageIcon) {
4.50 + return ((ImageIcon) icon).getImage();
4.51 } else {
4.52 ToolTipImage image = new ToolTipImage("", icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
4.53 Graphics g = image.getGraphics();
4.54 @@ -672,8 +681,8 @@
4.55
4.56 /** Cleaning reference. */
4.57 private static final class ActiveRef<T> extends SoftReference<Image> implements Runnable {
4.58 - private Map<T,ActiveRef<T>> holder;
4.59 - private T key;
4.60 + private final Map<T,ActiveRef<T>> holder;
4.61 + private final T key;
4.62
4.63 public ActiveRef(Image o, Map<T,ActiveRef<T>> holder, T key) {
4.64 super(o, Utilities.activeReferenceQueue());
4.65 @@ -694,6 +703,7 @@
4.66 */
4.67 private static class ToolTipImage extends BufferedImage implements Icon {
4.68 final String toolTipText;
4.69 + ImageIcon imageIcon;
4.70
4.71 public static ToolTipImage createNew(String toolTipText, Image image) {
4.72 ImageUtilities.ensureLoaded(image);
4.73 @@ -728,7 +738,13 @@
4.74 super(image.getWidth(), image.getHeight(), image.getType());
4.75 this.toolTipText = toolTipText;
4.76 }
4.77 -
4.78 +
4.79 + synchronized ImageIcon getIcon() {
4.80 + if (imageIcon == null) {
4.81 + imageIcon = new ImageIcon(this);
4.82 + }
4.83 + return imageIcon;
4.84 + }
4.85
4.86 public int getIconHeight() {
4.87 return super.getHeight();
5.1 --- a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Sun Feb 15 11:31:37 2009 +0100
5.2 +++ b/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java Mon Feb 16 17:41:54 2009 +0100
5.3 @@ -168,11 +168,19 @@
5.4 str = ImageUtilities.getImageToolTip(result);
5.5 expected = "";
5.6 assertEquals("Tool tip text should be empty, but it is " + str, expected, str);
5.7 -
5.8 - Icon icon = ImageUtilities.image2Icon(result);
5.9 - assertSame("Should be same instance", icon, result);
5.10 + }
5.11
5.12 - Image img = ImageUtilities.icon2Image(icon);
5.13 - assertSame("Should be same instance", icon, img);
5.14 + public void testConversions() {
5.15 + Image image = ImageUtilities.loadImage("org/openide/util/testimage.png", false);
5.16 + Icon icon = ImageUtilities.loadImageIcon("org/openide/util/testimage.png", false);
5.17 +
5.18 + assertNotNull("Should not be null", icon);
5.19 + assertNotNull("Should not be null", image);
5.20 +
5.21 + Icon icon2 = ImageUtilities.image2Icon(image);
5.22 + Image image2 = ImageUtilities.icon2Image(icon);
5.23 +
5.24 + assertEquals("Should be same instance", icon, icon2);
5.25 + assertEquals("Should be same instance", image, image2);
5.26 }
5.27 }
6.1 Binary file openide.util/test/unit/src/org/openide/util/testimage.png has changed