+
+ XXX no answer for resources-preferences
+
+
+
diff --git a/openide.util/nbproject/project.properties b/openide.util/nbproject/project.properties
--- a/openide.util/nbproject/project.properties
+++ b/openide.util/nbproject/project.properties
@@ -42,7 +42,7 @@
module.jar.dir=lib
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
-spec.version.base=7.21.0
+spec.version.base=7.22.0
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
diff --git a/openide.util/src/org/openide/util/ImageUtilities.java b/openide.util/src/org/openide/util/ImageUtilities.java
--- a/openide.util/src/org/openide/util/ImageUtilities.java
+++ b/openide.util/src/org/openide/util/ImageUtilities.java
@@ -137,7 +137,20 @@
*/
public static final Image loadImage(String resource, boolean localized) {
return getIcon(resource, localized);
- }
+ }
+
+ /**
+ * Loads an icon based on resource path.
+ * Similar to {@link #loadImage(String, boolean)}, returns Icon instead of Image.
+ * @param resource resource path of the icon (no initial slash)
+ * @param localized localized resource should be used
+ * @return Icon or null, if the icon cannot be loaded.
+ * @since 7.22
+ */
+ public static final Icon loadIcon(String resource, boolean localized) {
+ Image image = getIcon(resource, localized);
+ return image2Icon(image);
+ }
/** This method merges two images into the new one. The second image is drawn
* over the first one with its top-left corner at x, y. Images need not be of the same size.
@@ -184,7 +197,7 @@
*/
public static final Icon image2Icon(Image image) {
if (image instanceof ToolTipImage) {
- return (Icon) image;
+ return ((ToolTipImage) image).getIcon();
} else {
return new ImageIcon(image);
}
@@ -196,8 +209,8 @@
* @param icon {@link javax.swing.Icon} to be converted.
*/
public static final Image icon2Image(Icon icon) {
- if (icon instanceof ToolTipImage) {
- return (Image) icon;
+ if (icon instanceof ImageIcon) {
+ return ((ImageIcon) icon).getImage();
} else {
ToolTipImage image = new ToolTipImage("", icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
@@ -692,8 +705,9 @@
/**
* Image with tool tip text (for icons with badges)
*/
- private static class ToolTipImage extends BufferedImage implements Icon {
+ private static class ToolTipImage extends BufferedImage {
final String toolTipText;
+ ImageIcon imageIcon;
public static ToolTipImage createNew(String toolTipText, Image image) {
ImageUtilities.ensureLoaded(image);
@@ -728,18 +742,12 @@
super(image.getWidth(), image.getHeight(), image.getType());
this.toolTipText = toolTipText;
}
-
- public int getIconHeight() {
- return super.getHeight();
- }
-
- public int getIconWidth() {
- return super.getWidth();
- }
-
- public void paintIcon(Component c, Graphics g, int x, int y) {
- g.drawImage(this, x, y, null);
+ synchronized ImageIcon getIcon() {
+ if (imageIcon == null) {
+ imageIcon = new ImageIcon(this);
+ }
+ return imageIcon;
}
}
}
diff --git a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java b/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java
--- a/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java
+++ b/openide.util/test/unit/src/org/openide/util/ImageUtilitiesTest.java
@@ -168,11 +168,19 @@
str = ImageUtilities.getImageToolTip(result);
expected = "";
assertEquals("Tool tip text should be empty, but it is " + str, expected, str);
-
- Icon icon = ImageUtilities.image2Icon(result);
- assertSame("Should be same instance", icon, result);
+ }
- Image img = ImageUtilities.icon2Image(icon);
- assertSame("Should be same instance", icon, img);
+ public void testConversions() {
+ Image image = ImageUtilities.loadImage("org/openide/util/test_image.png", false);
+ Icon icon = ImageUtilities.loadIcon("org/openide/util/test_image.png", false);
+
+ assertNotNull("Should not be null", icon);
+ assertNotNull("Should not be null", image);
+
+ Icon icon2 = ImageUtilities.image2Icon(image);
+ Image image2 = ImageUtilities.icon2Image(icon);
+
+ assertEquals("Should be same instance", icon, icon2);
+ assertEquals("Should be same instance", image, image2);
}
}
diff --git a/openide.util/test/unit/src/org/openide/util/testimage.png b/openide.util/test/unit/src/org/openide/util/testimage.png
new file mode 100644
index 0000000000000000000000000000000000000000..0192f143b4d1706ecf387ab2deef7d2790fa3fa6
GIT binary patch
literal 689
zc$@*T0#5yjP)