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/09/25 16:25:07 UTC

svn commit: r818862 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ content/ effects/ skin/terra/ text/

Author: tvolkert
Date: Fri Sep 25 14:25:06 2009
New Revision: 818862

URL: http://svn.apache.org/viewvc?rev=818862&view=rev
Log:
Changed ListView.ItemRenderer to take a valid index (not -1) whenever the item is non-null; same for TableView.CellRenderer's rowIndex.  Added resource cache logic to all methods that take a URL and pass through to Image setter; added Javadoc around such methods

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ButtonData.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListItem.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewHeaderData.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeNode.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ImageNode.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=818862&r1=818861&r2=818862&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 Sep 25 14:25:06 2009
@@ -117,7 +117,7 @@
     }
 
     /**
-     * Sets the image view's icon by {@linkplain ClassLoader#getResource(String)
+     * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
      * resource name}.
      * <p>
      * <b>Note</b>: Using this signature will cause an entry to be added in the

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Fri Sep 25 14:25:06 2009
@@ -68,11 +68,11 @@
          *
          * @param item
          * The item to render, or <tt>null</tt> if called to calculate
-         * preferred size.
+         * preferred height.
          *
          * @param index
          * The index of the item being rendered, or <tt>-1</tt> if called to
-         * calculate preferred size.
+         * calculate preferred height.
          *
          * @param listView
          * The list view that contains the item.

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Fri Sep 25 14:25:06 2009
@@ -383,11 +383,11 @@
          *
          * @param value
          * The cell value to render, or <tt>null</tt> if called to calculate
-         * preferred size.
+         * preferred height.
          *
          * @param rowIndex
          * The index of the row being rendered, or <tt>-1</tt> if called to
-         * calculate preferred size.
+         * calculate preferred height.
          *
          * @param columnIndex
          * The index of the column being rendered.

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java Fri Sep 25 14:25:06 2009
@@ -723,24 +723,41 @@
 
     /**
      * Sets the window's icon by URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
      *
-     * @param icon
+     * @param iconURL
      * The location of the icon to set.
      */
-    public void setIcon(URL icon) {
-        if (icon == null) {
-            throw new IllegalArgumentException("icon is null.");
+    public void setIcon(URL iconURL) {
+        if (iconURL == null) {
+            throw new IllegalArgumentException("iconURL is null.");
         }
 
-        try {
-            setIcon(Image.load(icon));
-        } catch (TaskExecutionException exception) {
-            throw new IllegalArgumentException(exception);
+        Image icon = (Image)ApplicationContext.getResourceCache().get(iconURL);
+
+        if (icon == null) {
+            try {
+                icon = Image.load(iconURL);
+            } catch (TaskExecutionException exception) {
+                throw new IllegalArgumentException(exception);
+            }
+
+            ApplicationContext.getResourceCache().put(iconURL, icon);
         }
+
+        setIcon(icon);
     }
 
     /**
-     * Sets the window's icon by resource name.
+     * Sets the window's icon by {@linkplain ClassLoader#getResource(String)
+     * resource name}.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
      *
      * @param icon
      * The resource name of the icon to set.

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ButtonData.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ButtonData.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ButtonData.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ButtonData.java Fri Sep 25 14:25:06 2009
@@ -67,6 +67,10 @@
      * The location of the icon to set.
      */
     public void setIcon(URL iconURL) {
+        if (iconURL == null) {
+            throw new IllegalArgumentException("iconURL is null.");
+        }
+
         Image icon = (Image)ApplicationContext.getResourceCache().get(iconURL);
 
         if (icon == null) {
@@ -94,6 +98,10 @@
      * The resource name of the icon to set.
      */
     public void setIcon(String iconName) {
+        if (iconName == null) {
+            throw new IllegalArgumentException("iconName is null.");
+        }
+
         ClassLoader classLoader = ThreadUtilities.getClassLoader();
         setIcon(classLoader.getResource(iconName));
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListItem.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListItem.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListItem.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListItem.java Fri Sep 25 14:25:06 2009
@@ -56,7 +56,21 @@
         this.icon = icon;
     }
 
+    /**
+     * Sets the list item's icon by URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconURL
+     * The location of the icon to set.
+     */
     public void setIcon(URL iconURL) {
+        if (iconURL == null) {
+            throw new IllegalArgumentException("iconURL is null.");
+        }
+
         Image icon = (Image)ApplicationContext.getResourceCache().get(iconURL);
 
         if (icon == null) {
@@ -72,7 +86,22 @@
         setIcon(icon);
     }
 
+    /**
+     * Sets the list item's icon by {@linkplain ClassLoader#getResource(String)
+     * resource name}.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconName
+     * The resource name of the icon to set.
+     */
     public void setIcon(String iconName) {
+        if (iconName == null) {
+            throw new IllegalArgumentException("iconName is null.");
+        }
+
         ClassLoader classLoader = ThreadUtilities.getClassLoader();
         setIcon(classLoader.getResource(iconName));
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewHeaderData.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewHeaderData.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewHeaderData.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewHeaderData.java Fri Sep 25 14:25:06 2009
@@ -56,7 +56,21 @@
         this.icon = icon;
     }
 
+    /**
+     * Sets the header data's icon by URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconURL
+     * The location of the icon to set.
+     */
     public void setIcon(URL iconURL) {
+        if (iconURL == null) {
+            throw new IllegalArgumentException("iconURL is null.");
+        }
+
         Image icon = (Image)ApplicationContext.getResourceCache().get(iconURL);
 
         if (icon == null) {
@@ -72,7 +86,22 @@
         setIcon(icon);
     }
 
+    /**
+     * Sets the header data's icon by {@linkplain ClassLoader#getResource(String)
+     * resource name}.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconName
+     * The resource name of the icon to set.
+     */
     public void setIcon(String iconName) {
+        if (iconName == null) {
+            throw new IllegalArgumentException("iconName is null.");
+        }
+
         ClassLoader classLoader = ThreadUtilities.getClassLoader();
         setIcon(classLoader.getResource(iconName));
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeNode.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeNode.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeNode.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeNode.java Fri Sep 25 14:25:06 2009
@@ -56,7 +56,21 @@
         this.icon = icon;
     }
 
+    /**
+     * Sets the tree node's icon by URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconURL
+     * The location of the icon to set.
+     */
     public void setIcon(URL iconURL) {
+        if (iconURL == null) {
+            throw new IllegalArgumentException("iconURL is null.");
+        }
+
         Image icon = (Image)ApplicationContext.getResourceCache().get(iconURL);
 
         if (icon == null) {
@@ -72,7 +86,22 @@
         setIcon(icon);
     }
 
+    /**
+     * Sets the tree node's icon by {@linkplain ClassLoader#getResource(String)
+     * resource name}.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param iconName
+     * The resource name of the icon to set.
+     */
     public void setIcon(String iconName) {
+        if (iconName == null) {
+            throw new IllegalArgumentException("iconName is null.");
+        }
+
         ClassLoader classLoader = ThreadUtilities.getClassLoader();
         setIcon(classLoader.getResource(iconName));
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/WatermarkDecorator.java Fri Sep 25 14:25:06 2009
@@ -24,6 +24,7 @@
 
 import org.apache.pivot.util.ThreadUtilities;
 import org.apache.pivot.util.concurrent.TaskExecutionException;
+import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.BoxPane;
@@ -177,25 +178,42 @@
     }
 
     /**
-     * Sets the image that will be painted over this decorator's component.
-     *
-     * @param image
-     * This decorator's image
-     */
-    public void setImage(URL image) {
-        if (image == null) {
-            throw new IllegalArgumentException("image is null.");
+     * Sets the image that will be painted over this decorator's component by
+     * URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param imageURL
+     * This location of the image to set.
+     */
+    public void setImage(URL imageURL) {
+        if (imageURL == null) {
+            throw new IllegalArgumentException("imageURL is null.");
         }
 
-        try {
-            setImage(Image.load(image));
-        } catch (TaskExecutionException exception) {
-            throw new IllegalArgumentException(exception);
+        Image image = (Image)ApplicationContext.getResourceCache().get(imageURL);
+
+        if (image == null) {
+            try {
+                image = Image.load(imageURL);
+            } catch (TaskExecutionException exception) {
+                throw new IllegalArgumentException(exception);
+            }
+
+            ApplicationContext.getResourceCache().put(imageURL, image);
         }
+
+        setImage(image);
     }
 
     /**
      * Sets the image that will be painted over this decorator's component.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
      *
      * @param image
      * This decorator's image

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java Fri Sep 25 14:25:06 2009
@@ -109,8 +109,9 @@
 
         ListView.ItemRenderer renderer = listView.getItemRenderer();
 
+        int index = 0;
         for (Object item : listData) {
-            renderer.render(item, -1, listView, false, false, false, false);
+            renderer.render(item, index++, listView, false, false, false, false);
             preferredWidth = Math.max(preferredWidth, renderer.getPreferredWidth(-1));
         }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java Fri Sep 25 14:25:06 2009
@@ -133,8 +133,9 @@
                     TableView.CellRenderer cellRenderer = column.getCellRenderer();
                     List<?> tableData = tableView.getTableData();
 
+                    int rowIndex = 0;
                     for (Object rowData : tableData) {
-                        cellRenderer.render(rowData, -1, i, tableView, column.getName(),
+                        cellRenderer.render(rowData, rowIndex++, i, tableView, column.getName(),
                             false, false, false);
                         columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
                     }
@@ -212,8 +213,9 @@
                     TableView.CellRenderer cellRenderer = column.getCellRenderer();
                     List<?> tableData = tableView.getTableData();
 
+                    int rowIndex = 0;
                     for (Object rowData : tableData) {
-                        cellRenderer.render(rowData, -1, i, tableView, column.getName(),
+                        cellRenderer.render(rowData, rowIndex++, i, tableView, column.getName(),
                             false, false, false);
                         columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
                     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ImageNode.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ImageNode.java?rev=818862&r1=818861&r2=818862&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ImageNode.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/ImageNode.java Fri Sep 25 14:25:06 2009
@@ -21,6 +21,7 @@
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.util.ThreadUtilities;
 import org.apache.pivot.util.concurrent.TaskExecutionException;
+import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.media.Image;
 
 
@@ -76,18 +77,47 @@
         }
     }
 
-    public void setImage(URL image) {
-        if (image == null) {
-            throw new IllegalArgumentException("image is null.");
+    /**
+     * Sets the image node's current image by URL.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param imageURL
+     * The location of the image to set.
+     */
+    public void setImage(URL imageURL) {
+        if (imageURL == null) {
+            throw new IllegalArgumentException("imageURL is null.");
         }
 
-        try {
-            setImage(Image.load(image));
-        } catch (TaskExecutionException exception) {
-            throw new IllegalArgumentException(exception);
+        Image image = (Image)ApplicationContext.getResourceCache().get(imageURL);
+
+        if (image == null) {
+            try {
+                image = Image.load(imageURL);
+            } catch (TaskExecutionException exception) {
+                throw new IllegalArgumentException(exception);
+            }
+
+            ApplicationContext.getResourceCache().put(imageURL, image);
         }
+
+        setImage(image);
     }
 
+    /**
+     * Sets the image node's icon by {@linkplain ClassLoader#getResource(String)
+     * resource name}.
+     * <p>
+     * <b>Note</b>: Using this signature will cause an entry to be added in the
+     * application context's {@linkplain ApplicationContext#getResourceCache()
+     * resource cache} if one does not already exist.
+     *
+     * @param image
+     * The resource name of the image to set.
+     */
     public void setImage(String image) {
         if (image == null) {
             throw new IllegalArgumentException("image is null.");