You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/04/23 16:27:26 UTC
svn commit: r767932 - in /incubator/pivot/trunk: core/src/pivot/util/
tutorials/src/pivot/tutorials/ tutorials/src/pivot/tutorials/lists/
wtk/src/pivot/wtk/ wtk/src/pivot/wtk/content/ wtk/src/pivot/wtk/effects/
wtk/src/pivot/wtk/text/ wtk/src/pivot/wtkx/
Author: tvolkert
Date: Thu Apr 23 14:27:25 2009
New Revision: 767932
URL: http://svn.apache.org/viewvc?rev=767932&view=rev
Log:
Added ThreadUtilities, and changed usages of Thread.currentThread().getContextClassLoader() to use ThreadUtilities.getClassLoader(), thus making Pivot work in the IcedTea plug-in for Linux and using custom boostrap applets. Added TODO in that utility method noting that the method may be removed in the future.
Added:
incubator/pivot/trunk/core/src/pivot/util/ThreadUtilities.java
Modified:
incubator/pivot/trunk/core/src/pivot/util/Service.java
incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists/ListButtons.java
incubator/pivot/trunk/wtk/src/pivot/wtk/Accordion.java
incubator/pivot/trunk/wtk/src/pivot/wtk/ImageView.java
incubator/pivot/trunk/wtk/src/pivot/wtk/TabPane.java
incubator/pivot/trunk/wtk/src/pivot/wtk/Window.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/ButtonData.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListItem.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/TableViewHeaderData.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeNode.java
incubator/pivot/trunk/wtk/src/pivot/wtk/effects/WatermarkDecorator.java
incubator/pivot/trunk/wtk/src/pivot/wtk/text/ImageNode.java
incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java
Modified: incubator/pivot/trunk/core/src/pivot/util/Service.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/pivot/util/Service.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/pivot/util/Service.java (original)
+++ incubator/pivot/trunk/core/src/pivot/util/Service.java Thu Apr 23 14:27:25 2009
@@ -54,7 +54,7 @@
if (providerClassName == null) {
String serviceName = "META-INF/services/" + providerName;
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
InputStream serviceInputStream = classLoader.getResourceAsStream(serviceName);
if (serviceInputStream != null) {
Added: incubator/pivot/trunk/core/src/pivot/util/ThreadUtilities.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/pivot/util/ThreadUtilities.java?rev=767932&view=auto
==============================================================================
--- incubator/pivot/trunk/core/src/pivot/util/ThreadUtilities.java (added)
+++ incubator/pivot/trunk/core/src/pivot/util/ThreadUtilities.java Thu Apr 23 14:27:25 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.util;
+
+/**
+ * Contains utility methods dealing with threads.
+ *
+ * @author tvolkert
+ */
+public final class ThreadUtilities {
+ private ThreadUtilities() {
+ }
+
+ /**
+ * Gets the class loader used to load the Pivot classes (and, by
+ * association, the application classes and resources).
+ *
+ * @return
+ * The Pivot class loader.
+ */
+ public static ClassLoader getClassLoader() {
+ // TODO This method is only necessary if the Pivot classes (and by
+ // association, the application classes and resources) were loaded
+ // from a different class loader than the UI thread's class loader.
+ // Curently, this case exists in the IcedTea plug-in and when we load
+ // the Pivot classes manully using a bootstrap applet. If these cases
+ // ever cease to exist, then this method becomes superfluous and should
+ // be replaced with Thread.currentThread().getContextClassLoader()
+ ClassLoader classLoader;
+
+ try {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) {
+ classLoader = ThreadUtilities.class.getClassLoader();
+ }
+
+ return classLoader;
+ }
+}
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java Thu Apr 23 14:27:25 2009
@@ -22,6 +22,7 @@
import java.io.InputStream;
import java.net.URL;
import java.util.Comparator;
+
import pivot.collections.ArrayList;
import pivot.collections.Dictionary;
import pivot.collections.List;
@@ -29,6 +30,7 @@
import pivot.serialization.JSONSerializer;
import pivot.serialization.SerializationException;
import pivot.util.CalendarDate;
+import pivot.util.ThreadUtilities;
import pivot.util.Vote;
import pivot.wtk.Action;
import pivot.wtk.Alert;
@@ -255,7 +257,7 @@
String imageName = (String)selectedItem.getUserData();
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
URL imageURL = classLoader.getResource(imageName);
// If the image has not been added to the resource cache yet,
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists/ListButtons.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists/ListButtons.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists/ListButtons.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists/ListButtons.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
import pivot.collections.Dictionary;
+import pivot.util.ThreadUtilities;
import pivot.wtk.Application;
import pivot.wtk.ApplicationContext;
import pivot.wtk.Component;
@@ -39,7 +40,7 @@
String item = (String)listButton.getListData().get(index);
// Get the image URL for the selected item
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
URL imageURL = classLoader.getResource("pivot/tutorials/" + item);
// If the image has not been added to the resource cache yet,
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Accordion.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Accordion.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Accordion.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Accordion.java Thu Apr 23 14:27:25 2009
@@ -23,6 +23,7 @@
import pivot.collections.Sequence;
import pivot.util.ImmutableIterator;
import pivot.util.ListenerList;
+import pivot.util.ThreadUtilities;
import pivot.util.Vote;
import pivot.wtk.media.Image;
@@ -342,7 +343,7 @@
throw new IllegalArgumentException("icon is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(component, classLoader.getResource(icon));
}
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/ImageView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/ImageView.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/ImageView.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/ImageView.java Thu Apr 23 14:27:25 2009
@@ -17,7 +17,9 @@
package pivot.wtk;
import java.net.URL;
+
import pivot.util.ListenerList;
+import pivot.util.ThreadUtilities;
import pivot.wtk.media.Image;
/**
@@ -110,7 +112,7 @@
throw new IllegalArgumentException("image is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setImage(classLoader.getResource(image));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/TabPane.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/TabPane.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/TabPane.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/TabPane.java Thu Apr 23 14:27:25 2009
@@ -18,10 +18,12 @@
import java.net.URL;
import java.util.Iterator;
+
import pivot.collections.ArrayList;
import pivot.collections.Sequence;
import pivot.util.ImmutableIterator;
import pivot.util.ListenerList;
+import pivot.util.ThreadUtilities;
import pivot.util.Vote;
import pivot.wtk.media.Image;
@@ -451,7 +453,7 @@
throw new IllegalArgumentException("icon is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(component, classLoader.getResource(icon));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Window.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Window.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Window.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Window.java Thu Apr 23 14:27:25 2009
@@ -24,6 +24,7 @@
import pivot.collections.HashMap;
import pivot.collections.Sequence;
import pivot.util.ListenerList;
+import pivot.util.ThreadUtilities;
import pivot.util.Vote;
import pivot.wtk.media.Image;
@@ -603,7 +604,7 @@
throw new IllegalArgumentException("icon is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(classLoader.getResource(icon));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/ButtonData.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/ButtonData.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/ButtonData.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/ButtonData.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.wtk.ApplicationContext;
import pivot.wtk.media.Image;
@@ -67,7 +68,7 @@
}
public void setIcon(String iconName) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(classLoader.getResource(iconName));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListItem.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListItem.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListItem.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListItem.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.wtk.ApplicationContext;
import pivot.wtk.media.Image;
@@ -67,7 +68,7 @@
}
public void setIcon(String iconName) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(classLoader.getResource(iconName));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/TableViewHeaderData.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/TableViewHeaderData.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/TableViewHeaderData.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/TableViewHeaderData.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.wtk.ApplicationContext;
import pivot.wtk.media.Image;
@@ -67,7 +68,7 @@
}
public void setIcon(String iconName) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(classLoader.getResource(iconName));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeNode.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeNode.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeNode.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeNode.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.wtk.ApplicationContext;
import pivot.wtk.media.Image;
@@ -67,7 +68,7 @@
}
public void setIcon(String iconName) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setIcon(classLoader.getResource(iconName));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/effects/WatermarkDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/effects/WatermarkDecorator.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/effects/WatermarkDecorator.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/effects/WatermarkDecorator.java Thu Apr 23 14:27:25 2009
@@ -22,6 +22,7 @@
import java.awt.geom.AffineTransform;
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.wtk.Component;
import pivot.wtk.FlowPane;
import pivot.wtk.ImageView;
@@ -200,7 +201,7 @@
throw new IllegalArgumentException("image is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setImage(classLoader.getResource(image));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/text/ImageNode.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/text/ImageNode.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/text/ImageNode.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/text/ImageNode.java Thu Apr 23 14:27:25 2009
@@ -18,6 +18,7 @@
import java.net.URL;
+import pivot.util.ThreadUtilities;
import pivot.util.ListenerList;
import pivot.wtk.media.Image;
@@ -87,7 +88,7 @@
throw new IllegalArgumentException("image is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
setImage(classLoader.getResource(image));
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java?rev=767932&r1=767931&r2=767932&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/WTKXSerializer.java Thu Apr 23 14:27:25 2009
@@ -45,6 +45,7 @@
import pivot.serialization.SerializationException;
import pivot.util.ListenerList;
import pivot.util.Resources;
+import pivot.util.ThreadUtilities;
/**
* Loads an object hierarchy from an XML document.
@@ -147,7 +148,7 @@
throw new IllegalArgumentException("resourceName is null.");
}
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
URL location = classLoader.getResource(resourceName);
if (location == null) {
@@ -349,7 +350,7 @@
}
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = ThreadUtilities.getClassLoader();
URL scriptLocation;
if (src.charAt(0) == '/') {