Author: rwhitcomb
Date: Thu Jan 11 19:00:00 2018
New Revision: 1820921

URL: http://svn.apache.org/viewvc?rev=1820921&view=rev
Log:
PIVOT-1022:  Use the new capability of LinkedStack to limit the
stack depth in TextPane for the "undo" stack.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java?rev=1820921&r1=1820920&r2=1820921&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Thu Jan 11 19:00:00 
2018
@@ -25,7 +25,7 @@ import java.io.StringWriter;
 import java.net.URL;
 
 import org.apache.pivot.beans.DefaultProperty;
-import org.apache.pivot.collections.LinkedList;
+import org.apache.pivot.collections.LinkedStack;
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.text.AttributedStringCharacterIterator;
 import org.apache.pivot.util.ListenerList;
@@ -265,7 +265,7 @@ public class TextPane extends Container
             }
 
             if (!undoingHistory) {
-                addHistoryItem(new RangeInsertedEdit(node, offset, 
characterCount));
+                editHistory.push(new RangeInsertedEdit(node, offset, 
characterCount));
             }
 
             if (!bulkOperation) {
@@ -288,7 +288,7 @@ public class TextPane extends Container
             }
 
             if (!undoingHistory) {
-                addHistoryItem(new NodesRemovedEdit(node, removed, offset));
+                editHistory.push(new NodesRemovedEdit(node, removed, offset));
             }
         }
 
@@ -327,7 +327,7 @@ public class TextPane extends Container
             }
 
             if (!undoingHistory && removedChars != null) {
-                addHistoryItem(new RangeRemovedEdit(node, offset, 
characterCount, removedChars));
+                editHistory.push(new RangeRemovedEdit(node, offset, 
characterCount, removedChars));
             }
 
             if (!bulkOperation) {
@@ -336,7 +336,7 @@ public class TextPane extends Container
         }
     };
 
-    private LinkedList<Edit> editHistory = new LinkedList<>();
+    private LinkedStack<Edit> editHistory = new 
LinkedStack<>(MAXIMUM_EDIT_HISTORY_LENGTH);
 
     private TextPaneListenerList textPaneListeners = new 
TextPaneListenerList();
     private TextPaneCharacterListenerList textPaneCharacterListeners = new 
TextPaneCharacterListenerList();
@@ -829,23 +829,14 @@ public class TextPane extends Container
     }
 
     public void undo() {
-        int n = editHistory.getLength();
-        if (n > 0) {
+        if (editHistory.getDepth() > 0) {
             undoingHistory = true;
-            Edit edit = editHistory.remove(n - 1, 1).get(0);
+            Edit edit = editHistory.pop();
             edit.undo();
             undoingHistory = false;
         }
     }
 
-    private void addHistoryItem(Edit edit) {
-        editHistory.add(edit);
-
-        if (editHistory.getLength() > MAXIMUM_EDIT_HISTORY_LENGTH) {
-            editHistory.remove(0, 1);
-        }
-    }
-
     public void redo() {
         // TODO
     }


Reply via email to