You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/16 15:25:14 UTC
svn commit: r825883 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk:
ApplicationContext.java ImageView.java
Author: gbrown
Date: Fri Oct 16 13:25:14 2009
New Revision: 825883
URL: http://svn.apache.org/viewvc?rev=825883&view=rev
Log:
Resolve issue PIVOT-132.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=825883&r1=825882&r2=825883&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Fri Oct 16 13:25:14 2009
@@ -45,6 +45,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;
@@ -55,12 +56,10 @@
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.collections.HashMap;
-import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.Version;
import org.apache.pivot.wtk.Component.DecoratorSequence;
import org.apache.pivot.wtk.effects.Decorator;
-
/**
* Base class for application contexts.
* <p>
@@ -1345,22 +1344,38 @@
implements Dictionary<URL, Object>, Iterable<URL> {
@Override
public Object get(URL key) {
- return resourceCache.get(key);
+ try {
+ return resourceCache.get(key.toURI());
+ } catch (URISyntaxException exception) {
+ throw new RuntimeException(exception);
+ }
}
@Override
public Object put(URL key, Object value) {
- return resourceCache.put(key, value);
+ try {
+ return resourceCache.put(key.toURI(), value);
+ } catch (URISyntaxException exception) {
+ throw new RuntimeException(exception);
+ }
}
@Override
public Object remove(URL key) {
- return resourceCache.remove(key);
+ try {
+ return resourceCache.remove(key.toURI());
+ } catch (URISyntaxException exception) {
+ throw new RuntimeException(exception);
+ }
}
@Override
public boolean containsKey(URL key) {
- return resourceCache.containsKey(key);
+ try {
+ return resourceCache.containsKey(key.toURI());
+ } catch (URISyntaxException exception) {
+ throw new RuntimeException(exception);
+ }
}
@Override
@@ -1370,7 +1385,28 @@
@Override
public Iterator<URL> iterator() {
- return new ImmutableIterator<URL>(resourceCache.iterator());
+ return new Iterator<URL>() {
+ private Iterator<URI> iterator = resourceCache.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public URL next() {
+ try {
+ return iterator.next().toURL();
+ } catch (MalformedURLException exception) {
+ throw new RuntimeException(exception);
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
}
}
@@ -1441,7 +1477,7 @@
protected static URL origin = null;
- private static HashMap<URL, Object> resourceCache = new HashMap<URL, Object>();
+ private static HashMap<URI, Object> resourceCache = new HashMap<URI, Object>();
private static ResourceCacheDictionary resourceCacheDictionary = new ResourceCacheDictionary();
private static Timer timer = null;
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=825883&r1=825882&r2=825883&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:25:14 2009
@@ -132,14 +132,14 @@
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()
+ // Convert to URI because using a URL as a key causes performance problems
final java.net.URI imageURI;
try {
imageURI = imageURL.toURI();
- } catch (URISyntaxException ex) {
- // should never happen
- throw new RuntimeException(ex);
+ } catch (URISyntaxException exception) {
+ throw new RuntimeException(exception);
}
+
if (asynchronous) {
if (loadMap.containsKey(imageURI)) {
// Add this to the list of image views that are interested in