< prev index next >

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

Print this page




  41  * <code>UndoableEditListener</code> to a <code>JTextField</code>:
  42  * <pre>
  43  *   UndoManager undoManager = new UndoManager();
  44  *   JTextField tf = ...;
  45  *   tf.getDocument().addUndoableEditListener(undoManager);
  46  * </pre>
  47  * <p>
  48  * <code>UndoManager</code> maintains an ordered list of edits and the
  49  * index of the next edit in that list. The index of the next edit is
  50  * either the size of the current list of edits, or if
  51  * <code>undo</code> has been invoked it corresponds to the index
  52  * of the last significant edit that was undone. When
  53  * <code>undo</code> is invoked all edits from the index of the next
  54  * edit to the last significant edit are undone, in reverse order.
  55  * For example, consider an <code>UndoManager</code> consisting of the
  56  * following edits: <b>A</b> <i>b</i> <i>c</i> <b>D</b>.  Edits with a
  57  * upper-case letter in bold are significant, those in lower-case
  58  * and italicized are insignificant.
  59  * <p>
  60  * <a id="figure1"></a>
  61  * <table border=0 summary="">

  62  * <tr><td>
  63  *     <img src="doc-files/UndoManager-1.gif" alt="">
  64  * <tr><td style="text-align:center">Figure 1
  65  * </table>
  66  * <p>
  67  * As shown in <a href="#figure1">figure 1</a>, if <b>D</b> was just added, the
  68  * index of the next edit will be 4. Invoking <code>undo</code>
  69  * results in invoking <code>undo</code> on <b>D</b> and setting the
  70  * index of the next edit to 3 (edit <i>c</i>), as shown in the following
  71  * figure.
  72  * <p>
  73  * <a id="figure2"></a>
  74  * <table border=0 summary="">

  75  * <tr><td>
  76  *     <img src="doc-files/UndoManager-2.gif" alt="">
  77  * <tr><td style="text-align:center">Figure 2
  78  * </table>
  79  * <p>
  80  * The last significant edit is <b>A</b>, so that invoking
  81  * <code>undo</code> again invokes <code>undo</code> on <i>c</i>,
  82  * <i>b</i>, and <b>A</b>, in that order, setting the index of the
  83  * next edit to 0, as shown in the following figure.
  84  * <p>
  85  * <a id="figure3"></a>
  86  * <table border=0 summary="">

  87  * <tr><td>
  88  *     <img src="doc-files/UndoManager-3.gif" alt="">
  89  * <tr><td style="text-align:center">Figure 3
  90  * </table>
  91  * <p>
  92  * Invoking <code>redo</code> results in invoking <code>redo</code> on
  93  * all edits between the index of the next edit and the next
  94  * significant edit (or the end of the list).  Continuing with the previous
  95  * example if <code>redo</code> were invoked, <code>redo</code> would in
  96  * turn be invoked on <b>A</b>, <i>b</i> and <i>c</i>.  In addition
  97  * the index of the next edit is set to 3 (as shown in <a
  98  * href="#figure2">figure 2</a>).
  99  * <p>
 100  * Adding an edit to an <code>UndoManager</code> results in
 101  * removing all edits from the index of the next edit to the end of
 102  * the list.  Continuing with the previous example, if a new edit,
 103  * <i>e</i>, is added the edit <b>D</b> is removed from the list
 104  * (after having <code>die</code> invoked on it).  If <i>c</i> is not
 105  * incorporated by the next edit
 106  * (<code><i>c</i>.addEdit(<i>e</i>)</code> returns true), or replaced
 107  * by it (<code><i>e</i>.replaceEdit(<i>c</i>)</code> returns true),
 108  * the new edit is added after <i>c</i>, as shown in the following
 109  * figure.
 110  * <p>
 111  * <a id="figure4"></a>
 112  * <table border=0 summary="">

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




  41  * <code>UndoableEditListener</code> to a <code>JTextField</code>:
  42  * <pre>
  43  *   UndoManager undoManager = new UndoManager();
  44  *   JTextField tf = ...;
  45  *   tf.getDocument().addUndoableEditListener(undoManager);
  46  * </pre>
  47  * <p>
  48  * <code>UndoManager</code> maintains an ordered list of edits and the
  49  * index of the next edit in that list. The index of the next edit is
  50  * either the size of the current list of edits, or if
  51  * <code>undo</code> has been invoked it corresponds to the index
  52  * of the last significant edit that was undone. When
  53  * <code>undo</code> is invoked all edits from the index of the next
  54  * edit to the last significant edit are undone, in reverse order.
  55  * For example, consider an <code>UndoManager</code> consisting of the
  56  * following edits: <b>A</b> <i>b</i> <i>c</i> <b>D</b>.  Edits with a
  57  * upper-case letter in bold are significant, those in lower-case
  58  * and italicized are insignificant.
  59  * <p>
  60  * <a id="figure1"></a>
  61  * <table class="borderless">
  62  * <caption style="display:none">Figure 1</caption>
  63  * <tr><td>
  64  *     <img src="doc-files/UndoManager-1.gif" alt="">
  65  * <tr><td style="text-align:center">Figure 1
  66  * </table>
  67  * <p>
  68  * As shown in <a href="#figure1">figure 1</a>, if <b>D</b> was just added, the
  69  * index of the next edit will be 4. Invoking <code>undo</code>
  70  * results in invoking <code>undo</code> on <b>D</b> and setting the
  71  * index of the next edit to 3 (edit <i>c</i>), as shown in the following
  72  * figure.
  73  * <p>
  74  * <a id="figure2"></a>
  75  * <table class="borderless">
  76  * <caption style="display:none">Figure 2</caption>
  77  * <tr><td>
  78  *     <img src="doc-files/UndoManager-2.gif" alt="">
  79  * <tr><td style="text-align:center">Figure 2
  80  * </table>
  81  * <p>
  82  * The last significant edit is <b>A</b>, so that invoking
  83  * <code>undo</code> again invokes <code>undo</code> on <i>c</i>,
  84  * <i>b</i>, and <b>A</b>, in that order, setting the index of the
  85  * next edit to 0, as shown in the following figure.
  86  * <p>
  87  * <a id="figure3"></a>
  88  * <table class="borderless">
  89  * <caption style="display:none">Figure 3</caption>
  90  * <tr><td>
  91  *     <img src="doc-files/UndoManager-3.gif" alt="">
  92  * <tr><td style="text-align:center">Figure 3
  93  * </table>
  94  * <p>
  95  * Invoking <code>redo</code> results in invoking <code>redo</code> on
  96  * all edits between the index of the next edit and the next
  97  * significant edit (or the end of the list).  Continuing with the previous
  98  * example if <code>redo</code> were invoked, <code>redo</code> would in
  99  * turn be invoked on <b>A</b>, <i>b</i> and <i>c</i>.  In addition
 100  * the index of the next edit is set to 3 (as shown in <a
 101  * href="#figure2">figure 2</a>).
 102  * <p>
 103  * Adding an edit to an <code>UndoManager</code> results in
 104  * removing all edits from the index of the next edit to the end of
 105  * the list.  Continuing with the previous example, if a new edit,
 106  * <i>e</i>, is added the edit <b>D</b> is removed from the list
 107  * (after having <code>die</code> invoked on it).  If <i>c</i> is not
 108  * incorporated by the next edit
 109  * (<code><i>c</i>.addEdit(<i>e</i>)</code> returns true), or replaced
 110  * by it (<code><i>e</i>.replaceEdit(<i>c</i>)</code> returns true),
 111  * the new edit is added after <i>c</i>, as shown in the following
 112  * figure.
 113  * <p>
 114  * <a id="figure4"></a>
 115  * <table class="borderless">
 116  * <caption style="display:none">Figure 4</caption>
 117  * <tr><td>
 118  *     <img src="doc-files/UndoManager-4.gif" alt="">
 119  * <tr><td style="text-align:center">Figure 4
 120  * </table>
 121  * <p>
 122  * Once <code>end</code> has been invoked on an <code>UndoManager</code>
 123  * the superclass behavior is used for all <code>UndoableEdit</code>
 124  * methods.  Refer to <code>CompoundEdit</code> for more details on its
 125  * behavior.
 126  * <p>
 127  * Unlike the rest of Swing, this class is thread safe.
 128  * <p>
 129  * <strong>Warning:</strong>
 130  * Serialized objects of this class will not be compatible with
 131  * future Swing releases. The current serialization support is
 132  * appropriate for short term storage or RMI between applications running
 133  * the same version of Swing.  As of 1.4, support for long term storage
 134  * of all JavaBeans&trade;
 135  * has been added to the <code>java.beans</code> package.
 136  * Please see {@link java.beans.XMLEncoder}.


< prev index next >