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/08/03 15:37:21 UTC

svn commit: r800377 - in /incubator/pivot/trunk: core/src/org/apache/pivot/collections/ demos/www/ tutorials/src/org/apache/pivot/tutorials/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/

Author: gbrown
Date: Mon Aug  3 13:37:21 2009
New Revision: 800377

URL: http://svn.apache.org/viewvc?rev=800377&view=rev
Log:
Additional work on PIVOT-192; other minor updates.

Added:
    incubator/pivot/trunk/demos/www/multiselect.template.html
Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/FilteredList.java
    incubator/pivot/trunk/demos/www/index.html
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButtonListener.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/FilteredList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/FilteredList.java?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/FilteredList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/FilteredList.java Mon Aug  3 13:37:21 2009
@@ -201,7 +201,8 @@
                 for (T item : source) {
                     if (filter == null
                         || filter.include(item)) {
-                        listListeners.itemInserted(this, view.add(item));
+                        int index = view.add(item);
+                        listListeners.itemInserted(this, index);
                     }
                 }
             }
@@ -243,7 +244,8 @@
                 for (T item : source) {
                     if (filter == null
                         || filter.include(item)) {
-                        listListeners.itemInserted(this, view.add(item));
+                        int index = view.add(item);
+                        listListeners.itemInserted(this, index);
                     }
                 }
             }

Modified: incubator/pivot/trunk/demos/www/index.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/www/index.html?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/www/index.html (original)
+++ incubator/pivot/trunk/demos/www/index.html Mon Aug  3 13:37:21 2009
@@ -109,5 +109,12 @@
 handy when displaying tables with many columns.<br>
 </p>
 
+<p>
+<a href="multiselect.html">Multiple Selection</a><br>
+Demonstrates Pivot's use of ranges to maintain selection state in a ListView
+component. This is more efficient than maintaining a list of individual
+selected indexes.<br>
+</p>
+
 </body>
 </html>

Added: incubator/pivot/trunk/demos/www/multiselect.template.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/www/multiselect.template.html?rev=800377&view=auto
==============================================================================
--- incubator/pivot/trunk/demos/www/multiselect.template.html (added)
+++ incubator/pivot/trunk/demos/www/multiselect.template.html Mon Aug  3 13:37:21 2009
@@ -0,0 +1,42 @@
+<!--
+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.
+-->
+
+<html>
+<head>
+<title>Pivot Multiple Selection Demo</title>
+</head>
+<body>
+<p>This application demonstrates Pivot's use of ranges to maintain selection state in a ListView component. This is more efficient than maintaining a list of individual selected indexes.</p>
+
+<script src="http://java.com/js/deployJava.js"></script>
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+    archive:"lib/@project_name@-core-@version@.jar,lib/@project_name@-wtk-@version@.jar,lib/@project_name@-wtk-@version@.terra.jar,lib/@project_name@-tutorials-@version@.jar",
+    width:480,
+    height:360
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.lists.MultiSelect",
+    codebase_lookup:false
+};
+var version = "1.6";
+deployJava.runApplet(attributes, parameters, version);
+</script>
+
+<p>TableView also maintains selection in this manner.</p>
+
+</body>
+</html>

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/KitchenSink.java Mon Aug  3 13:37:21 2009
@@ -41,6 +41,7 @@
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.ButtonPressListener;
 import org.apache.pivot.wtk.ComponentMouseButtonListener;
+import org.apache.pivot.wtk.ListButton;
 import org.apache.pivot.wtk.MenuHandler;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.DragSource;
@@ -120,6 +121,7 @@
         private ListView editableListView = null;
         private ListView iconListView = null;
         private ListView checkedListView = null;
+        private ListButton iconListButton = null;
 
         @SuppressWarnings("unchecked")
         public Vote previewExpandedChange(Rollup rollup) {
@@ -136,6 +138,7 @@
                 editableListView = (ListView)wtkxSerializer.get("editableListView");
                 iconListView = (ListView)wtkxSerializer.get("iconListView");
                 checkedListView = (ListView)wtkxSerializer.get("checkedListView");
+                iconListButton = (ListButton)wtkxSerializer.get("iconListButton");
 
                 rollup.setContent(component);
 
@@ -148,11 +151,15 @@
                     }
                 });
 
-                iconListView.setDisabledItemFilter(new Filter<ListItem>() {
+
+                Filter<ListItem> disabledItemFilter = new Filter<ListItem>() {
                     public boolean include(ListItem listItem) {
                         return Character.toLowerCase(listItem.getText().charAt(0)) == 'c';
                     }
-                });
+                };
+
+                iconListView.setDisabledItemFilter(disabledItemFilter);
+                iconListButton.setDisabledItemFilter(disabledItemFilter);
 
                 checkedListView.setItemChecked(0, true);
                 checkedListView.setItemChecked(2, true);

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx Mon Aug  3 13:37:21 2009
@@ -135,7 +135,7 @@
                                 </listData>
                             </ListButton>
 
-                            <ListButton Form.label="Image" selectedIndex="2">
+                            <ListButton wtkx:id="iconListButton" Form.label="Image" selectedIndex="2">
                                 <listData>
                                     <collections:ArrayList>
                                         <content:ListItem icon="@anchor.png" text="Anchor"/>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java Mon Aug  3 13:37:21 2009
@@ -21,6 +21,7 @@
 import org.apache.pivot.collections.List;
 import org.apache.pivot.serialization.JSONSerializer;
 import org.apache.pivot.serialization.SerializationException;
+import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.wtk.content.ListButtonDataRenderer;
 import org.apache.pivot.wtk.content.ListViewItemRenderer;
@@ -52,6 +53,12 @@
             }
         }
 
+        public void disabledItemFilterChanged(ListButton listButton, Filter<?> previousDisabledItemFilter) {
+            for (ListButtonListener listener : this) {
+                listener.disabledItemFilterChanged(listButton, previousDisabledItemFilter);
+            }
+        }
+
         public void selectedItemKeyChanged(ListButton listButton, String previousSelectedItemKey) {
             for (ListButtonListener listener : this) {
                 listener.selectedItemKeyChanged(listButton, previousSelectedItemKey);
@@ -76,6 +83,7 @@
     private List<?> listData;
     private ListView.ItemRenderer itemRenderer = null;
     private int selectedIndex = -1;
+    private Filter<?> disabledItemFilter = null;
     private String selectedItemKey = null;
 
     private ListButtonListenerList listButtonListeners = new ListButtonListenerList();
@@ -265,6 +273,54 @@
         setSelectedIndex(index);
     }
 
+    /**
+     * Returns an item's disabled state.
+     *
+     * @param index
+     * The index of the item whose disabled state is to be tested.
+     *
+     * @return
+     * <tt>true</tt> if the item is disabled; <tt>false</tt>,
+     * otherwise.
+     */
+    @SuppressWarnings("unchecked")
+    public boolean isItemDisabled(int index) {
+        boolean disabled = false;
+
+        if (disabledItemFilter != null) {
+            Object item = listData.get(index);
+            disabled = ((Filter<Object>)disabledItemFilter).include(item);
+        }
+
+        return disabled;
+    }
+
+    /**
+     * Returns the disabled item filter.
+     *
+     * @return
+     * The disabled item filter, or <tt>null</tt> if no disabled item filter is
+     * set.
+     */
+    public Filter<?> getDisabledItemFilter() {
+        return disabledItemFilter;
+    }
+
+    /**
+     * Sets the disabled item filter.
+     *
+     * @param disabledItemFilter
+     * The disabled item filter, or <tt>null</tt> for no disabled item filter.
+     */
+    public void setDisabledItemFilter(Filter<?> disabledItemFilter) {
+        Filter<?> previousDisabledItemFilter = this.disabledItemFilter;
+
+        if (previousDisabledItemFilter != disabledItemFilter) {
+            this.disabledItemFilter = disabledItemFilter;
+            listButtonListeners.disabledItemFilterChanged(this, previousDisabledItemFilter);
+        }
+    }
+
     public String getSelectedItemKey() {
         return selectedItemKey;
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButtonListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButtonListener.java?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButtonListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButtonListener.java Mon Aug  3 13:37:21 2009
@@ -17,6 +17,7 @@
 package org.apache.pivot.wtk;
 
 import org.apache.pivot.collections.List;
+import org.apache.pivot.util.Filter;
 
 /**
  * List button listener list interface.
@@ -41,6 +42,14 @@
     public void itemRendererChanged(ListButton listButton, ListView.ItemRenderer previousItemRenderer);
 
     /**
+     * Called when a list button's disabled item filter has changed.
+     *
+     * @param listButton
+     * @param previousDisabledItemFilter
+     */
+    public void disabledItemFilterChanged(ListButton listButton, Filter<?> previousDisabledItemFilter);
+
+    /**
      * Called when a list button's selected value key has changed.
      *
      * @param listButton

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java?rev=800377&r1=800376&r2=800377&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java Mon Aug  3 13:37:21 2009
@@ -18,6 +18,7 @@
 
 import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.List;
+import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.Vote;
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.Component;
@@ -394,6 +395,10 @@
         listView.setItemRenderer(listButton.getItemRenderer());
     }
 
+    public void disabledItemFilterChanged(ListButton listButton, Filter<?> previousDisabledItemFilter) {
+        listView.setDisabledItemFilter(listButton.getDisabledItemFilter());
+    }
+
     public void selectedItemKeyChanged(ListButton listButton, String previousSelectedItemKey) {
         // No-op
     }