Author: rwhitcomb
Date: Tue Feb  6 22:10:17 2018
New Revision: 1823399

URL: http://svn.apache.org/viewvc?rev=1823399&view=rev
Log:
Add an image name parameter to ImageUtils.findByName to make error
message more explicit.  So, change all the callers.

In addition, change some places that could use this method that were
not previously using it.

Modified:
    pivot/trunk/core/src/org/apache/pivot/util/ImageUtils.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/BaseContent.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeBranch.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java

Modified: pivot/trunk/core/src/org/apache/pivot/util/ImageUtils.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/ImageUtils.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/ImageUtils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/ImageUtils.java Tue Feb  6 
22:10:17 2018
@@ -28,17 +28,19 @@ public class ImageUtils {
      *
      * @param imageName The name of the image resource to find (whose
      * leading character is stripped off -- likely "@" or "/").
+     * @param imageType A user-friendly name of what this resource is (for
+     * error messages).
      * @return The URL from which to load the image if it is found.
      * @throws IllegalArgumentException if the image resource cannot be found,
      * or if the {@code imageName} is null or empty.
      */
-    public static URL findByName(String imageName) {
+    public static URL findByName(String imageName, String imageType) {
         Utils.checkNullOrEmpty(imageName, "imageName");
 
         ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
         URL url = classLoader.getResource(imageName.substring(1));
         if (url == null) {
-            throw new IllegalArgumentException("Cannot find image resource: " 
+ imageName);
+            throw new IllegalArgumentException("Cannot find " + imageType + " 
resource: " + imageName);
         }
         return url;
     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java Tue Feb  6 22:10:17 
2018
@@ -215,10 +215,10 @@ public class ImageView extends Component
      *
      * @param imageName The resource name of the image to set.
      * @see #setImage(URL)
-     * @see ImageUtils#findByName(String)
+     * @see ImageUtils#findByName(String,String)
      */
     public final void setImage(String imageName) {
-        setImage(ImageUtils.findByName(imageName));
+        setImage(ImageUtils.findByName(imageName, "image"));
     }
 
     /**

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java Tue Feb  6 22:10:17 
2018
@@ -23,6 +23,7 @@ import org.apache.pivot.beans.DefaultPro
 import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.HashMap;
 import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.util.ImageUtils;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.util.Utils;
@@ -632,16 +633,10 @@ public class Window extends Container {
      *
      * @param iconName The resource name of the icon to set.
      * @see #setIcon(URL)
+     * @see ImageUtils#findByName(String,String)
      */
     public void setIcon(String iconName) {
-        Utils.checkNull(iconName, "iconName");
-
-        ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
-        URL url = classLoader.getResource(iconName.substring(1));
-        if (url == null) {
-            throw new IllegalArgumentException("Cannot find icon resource " + 
iconName);
-        }
-        setIcon(url);
+        setIcon(ImageUtils.findByName(iconName, "icon"));
     }
 
     public Component getContent() {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/BaseContent.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/BaseContent.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/BaseContent.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/BaseContent.java Tue Feb  
6 22:10:17 2018
@@ -71,10 +71,10 @@ public class BaseContent {
      *
      * @param iconName The resource name of the icon to set.
      * @see #setIcon(URL)
-     * @see ImageUtils#findByName(String)
+     * @see ImageUtils#findByName(String,String)
      */
     public void setIcon(String iconName) {
-        setIcon(ImageUtils.findByName(iconName));
+        setIcon(ImageUtils.findByName(iconName, "icon"));
     }
 
     public String getText() {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeBranch.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeBranch.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeBranch.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeBranch.java Tue Feb  6 
22:10:17 2018
@@ -24,6 +24,7 @@ import org.apache.pivot.collections.Arra
 import org.apache.pivot.collections.List;
 import org.apache.pivot.collections.ListListener;
 import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.util.ImageUtils;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.util.Utils;
@@ -90,15 +91,7 @@ public class TreeBranch extends TreeNode
      * @see #setExpandedIcon(URL)
      */
     public void setExpandedIcon(String expandedIconName) {
-        Utils.checkNullOrEmpty(expandedIconName, "expandedIconName");
-
-        ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
-        URL url = classLoader.getResource(expandedIconName.substring(1));
-        if (url == null) {
-            throw new IllegalArgumentException("Cannot find expandedIcon 
resource: "
-                + expandedIconName);
-        }
-        setExpandedIcon(url);
+        setExpandedIcon(ImageUtils.findByName(expandedIconName, "expanded 
icon"));
     }
 
     private void checkNode(TreeNode treeNode) {

Modified: 
pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java?rev=1823399&r1=1823398&r2=1823399&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java 
(original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java 
Tue Feb  6 22:10:17 2018
@@ -33,6 +33,7 @@ import org.apache.pivot.wtk.FontUtilitie
 import org.apache.pivot.wtk.ImageView;
 import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.Orientation;
+import org.apache.pivot.wtk.Style;
 import org.apache.pivot.wtk.Theme;
 import org.apache.pivot.wtk.VerticalAlignment;
 import org.apache.pivot.wtk.media.Image;
@@ -89,7 +90,7 @@ public class WatermarkDecorator implemen
         boxPane.add(imageView);
         boxPane.add(label);
 
-        boxPane.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+        boxPane.getStyles().put(Style.verticalAlignment, 
VerticalAlignment.CENTER);
         imageView.getStyles().put("opacity", opacity);
 
         Font font = (Font) label.getStyles().get("font");
@@ -186,10 +187,10 @@ public class WatermarkDecorator implemen
      *
      * @param imageName The resource name of the image to set.
      * @see #setImage(URL)
-     * @see ImageUtils#findByName(String)
+     * @see ImageUtils#findByName(String,String)
      */
     public void setImage(String imageName) {
-        setImage(ImageUtils.findByName(imageName));
+        setImage(ImageUtils.findByName(imageName, "image"));
     }
 
     /**


Reply via email to