Author: rwhitcomb
Date: Thu Jan 11 19:15:38 2018
New Revision: 1820922

URL: http://svn.apache.org/viewvc?rev=1820922&view=rev
Log:
PIVOT-1022:  Make the same changes for LinkedStack as were made
in TextPane to TextInput and TextArea too (for their "undo" stacks).

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java

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=1820922&r1=1820921&r2=1820922&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Thu Jan 11 19:15:38 
2018
@@ -26,7 +26,7 @@ import java.net.URL;
 import java.util.Iterator;
 
 import org.apache.pivot.collections.ArrayList;
-import org.apache.pivot.collections.LinkedList;
+import org.apache.pivot.collections.LinkedStack;
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.json.JSON;
 import org.apache.pivot.util.ImmutableIterator;
@@ -556,7 +556,7 @@ public class TextArea extends Component
     private BindType textBindType = BindType.BOTH;
     private TextBindMapping textBindMapping = null;
 
-    private LinkedList<Edit> editHistory = new LinkedList<>();
+    private LinkedStack<Edit> editHistory = new 
LinkedStack<>(MAXIMUM_EDIT_HISTORY_LENGTH);
 
     private TextAreaListenerList textAreaListeners = new 
TextAreaListenerList();
     private TextAreaContentListenerList textAreaContentListeners = new 
TextAreaContentListenerList();
@@ -769,7 +769,7 @@ public class TextArea extends Component
 
             // Add an insert history item
             if (addToEditHistory) {
-                addHistoryItem(new InsertTextEdit(text, index));
+                editHistory.push(new InsertTextEdit(text, index));
             }
         }
     }
@@ -786,7 +786,7 @@ public class TextArea extends Component
         if (count > 0) {
             // Add a remove history item
             if (addToEditHistory) {
-                addHistoryItem(new RemoveTextEdit(index, count));
+                editHistory.push(new RemoveTextEdit(index, count));
             }
 
             // Identify the leading and trailing paragraph indexes
@@ -926,21 +926,12 @@ public class TextArea extends Component
     }
 
     public void undo() {
-        int n = editHistory.getLength();
-        if (n > 0) {
-            Edit edit = editHistory.remove(n - 1, 1).get(0);
+        if (editHistory.getDepth() > 0) {
+            Edit edit = editHistory.pop();
             edit.undo();
         }
     }
 
-    private void addHistoryItem(Edit edit) {
-        editHistory.add(edit);
-
-        if (editHistory.getLength() > MAXIMUM_EDIT_HISTORY_LENGTH) {
-            editHistory.remove(0, 1);
-        }
-    }
-
     /**
      * @return 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=1820922&r1=1820921&r2=1820922&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java Thu Jan 11 19:15:38 
2018
@@ -19,7 +19,7 @@ package org.apache.pivot.wtk;
 import java.awt.Toolkit;
 import java.io.IOException;
 
-import org.apache.pivot.collections.LinkedList;
+import org.apache.pivot.collections.LinkedStack;
 import org.apache.pivot.json.JSON;
 import org.apache.pivot.text.AttributedStringCharacterIterator;
 import org.apache.pivot.util.ListenerList;
@@ -128,7 +128,7 @@ public class TextInput extends Component
     private boolean strictValidation = false;
     private boolean textValid = true;
 
-    private LinkedList<Edit> editHistory = new LinkedList<>();
+    private LinkedStack<Edit> editHistory = new 
LinkedStack<>(MAXIMUM_EDIT_HISTORY_LENGTH);
 
     private TextInputListener.Listeners textInputListeners = new 
TextInputListener.Listeners();
     private TextInputContentListener.Listeners textInputContentListeners = new 
TextInputContentListener.Listeners();
@@ -224,7 +224,7 @@ public class TextInput extends Component
 
                 // Add an insert history item
                 if (addToEditHistory) {
-                    addHistoryItem(new InsertTextEdit(text, index));
+                    editHistory.push(new InsertTextEdit(text, index));
                 }
 
                 // Update selection
@@ -267,7 +267,7 @@ public class TextInput extends Component
             if (vote == Vote.APPROVE) {
                 // Add a remove history item
                 if (addToEditHistory) {
-                    addHistoryItem(new RemoveTextEdit(index, count));
+                    editHistory.push(new RemoveTextEdit(index, count));
                 }
 
                 // Remove the text
@@ -410,21 +410,12 @@ public class TextInput extends Component
     }
 
     public void undo() {
-        int n = editHistory.getLength();
-        if (n > 0) {
-            Edit edit = editHistory.remove(n - 1, 1).get(0);
+        if (editHistory.getDepth() > 0) {
+            Edit edit = editHistory.pop();
             edit.undo();
         }
     }
 
-    private void addHistoryItem(Edit edit) {
-        editHistory.add(edit);
-
-        if (editHistory.getLength() > MAXIMUM_EDIT_HISTORY_LENGTH) {
-            editHistory.remove(0, 1);
-        }
-    }
-
     /**
      * @return The starting index of the selection.
      */


Reply via email to