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/03/19 20:04:46 UTC

svn commit: r756136 - in /incubator/pivot/trunk: tutorials/src/pivot/tutorials/ wtk/src/pivot/wtk/ wtk/src/pivot/wtk/content/ wtk/src/pivot/wtk/skin/terra/

Author: gbrown
Date: Thu Mar 19 19:04:45 2009
New Revision: 756136

URL: http://svn.apache.org/viewvc?rev=756136&view=rev
Log:
Add support for list view item editors and table view row editors.

Added:
    incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java
Modified:
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists.wtkx
    incubator/pivot/trunk/wtk/src/pivot/wtk/ListView.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/ListViewListener.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/TableView.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/TableViewListener.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraListViewSkin.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTableViewSkin.java

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists.wtkx?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/lists.wtkx Thu Mar 19 19:04:45 2009
@@ -37,6 +37,9 @@
                                             <content:ListItem text="Purple"/>
                                         </collections:ArrayList>
                                     </listData>
+                                    <itemEditor>
+                                        <content:ListViewItemEditor/>
+                                    </itemEditor>
                                 </ListView>
                             </view>
                         </ScrollPane>

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/ListView.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/ListView.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/ListView.java Thu Mar 19 19:04:45 2009
@@ -85,6 +85,21 @@
     }
 
     /**
+     * List item editor interface.
+     *
+     * @author gbrown
+     */
+    public interface ItemEditor {
+        /**
+         * Notifies the editor that editing should begin.
+         *
+         * @param listView
+         * @param index
+         */
+        public void edit(ListView listView, int index);
+    }
+
+    /**
      * List view skin interface. List view skins are required to implement
      * this.
      *
@@ -217,6 +232,13 @@
             }
         }
 
+        public void itemEditorChanged(ListView listView,
+            ListView.ItemEditor previousItemEditor) {
+            for (ListViewListener listener : this) {
+                listener.itemEditorChanged(listView, previousItemEditor);
+            }
+        }
+
         public void selectModeChanged(ListView listView,
             ListView.SelectMode previousSelectMode) {
             for (ListViewListener listener : this) {
@@ -325,6 +347,7 @@
     private ListHandler listDataHandler = new ListHandler();
 
     private ItemRenderer itemRenderer = null;
+    private ItemEditor itemEditor = null;
 
     private SpanSequence selectedRanges = new SpanSequence();
     private SelectMode selectMode = SelectMode.SINGLE;
@@ -458,6 +481,31 @@
     }
 
     /**
+     * Returns the editor used to edit items in this list.
+     *
+     * @return
+     * The item editor, or <tt>null</tt> if no editor is installed.
+     */
+    public ItemEditor getItemEditor() {
+        return itemEditor;
+    }
+
+    /**
+     * Sets the editor used to edit items in this list.
+     *
+     * @param itemEditor
+     * The item editor for the list.
+     */
+    public void setItemEditor(ItemEditor itemEditor) {
+        ItemEditor previousItemEditor = this.itemEditor;
+
+        if (previousItemEditor != itemEditor) {
+            this.itemEditor = itemEditor;
+            listViewListeners.itemEditorChanged(this, previousItemEditor);
+        }
+    }
+
+    /**
      * When in single-select mode, returns the currently selected index.
      *
      * @return

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/ListViewListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/ListViewListener.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/ListViewListener.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/ListViewListener.java Thu Mar 19 19:04:45 2009
@@ -40,6 +40,14 @@
     public void itemRendererChanged(ListView listView, ListView.ItemRenderer previousItemRenderer);
 
     /**
+     * Called when a list view's item editor has changed.
+     *
+     * @param listView
+     * @param previousItemEditor
+     */
+    public void itemEditorChanged(ListView listView, ListView.ItemEditor previousItemEditor);
+
+    /**
      * Called when a list view's select mode has changed.
      *
      * @param listView

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/TableView.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/TableView.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/TableView.java Thu Mar 19 19:04:45 2009
@@ -434,6 +434,15 @@
     }
 
     /**
+     * Table row editor interface.
+     *
+     * gbrown
+     */
+    public interface RowEditor {
+        public void edit(TableView tableView, int rowIndex, int columnIndex);
+    }
+
+    /**
      * Table view skin interface. Table view skins must implement this.
      *
      * @author gbrown
@@ -672,6 +681,13 @@
             }
         }
 
+        public void rowEditorChanged(TableView tableView,
+            TableView.RowEditor previousRowEditor) {
+            for (TableViewListener listener : this) {
+                listener.rowEditorChanged(tableView, previousRowEditor);
+            }
+        }
+
         public void selectModeChanged(TableView tableView, SelectMode previousSelectMode) {
             for (TableViewListener listener : this) {
                 listener.selectModeChanged(tableView, previousSelectMode);
@@ -819,6 +835,8 @@
 
     private ArrayList<Integer> disabledIndexes = new ArrayList<Integer>();
 
+    private RowEditor rowEditor = null;
+
     private TableViewListenerList tableViewListeners = new TableViewListenerList();
     private TableViewColumnListenerList tableViewColumnListeners =
         new TableViewColumnListenerList();
@@ -921,6 +939,31 @@
     }
 
     /**
+     * Returns the editor used to edit rows in this table.
+     *
+     * @return
+     * The row editor, or <tt>null</tt> if no editor is installed.
+     */
+    public RowEditor getRowEditor() {
+        return rowEditor;
+    }
+
+    /**
+     * Sets the editor used to edit rows in this table.
+     *
+     * @param rowEditor
+     * The row editor for the list.
+     */
+    public void setRowEditor(RowEditor rowEditor) {
+        RowEditor previousRowEditor = this.rowEditor;
+
+        if (previousRowEditor != rowEditor) {
+            this.rowEditor = rowEditor;
+            tableViewListeners.rowEditorChanged(this, previousRowEditor);
+        }
+    }
+
+    /**
      * When in single-select mode, returns the currently selected index.
      *
      * @return

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/TableViewListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/TableViewListener.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/TableViewListener.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/TableViewListener.java Thu Mar 19 19:04:45 2009
@@ -32,6 +32,14 @@
     public void tableDataChanged(TableView tableView, List<?> previousTableData);
 
     /**
+     * Called when a table view's row editor has changed.
+     *
+     * @param tableView
+     * @param previousRowEditor
+     */
+    public void rowEditorChanged(TableView tableView, TableView.RowEditor previousRowEditor);
+
+    /**
      * Called when a table view's select mode has changed.
      *
      * @param tableView

Added: incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java?rev=756136&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java (added)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java Thu Mar 19 19:04:45 2009
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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.wtk.content;
+
+import pivot.wtk.ListView;
+
+/**
+ * Default list view item editor.
+ *
+ * @author gbrown
+ */
+public class ListViewItemEditor implements ListView.ItemEditor {
+    public void edit(ListView listView, int index) {
+        // TODO Get item bounds
+
+        // TODO Constrain bounds to viewports
+
+        // TODO Add listener for mouse events on listView so we can close the
+        // popup when the affiliate is clicked
+
+        System.out.println("BEGIN EDIT " + index);
+    }
+}

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraListViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraListViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraListViewSkin.java Thu Mar 19 19:04:45 2009
@@ -63,6 +63,7 @@
     private Insets checkboxPadding = new Insets(2, 2, 2, 0);
 
     private int highlightedIndex = -1;
+    private int editIndex = -1;
 
     private static final Checkbox CHECKBOX = new Checkbox();
 
@@ -246,8 +247,16 @@
     }
 
     public Bounds getItemBounds(int index) {
+        ListView listView = (ListView)getComponent();
         int itemHeight = getItemHeight();
-        return new Bounds(0, index * itemHeight, getWidth(), itemHeight);
+
+        Bounds itemBounds = new Bounds(0, index * itemHeight, getWidth(), itemHeight);
+        if (listView.getCheckmarksEnabled()) {
+            itemBounds.x = CHECKBOX.getWidth() + checkboxPadding.left + checkboxPadding.right;
+            itemBounds.width -= itemBounds.x;
+        }
+
+        return itemBounds;
     }
 
     public int getItemHeight() {
@@ -519,6 +528,7 @@
         }
 
         highlightedIndex = -1;
+        editIndex = -1;
     }
 
     @Override
@@ -575,10 +585,11 @@
                         listView.addSelectedIndex(itemIndex);
                     }
                 } else {
-                    // Select the item
-                    if ((selectMode == ListView.SelectMode.SINGLE
-                            && listView.getSelectedIndex() != itemIndex)
-                        || selectMode == ListView.SelectMode.MULTI) {
+                    if (listView.isItemSelected(itemIndex)) {
+                        // Edit the item
+                        editIndex = itemIndex;
+                    } else {
+                        // Select the item
                         listView.setSelectedIndex(itemIndex);
                     }
                 }
@@ -610,6 +621,17 @@
                 && y > itemY + checkboxPadding.top
                 && y < itemY + checkboxPadding.top + CHECKBOX.getHeight()) {
                 listView.setItemChecked(itemIndex, !listView.isItemChecked(itemIndex));
+            } else {
+                if (editIndex != -1
+                    && count == 1) {
+                    ListView.ItemEditor itemEditor = listView.getItemEditor();
+
+                    if (itemEditor != null) {
+                        itemEditor.edit(listView, editIndex);
+                    }
+                }
+
+                editIndex = -1;
             }
         }
 
@@ -739,6 +761,10 @@
         invalidateComponent();
     }
 
+    public void itemEditorChanged(ListView listView, ListView.ItemEditor previousItemEditor) {
+        // No-op
+    }
+
     public void selectModeChanged(ListView listView, ListView.SelectMode previousSelectMode) {
         repaintComponent();
     }

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=756136&r1=756135&r2=756136&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTableViewSkin.java Thu Mar 19 19:04:45 2009
@@ -71,6 +71,7 @@
     private boolean includeTrailingVerticalGridLine;
 
     private int highlightedIndex = -1;
+    private int editIndex = -1;
 
     public TerraTableViewSkin() {
         TerraTheme theme = (TerraTheme)Theme.getTheme();
@@ -804,6 +805,7 @@
         }
 
         highlightedIndex = -1;
+        editIndex = -1;
     }
 
     @Override
@@ -850,10 +852,11 @@
                     tableView.addSelectedIndex(rowIndex);
                 }
             } else {
-                // Select the row
-                if ((selectMode == TableView.SelectMode.SINGLE
-                        && tableView.getSelectedIndex() != rowIndex)
-                    || selectMode == TableView.SelectMode.MULTI) {
+                if (tableView.isRowSelected(rowIndex)) {
+                    // Edit the row
+                    editIndex = rowIndex;
+                } else {
+                    // Select the row
                     tableView.setSelectedIndex(rowIndex);
                 }
             }
@@ -863,6 +866,26 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
+    public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
+        boolean consumed = super.mouseClick(component, button, x, y, count);
+
+        TableView tableView = (TableView)getComponent();
+        if (editIndex != -1
+            && count == 1) {
+            TableView.RowEditor rowEditor = tableView.getRowEditor();
+
+            if (rowEditor != null) {
+                rowEditor.edit(tableView, editIndex, getColumnAt(x));
+            }
+        }
+
+        editIndex = -1;
+
+        return consumed;
+    }
+
+    @Override
     public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount,
         int wheelRotation, int x, int y) {
         if (highlightedIndex != -1) {
@@ -959,6 +982,10 @@
         invalidateComponent();
     }
 
+    public void rowEditorChanged(TableView tableView, TableView.RowEditor previousRowEditor) {
+        // No-op
+    }
+
     public void selectModeChanged(TableView tableView, TableView.SelectMode previousSelectMode) {
         // No-op
     }