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 2010/09/11 21:44:44 UTC

svn commit: r996202 - in /pivot/trunk: tests/src/org/apache/pivot/tests/sql/ tests/src/org/apache/pivot/tests/text_area_test.bxml wtk/src/org/apache/pivot/wtk/TextArea.java wtk/src/org/apache/pivot/wtk/TextInput.java

Author: gbrown
Date: Sat Sep 11 19:44:44 2010
New Revision: 996202

URL: http://svn.apache.org/viewvc?rev=996202&view=rev
Log:
Undo updates.

Removed:
    pivot/trunk/tests/src/org/apache/pivot/tests/sql/
Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/text_area_test.bxml
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/text_area_test.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/text_area_test.bxml?rev=996202&r1=996201&r2=996202&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/text_area_test.bxml (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/text_area_test.bxml Sat Sep 11 19:44:44 2010
@@ -28,7 +28,7 @@ limitations under the License.
 
     <BoxPane orientation="vertical" styles="{padding:8}">
         <Border>
-            <TextArea bxml:id="textArea" text="@sample.txt" preferredWidth="320"
+            <TextArea bxml:id="textArea" text="ABC&#x000A;DEF&#x000A;GHI&#x000A;JKL&#x000A;MNO&#x000A;PQ" preferredWidth="320"
                 styles="{margin:8, backgroundColor:'#eeeeee', wrapText:true}">
                 <textAreaContentListeners>
                 function textChanged(textArea) {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=996202&r1=996201&r2=996202&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Sat Sep 11 19:44:44 2010
@@ -467,8 +467,8 @@ public class TextArea extends Component 
     }
 
     private class RemoveTextEdit implements Edit {
-        private final String text;
         private final int index;
+        private final CharSequence text;
 
         public RemoveTextEdit(int index, int count) {
             this.index = index;
@@ -580,6 +580,7 @@ public class TextArea extends Component 
     private TextAreaBindingListenerList textAreaBindingListeners = new TextAreaBindingListenerList();
 
     private static final int INITIAL_PARAGRAPH_CAPACITY = 256;
+    private static final int MAXIMUM_EDIT_HISTORY_LENGTH = 30;
 
     public TextArea() {
         installSkin(TextArea.class);
@@ -637,17 +638,16 @@ public class TextArea extends Component 
         // and moving to next paragraph as needed
         int i = 0;
         while (i < count) {
-            textBuilder.append(paragraph.characters.charAt(characterOffset++));
-            i++;
-
             if (characterOffset == paragraph.characters.length()
                 && i < characterCount) {
                 textBuilder.append('\n');
-                i++;
-
                 paragraph = paragraphs.get(++paragraphIndex);
                 characterOffset = 0;
+            } else {
+                textBuilder.append(paragraph.characters.charAt(characterOffset++));
             }
+
+            i++;
         }
 
         return textBuilder.toString();
@@ -715,6 +715,9 @@ public class TextArea extends Component 
 
         paragraphs.add(paragraph);
 
+        // Clear the edit history
+        editHistory.clear();
+
         // Update content
         paragraphSequence.remove(0, paragraphSequence.getLength());
 
@@ -773,7 +776,7 @@ public class TextArea extends Component 
 
             // Add an insert history item
             if (addToEditHistory) {
-                editHistory.add(new InsertTextEdit(text, index));
+                addHistoryItem(new InsertTextEdit(text, index));
             }
         }
     }
@@ -791,7 +794,7 @@ public class TextArea extends Component 
         if (count > 0) {
             // Add a remove history item
             if (addToEditHistory) {
-                editHistory.add(new RemoveTextEdit(index, count));
+                addHistoryItem(new RemoveTextEdit(index, count));
             }
 
             // Identify the leading and trailing paragraph indexes
@@ -942,6 +945,14 @@ public class TextArea extends Component 
         }
     }
 
+    private void addHistoryItem(Edit edit) {
+        editHistory.add(edit);
+
+        if (editHistory.getLength() > MAXIMUM_EDIT_HISTORY_LENGTH) {
+            editHistory.remove(0, 1);
+        }
+    }
+
     /**
      * Returns the starting index of the selection.
      *

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java?rev=996202&r1=996201&r2=996202&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Sat Sep 11 19:44:44 2010
@@ -90,8 +90,8 @@ public class TextInput extends Component
     }
 
     private class RemoveTextEdit implements Edit {
-        private final String text;
         private final int index;
+        private final String text;
 
         public RemoveTextEdit(int index, int count) {
             this.index = index;
@@ -278,6 +278,8 @@ public class TextInput extends Component
 
     public static final int DEFAULT_TEXT_SIZE = 16;
 
+    private static final int MAXIMUM_EDIT_HISTORY_LENGTH = 30;
+
     public TextInput() {
         installSkin(TextInput.class);
     }
@@ -337,7 +339,7 @@ public class TextInput extends Component
         textValid = (validator == null) ? true : validator.isValid(text);
 
         // Clear the edit history
-        editHistory = new LinkedList<Edit>();
+        editHistory.clear();
 
         // Fire change events
         textInputContentListeners.textChanged(this);
@@ -374,7 +376,7 @@ public class TextInput extends Component
 
                 // Add an insert history item
                 if (addToEditHistory) {
-                    editHistory.add(new InsertTextEdit(text, index));
+                    addHistoryItem(new InsertTextEdit(text, index));
                 }
 
                 // Update selection
@@ -416,7 +418,7 @@ public class TextInput extends Component
             if (vote == Vote.APPROVE) {
                 // Add a remove history item
                 if (addToEditHistory) {
-                    editHistory.add(new RemoveTextEdit(index, count));
+                    addHistoryItem(new RemoveTextEdit(index, count));
                 }
 
                 // Remove the text
@@ -522,6 +524,14 @@ public class TextInput extends Component
         }
     }
 
+    private void addHistoryItem(Edit edit) {
+        editHistory.add(edit);
+
+        if (editHistory.getLength() > MAXIMUM_EDIT_HISTORY_LENGTH) {
+            editHistory.remove(0, 1);
+        }
+    }
+
     /**
      * Returns the starting index of the selection.
      *