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/13 14:48:48 UTC

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

Author: gbrown
Date: Thu Aug 13 12:48:48 2009
New Revision: 803866

URL: http://svn.apache.org/viewvc?rev=803866&view=rev
Log:
Ensure that text is selected in list, table, and tree editors.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.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/TextArea.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Thu Aug 13 12:48:48 2009
@@ -2201,13 +2201,13 @@
      * otherwise, the component that has gained the focus.
      */
     private void setFocused(boolean focused, Component obverseComponent) {
-        componentStateListeners.focusedChanged(this, obverseComponent);
-
         if (focused) {
             parent.descendantGainedFocus(this, obverseComponent);
         } else {
             parent.descendantLostFocus(this);
         }
+
+        componentStateListeners.focusedChanged(this, obverseComponent);
     }
 
     /**

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=803866&r1=803865&r2=803866&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 Thu Aug 13 12:48:48 2009
@@ -522,11 +522,18 @@
      * The index to select, or <tt>-1</tt> to clear the selection.
      */
     public void setSelectedIndex(int index) {
-        ArrayList<Span> selectedRanges = new ArrayList<Span>();
+        setSelectedRange(index, index);
+    }
 
-        if (index >= 0) {
-            selectedRanges.add(new Span(index));
-        }
+    /**
+     * Sets the selection to a single range.
+     *
+     * @param start
+     * @param end
+     */
+    public void setSelectedRange(int start, int end) {
+        ArrayList<Span> selectedRanges = new ArrayList<Span>();
+        selectedRanges.add(new Span(start, end));
 
         setSelectedRanges(selectedRanges);
     }
@@ -786,6 +793,13 @@
     }
 
     /**
+     * Selects all items in the list.
+     */
+    public void selectAll() {
+        setSelectedRange(0, listData.getLength() - 1);
+    }
+
+    /**
      * Clears the selection.
      */
     public void clearSelection() {

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=803866&r1=803865&r2=803866&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 Thu Aug 13 12:48:48 2009
@@ -974,11 +974,18 @@
      * The index to select, or <tt>-1</tt> to clear the selection.
      */
     public void setSelectedIndex(int index) {
-        ArrayList<Span> selectedRanges = new ArrayList<Span>();
+        setSelectedRange(index, index);
+    }
 
-        if (index >= 0) {
-            selectedRanges.add(new Span(index));
-        }
+    /**
+     * Sets the selection to a single range.
+     *
+     * @param start
+     * @param end
+     */
+    public void setSelectedRange(int start, int end) {
+        ArrayList<Span> selectedRanges = new ArrayList<Span>();
+        selectedRanges.add(new Span(start, end));
 
         setSelectedRanges(selectedRanges);
     }
@@ -1238,6 +1245,13 @@
     }
 
     /**
+     * Selects all rows in the table.
+     */
+    public void selectAll() {
+        setSelectedRange(0, tableData.getLength() - 1);
+    }
+
+    /**
      * Clears the selection.
      */
     public void clearSelection() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Thu Aug 13 12:48:48 2009
@@ -351,6 +351,18 @@
     }
 
     /**
+     * Returns a span representing the current selection.
+     *
+     * @return
+     * A span containing the current selection. Both start and end points are
+     * inclusive. Returns <tt>null</tt> if the selection is empty.
+     */
+    public Span getSelection() {
+        return (selectionLength == 0) ? null : new Span(selectionStart,
+            selectionStart + selectionLength - 1);
+    }
+
+    /**
      * Sets the selection. The sum of the selection start and length must be
      * less than the length of the text input's content.
      *

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Thu Aug 13 12:48:48 2009
@@ -405,6 +405,18 @@
     }
 
     /**
+     * Returns a span representing the current selection.
+     *
+     * @return
+     * A span containing the current selection. Both start and end points are
+     * inclusive. Returns <tt>null</tt> if the selection is empty.
+     */
+    public Span getSelection() {
+        return (selectionLength == 0) ? null : new Span(selectionStart,
+            selectionStart + selectionLength - 1);
+    }
+
+    /**
      * Sets the selection. The sum of the selection start and length must be
      * less than the length of the text input's content.
      *
@@ -438,15 +450,17 @@
     }
 
     /**
-     * Returns a span representing the current selection.
-     *
-     * @return
-     * A span containing the current selection. Both start and end points are
-     * inclusive. Returns <tt>null</tt> if the selection is empty.
+     * Selects all text.
      */
-    public Span getSelectionRange() {
-        return (selectionLength == 0) ? null : new Span(selectionStart,
-            selectionStart + selectionLength - 1);
+    public void selectAll() {
+        setSelection(0, textNode.getCharacterCount());
+    }
+
+    /**
+     * Clears the selection.
+     */
+    public void clearSelection() {
+        setSelection(0, 0);
     }
 
     /**

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java Thu Aug 13 12:48:48 2009
@@ -209,6 +209,7 @@
                 + (editBounds.height - textInput.getPreferredHeight(-1)) / 2);
             popup.open(listView.getWindow());
 
+            textInput.selectAll();
             textInput.requestFocus();
         }
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java Thu Aug 13 12:48:48 2009
@@ -228,6 +228,7 @@
                 + (cellBounds.height - textInput.getPreferredHeight(-1)) / 2);
             popup.open(tableView.getWindow());
 
+            textInput.selectAll();
             textInput.requestFocus();
         }
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java Thu Aug 13 12:48:48 2009
@@ -247,6 +247,7 @@
                 + (editBounds.height - textInput.getPreferredHeight(-1)) / 2);
             popup.open(treeView.getWindow());
 
+            textInput.selectAll();
             textInput.requestFocus();
         }
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=803866&r1=803865&r2=803866&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Thu Aug 13 12:48:48 2009
@@ -1219,31 +1219,26 @@
     public void focusedChanged(Component component, Component obverseComponent) {
         super.focusedChanged(component, obverseComponent);
 
-        TextInput textInput = (TextInput)getComponent();
-        TextNode textNode = textInput.getTextNode();
-
-        Window window = component.getWindow();
+        TextInput textInput = (TextInput)component;
+        Window window = textInput.getWindow();
 
         if (component.isFocused()) {
-            // If focus is not being restored or the focus was permanently
-            // transferred within this window, select all
-            if ((obverseComponent == null
-                    && window.getFocusDescendant() != component)
-                || (obverseComponent != null
-                    && obverseComponent.getWindow() == window)) {
+            // If focus was permanently transferred within this window,
+            // select all
+            if (obverseComponent != null
+                && obverseComponent.getWindow() == window) {
                 if (Mouse.getCapturer() != component) {
-                    textInput.setSelection(0, textNode.getCharacterCount());
+                    textInput.selectAll();
                 }
             }
 
             showCaret(textInput.getSelectionLength() == 0);
         } else {
-            // If focus is being permanently transferred within this window,
+            // If focus was permanently transferred within this window,
             // clear the selection
             if (obverseComponent != null
                 && obverseComponent.getWindow() == window) {
-                textInput.setSelection(textInput.getSelectionStart()
-                    + textInput.getSelectionLength(), 0);
+                textInput.clearSelection();
             }
 
             showCaret(false);