You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2009/10/16 15:13:00 UTC
svn commit: r825876 -
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
Author: noelgrandin
Date: Fri Oct 16 13:13:00 2009
New Revision: 825876
URL: http://svn.apache.org/viewvc?rev=825876&view=rev
Log:
PIVOT-132 - don't use URL as a key in a hashmap
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java?rev=825876&r1=825875&r2=825876&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java Fri Oct 16 13:13:00 2009
@@ -16,6 +16,7 @@
*/
package org.apache.pivot.wtk;
+import java.net.URISyntaxException;
import java.net.URL;
import org.apache.pivot.collections.ArrayList;
@@ -66,8 +67,8 @@
// Maintains a mapping of image URL to image views that should be notified when
// an asynchronously loaded image is available
- private static HashMap<URL, ArrayList<ImageView>> loadMap =
- new HashMap<URL, ArrayList<ImageView>>();
+ private static HashMap<java.net.URI, ArrayList<ImageView>> loadMap =
+ new HashMap<java.net.URI, ArrayList<ImageView>>();
/**
* Creates an empty image view.
@@ -131,11 +132,19 @@
Image image = (Image)ApplicationContext.getResourceCache().get(imageURL);
if (image == null) {
+ // convert to URI because using URL in a hashmap is a no-no - URL does bad stuff in equals() and hashCode()
+ final java.net.URI imageURI;
+ try {
+ imageURI = imageURL.toURI();
+ } catch (URISyntaxException ex) {
+ // should never happen
+ throw new RuntimeException(ex);
+ }
if (asynchronous) {
- if (loadMap.containsKey(imageURL)) {
+ if (loadMap.containsKey(imageURI)) {
// Add this to the list of image views that are interested in
// the image at this URL
- loadMap.get(imageURL).add(this);
+ loadMap.get(imageURI).add(this);
} else {
Image.load(imageURL, new TaskAdapter<Image>(new TaskListener<Image>() {
@Override
@@ -144,11 +153,11 @@
// Update the contents of all image views that requested this
// image
- for (ImageView imageView : loadMap.get(imageURL)) {
+ for (ImageView imageView : loadMap.get(imageURI)) {
imageView.setImage(image);
}
- loadMap.remove(imageURL);
+ loadMap.remove(imageURI);
// Add the image to the cache
ApplicationContext.getResourceCache().put(imageURL, image);
@@ -160,7 +169,7 @@
}
}));
- loadMap.put(imageURL, new ArrayList<ImageView>(this));
+ loadMap.put(imageURI, new ArrayList<ImageView>(this));
}
} else {
try {