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/11/05 22:00:28 UTC

svn commit: r833164 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: skin/TextAreaSkin.java text/Element.java

Author: gbrown
Date: Thu Nov  5 21:00:27 2009
New Revision: 833164

URL: http://svn.apache.org/viewvc?rev=833164&view=rev
Log:
Resolve some additional selection issues in TextArea.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=833164&r1=833163&r2=833164&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Thu Nov  5 21:00:27 2009
@@ -401,7 +401,7 @@
                 }
             }
 
-            return characterBounds;
+            return characterBounds.intersect(0, 0, getWidth(), getHeight());
         }
 
         @Override
@@ -519,7 +519,11 @@
                 if (from == -1) {
                     int i = (direction == Direction.FORWARD) ? 0 : getLength() - 1;
                     NodeView nodeView = get(i);
-                    offset = nodeView.getInsertionPoint(x - nodeView.getX(), -1);
+                    offset = nodeView.getNextInsertionPoint(x - nodeView.getX(), -1, direction);
+
+                    if (offset != -1) {
+                        offset += nodeView.getOffset();
+                    }
                 } else {
                     // Find the node view that contains the offset
                     int n = getLength();
@@ -768,11 +772,10 @@
                         if (x < row.x) {
                             NodeView firstNodeView = row.nodeViews.get(0);
                             offset = firstNodeView.getOffset();
-                        } else if (x > row.x + row.width) {
+                        } else if (x > row.x + row.width - 1) {
                             NodeView lastNodeView = row.nodeViews.get(row.nodeViews.getLength() - 1);
                             offset = lastNodeView.getOffset() + lastNodeView.getCharacterCount();
 
-                            // TODO Check for whitespace character here
                             if (offset < getCharacterCount() - 1) {
                                 offset--;
                             }
@@ -860,7 +863,6 @@
                         NodeView lastNodeView = row.nodeViews.get(row.nodeViews.getLength() - 1);
                         offset = lastNodeView.getOffset() + lastNodeView.getCharacterCount();
 
-                        // TODO Check for whitespace character here
                         if (offset < getCharacterCount() - 1) {
                             offset--;
                         }
@@ -2260,12 +2262,12 @@
             int selectionLength = textArea.getSelectionLength();
 
             if (selectionLength > 0) {
-                Bounds trailingSelectionBounds = getCharacterBounds(selectionStart
-                    + selectionLength - 1);
+                int selectionEnd = selectionStart + selectionLength - 1;
+                Bounds trailingSelectionBounds = getCharacterBounds(selectionEnd);
                 selection = new Area();
 
                 int firstRowIndex = getRowIndex(selectionStart);
-                int lastRowIndex = getRowIndex(selectionStart + selectionLength - 1);
+                int lastRowIndex = getRowIndex(selectionEnd);
 
                 if (firstRowIndex == lastRowIndex) {
                     selection.add(new Area(new Rectangle(leadingSelectionBounds.x, leadingSelectionBounds.y,

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java?rev=833164&r1=833163&r2=833164&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java Thu Nov  5 21:00:27 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.pivot.wtk.text;
 
-import java.util.Comparator;
 import java.util.Iterator;
 
 import org.apache.pivot.collections.ArrayList;
@@ -33,55 +32,6 @@
  */
 public abstract class Element extends Node
     implements Sequence<Node>, Iterable<Node> {
-    /**
-     * Private node class that simply represents an offset value. Used to
-     * perform binary searches.
-     */
-    private static class NullNode extends Node {
-        @Override
-        public void insertRange(Node range, int offset) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public Node removeRange(int offset, int characterCount) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public Node getRange(int offset, int characterCount) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public char getCharacter(int offset) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public int getCharacterCount() {
-            return 0;
-        }
-
-        @Override
-        public Node duplicate(boolean recursive) {
-            throw new UnsupportedOperationException();
-        }
-    }
-
-    /**
-     * Comparator used to perform binary searches on child nodes.
-     */
-    private static class NodeOffsetComparator implements Comparator<Node> {
-        @Override
-        public int compare(Node node1, Node node2) {
-            int offset1 = node1.getOffset();
-            int offset2 = node2.getOffset();
-
-            return (offset1 - offset2);
-        }
-    }
-
     private static class ElementListenerList extends ListenerList<ElementListener>
         implements ElementListener {
         @Override
@@ -105,10 +55,6 @@
 
     private ElementListenerList elementListeners = new ElementListenerList();
 
-    private static final NullNode nullNode = new NullNode();
-    private static final NodeOffsetComparator nodeOffsetComparator =
-        new NodeOffsetComparator();
-
     public Element() {
     }
 
@@ -333,8 +279,8 @@
 
     @Override
     public char getCharacter(int offset) {
-        // TODO Find the node that contains offset, translate, and call getCharacter() on it
-        return 0;
+        Node node = getNodeAt(offset);
+        return node.getCharacter(offset - node.getOffset());
     }
 
     @Override
@@ -477,18 +423,7 @@
             throw new IllegalArgumentException("node is null.");
         }
 
-        int index = -1;
-        if (node.getParent() == this) {
-            index = ArrayList.binarySearch(nodes, node, nodeOffsetComparator);
-
-            if (index < 0) {
-                // Decrement the index by one, since we only get exact
-                // matches when the offset values are identical
-                index = -(index + 1) - 1;
-            }
-        }
-
-        return index;
+        return nodes.indexOf(node);
     }
 
     @Override
@@ -510,10 +445,21 @@
             throw new IndexOutOfBoundsException();
         }
 
-        nullNode.setParent(this);
-        nullNode.setOffset(offset);
+        int index = -1;
+
+        for (int i = 0, n = nodes.getLength(); i < n; i++) {
+            Node node = nodes.get(i);
+            int nodeOffset = node.getOffset();
+            int characterCount = node.getCharacterCount();
 
-        return indexOf(nullNode);
+            if (offset >= nodeOffset
+                && offset < nodeOffset + characterCount) {
+                index = i;
+                break;
+            }
+        }
+
+        return index;
     }
 
     /**