src/share/classes/javax/swing/undo/UndoManager.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 115  * </table>
 116  * <p>
 117  * Once <code>end</code> has been invoked on an <code>UndoManager</code>
 118  * the superclass behavior is used for all <code>UndoableEdit</code>
 119  * methods.  Refer to <code>CompoundEdit</code> for more details on its
 120  * behavior.
 121  * <p>
 122  * Unlike the rest of Swing, this class is thread safe.
 123  * <p>
 124  * <strong>Warning:</strong>
 125  * Serialized objects of this class will not be compatible with
 126  * future Swing releases. The current serialization support is
 127  * appropriate for short term storage or RMI between applications running
 128  * the same version of Swing.  As of 1.4, support for long term storage
 129  * of all JavaBeans&trade;
 130  * has been added to the <code>java.beans</code> package.
 131  * Please see {@link java.beans.XMLEncoder}.
 132  *
 133  * @author Ray Ryan
 134  */

 135 public class UndoManager extends CompoundEdit implements UndoableEditListener {
 136     int indexOfNextAdd;
 137     int limit;
 138 
 139     /**
 140      * Creates a new <code>UndoManager</code>.
 141      */
 142     public UndoManager() {
 143         super();
 144         indexOfNextAdd = 0;
 145         limit = 100;
 146         edits.ensureCapacity(limit);
 147     }
 148 
 149     /**
 150      * Returns the maximum number of edits this {@code UndoManager}
 151      * holds. A value less than 0 indicates the number of edits is not
 152      * limited.
 153      *
 154      * @return the maximum number of edits this {@code UndoManager} holds


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 115  * </table>
 116  * <p>
 117  * Once <code>end</code> has been invoked on an <code>UndoManager</code>
 118  * the superclass behavior is used for all <code>UndoableEdit</code>
 119  * methods.  Refer to <code>CompoundEdit</code> for more details on its
 120  * behavior.
 121  * <p>
 122  * Unlike the rest of Swing, this class is thread safe.
 123  * <p>
 124  * <strong>Warning:</strong>
 125  * Serialized objects of this class will not be compatible with
 126  * future Swing releases. The current serialization support is
 127  * appropriate for short term storage or RMI between applications running
 128  * the same version of Swing.  As of 1.4, support for long term storage
 129  * of all JavaBeans&trade;
 130  * has been added to the <code>java.beans</code> package.
 131  * Please see {@link java.beans.XMLEncoder}.
 132  *
 133  * @author Ray Ryan
 134  */
 135 @SuppressWarnings("serial") // Same-version serialization only
 136 public class UndoManager extends CompoundEdit implements UndoableEditListener {
 137     int indexOfNextAdd;
 138     int limit;
 139 
 140     /**
 141      * Creates a new <code>UndoManager</code>.
 142      */
 143     public UndoManager() {
 144         super();
 145         indexOfNextAdd = 0;
 146         limit = 100;
 147         edits.ensureCapacity(limit);
 148     }
 149 
 150     /**
 151      * Returns the maximum number of edits this {@code UndoManager}
 152      * holds. A value less than 0 indicates the number of edits is not
 153      * limited.
 154      *
 155      * @return the maximum number of edits this {@code UndoManager} holds