2727 */
2828package javax .swing .undo ;
2929
30- import java .util .Enumeration ;
31- import java .util .Vector ;
30+ import java .util .ArrayList ;
31+ import java .util .List ;
3232
3333/**
3434 * A concrete subclass of AbstractUndoableEdit, used to assemble little
@@ -47,12 +47,12 @@ public class CompoundEdit extends AbstractUndoableEdit {
4747 * The collection of <code>UndoableEdit</code>s
4848 * undone/redone en masse by this <code>CompoundEdit</code>.
4949 */
50- protected Vector <UndoableEdit > edits ;
50+ protected List <UndoableEdit > edits ;
5151
5252 public CompoundEdit () {
5353 super ();
5454 inProgress = true ;
55- edits = new Vector <UndoableEdit >();
55+ edits = new ArrayList <UndoableEdit >();
5656 }
5757
5858 /**
@@ -63,9 +63,8 @@ public CompoundEdit() {
6363 @ Override
6464 public void undo () throws CannotUndoException {
6565 super .undo ();
66- int i = edits .size ();
67- while (i -- > 0 ) {
68- UndoableEdit e = (UndoableEdit )edits .elementAt (i );
66+ for (int i = edits .size (); --i >= 0 ;) {
67+ UndoableEdit e = (UndoableEdit )edits .get (i );
6968 e .undo ();
7069 }
7170 }
@@ -78,9 +77,8 @@ public void undo() throws CannotUndoException {
7877 @ Override
7978 public void redo () throws CannotRedoException {
8079 super .redo ();
81- Enumeration cursor = edits .elements ();
82- while (cursor .hasMoreElements ()) {
83- ((UndoableEdit )cursor .nextElement ()).redo ();
80+ for (int i = edits .size (); --i >= 0 ;) {
81+ edits .get (i ).redo ();
8482 }
8583 }
8684
@@ -91,10 +89,7 @@ public void redo() throws CannotRedoException {
9189 */
9290 protected UndoableEdit lastEdit () {
9391 int count = edits .size ();
94- if (count > 0 )
95- return (UndoableEdit )edits .elementAt (count -1 );
96- else
97- return null ;
92+ return (count > 0 ? edits .get (count - 1 ) : null );
9893 }
9994
10095 /**
@@ -103,57 +98,52 @@ protected UndoableEdit lastEdit() {
10398 */
10499 @ Override
105100 public void die () {
106- int size = edits .size ();
107- for (int i = size -1 ; i >= 0 ; i --)
101+ for (int i = edits .size (); --i >= 0 ;)
108102 {
109- UndoableEdit e = (UndoableEdit )edits .elementAt (i );
110- // System.out.println("CompoundEdit(" + i + "): Discarding " +
111- // e.getUndoPresentationName());
103+ UndoableEdit e = edits .get (i );
112104 e .die ();
113105 }
114106 super .die ();
115107 }
116108
117- /**
118- * If this edit is <code>inProgress</code>,
119- * accepts <code>anEdit</code> and returns true.
120- *
121- * <p>The last edit added to this <code>CompoundEdit</code>
122- * is given a chance to <code>addEdit(anEdit)</code>.
123- * If it refuses (returns false), <code>anEdit</code> is
124- * given a chance to <code>replaceEdit</code> the last edit.
125- * If <code>anEdit</code> returns false here,
126- * it is added to <code>edits</code>.
127- *
128- * @param anEdit the edit to be added
129- * @return true if the edit is <code>inProgress</code>;
130- * otherwise returns false
131- */
132- @ Override
133- public boolean addEdit (UndoableEdit anEdit ) {
134- if (!inProgress ) {
135- return false ;
136- } else {
137- UndoableEdit last = lastEdit ();
109+ /**
110+ * If this edit is <code>inProgress</code>, accepts <code>anEdit</code> and
111+ * returns true.
112+ *
113+ * <p>
114+ * The last edit added to this <code>CompoundEdit</code> is given a chance to
115+ * <code>addEdit(anEdit)</code>. If it refuses (returns false),
116+ * <code>anEdit</code> is given a chance to <code>replaceEdit</code> the last
117+ * edit. If <code>anEdit</code> returns false here, it is added to
118+ * <code>edits</code>.
119+ *
120+ * @param anEdit the edit to be added
121+ * @return true if the edit is <code>inProgress</code>; otherwise returns false
122+ */
123+ @ Override
124+ public boolean addEdit (UndoableEdit anEdit ) {
125+ if (!inProgress ) {
126+ return false ;
127+ } else {
128+ UndoableEdit last = lastEdit ();
138129
139- // If this is the first subedit received, just add it.
140- // Otherwise, give the last one a chance to absorb the new
141- // one. If it won't, give the new one a chance to absorb
142- // the last one.
130+ // If this is the first subedit received, just add it.
131+ // Otherwise, give the last one a chance to absorb the new
132+ // one. If it won't, give the new one a chance to absorb
133+ // the last one.
143134
144- if (last == null ) {
145- edits .addElement (anEdit );
146- }
147- else if (!last .addEdit (anEdit )) {
148- if (anEdit .replaceEdit (last )) {
149- edits .removeElementAt (edits .size ()-1 );
150- }
151- edits .addElement (anEdit );
152- }
135+ if (last == null ) {
136+ edits .add (anEdit );
137+ } else if (!last .addEdit (anEdit )) {
138+ if (anEdit .replaceEdit (last )) {
139+ edits .remove (edits .size () - 1 );
140+ }
141+ edits .add (anEdit );
142+ }
153143
154- return true ;
155- }
156- }
144+ return true ;
145+ }
146+ }
157147
158148 /**
159149 * Sets <code>inProgress</code> to false.
@@ -205,9 +195,8 @@ public boolean isInProgress() {
205195 */
206196 @ Override
207197 public boolean isSignificant () {
208- Enumeration cursor = edits .elements ();
209- while (cursor .hasMoreElements ()) {
210- if (((UndoableEdit )cursor .nextElement ()).isSignificant ()) {
198+ for (int i = edits .size (); --i >= 0 ;) {
199+ if (edits .get (i ).isSignificant ()) {
211200 return true ;
212201 }
213202 }
0 commit comments