jdk/src/share/classes/javax/swing/undo/UndoableEdit.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 23715 54ae9dd9df73
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.undo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An <code>UndoableEdit</code> represents an edit.  The edit may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * be undone, or if already undone the edit may be redone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <code>UndoableEdit</code> is designed to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>UndoManager</code>.  As <code>UndoableEdit</code>s are generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * by an <code>UndoableEditListener</code> they are typically added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the <code>UndoManager</code>.  When an <code>UndoableEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is added to an <code>UndoManager</code> the following occurs (assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>end</code> has not been called on the <code>UndoManager</code>):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <li>If the <code>UndoManager</code> contains edits it will call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *     <code>addEdit</code> on the current edit passing in the new edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     as the argument.  If <code>addEdit</code> returns true the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *     new edit is assumed to have been incorporated into the current edit and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *     the new edit will not be added to the list of current edits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     Edits can use <code>addEdit</code> as a way for smaller edits to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     be incorporated into a larger edit and treated as a single edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>If <code>addEdit</code> returns false <code>replaceEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     is called on the new edit with the current edit passed in as the
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
    50
 *     argument. This is the inverse of <code>addEdit</code> &#8212;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     if the new edit returns true from <code>replaceEdit</code>, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     edit replaces the current edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The <code>UndoManager</code> makes use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>isSignificant</code> to determine how many edits should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * undone or redone.  The <code>UndoManager</code> will undo or redo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * all insignificant edits (<code>isSignificant</code> returns false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * between the current edit and the last or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * next significant edit.   <code>addEdit</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>replaceEdit</code> can be used to treat multiple edits as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * a single edit, returning false from <code>isSignificant</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * allows for treating can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * have many smaller edits undone or redone at once.  Similar functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * can also be done using the <code>addEdit</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Ray Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public interface UndoableEdit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Undo the edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @throws CannotUndoException if this edit can not be undone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public void undo() throws CannotUndoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Returns true if this edit may be undone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return true if this edit may be undone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public boolean canUndo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Re-applies the edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @throws CannotRedoException if this edit can not be redone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void redo() throws CannotRedoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns true if this edit may be redone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return true if this edit may be redone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public boolean canRedo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Informs the edit that it should no longer be used. Once an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>UndoableEdit</code> has been marked as dead it can no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * be undone or redone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * This is a useful hook for cleaning up state no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * needed once undoing or redoing is impossible--for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * deleting file resources used by objects that can no longer be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * undeleted. <code>UndoManager</code> calls this before it dequeues edits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Note that this is a one-way operation. There is no "un-die"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see CompoundEdit#die
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void die();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Adds an <code>UndoableEdit</code> to this <code>UndoableEdit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * This method can be used to coalesce smaller edits into a larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * compound edit.  For example, text editors typically allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * undo operations to apply to words or sentences.  The text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * editor may choose to generate edits on each key event, but allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * those edits to be coalesced into a more user-friendly unit, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * a word. In this case, the <code>UndoableEdit</code> would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * override <code>addEdit</code> to return true when the edits may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * be coalesced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * A return value of true indicates <code>anEdit</code> was incorporated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * into this edit.  A return value of false indicates <code>anEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * may not be incorporated into this edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <p>Typically the receiver is already in the queue of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>UndoManager</code> (or other <code>UndoableEditListener</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * and is being given a chance to incorporate <code>anEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * rather than letting it be added to the queue in turn.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <p>If true is returned, from now on <code>anEdit</code> must return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * false from <code>canUndo</code> and <code>canRedo</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * and must throw the appropriate exception on <code>undo</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>redo</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param anEdit the edit to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return true if <code>anEdit</code> may be incorporated into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *              edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public boolean addEdit(UndoableEdit anEdit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns true if this <code>UndoableEdit</code> should replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <code>anEdit</code>. This method is used by <code>CompoundEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * and the <code>UndoManager</code>; it is called if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <code>anEdit</code> could not be added to the current edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * (<code>addEdit</code> returns false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * This method provides a way for an edit to replace an existing edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <p>This message is the opposite of addEdit--anEdit has typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * already been queued in an <code>UndoManager</code> (or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * UndoableEditListener), and the receiver is being given a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * to take its place.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <p>If true is returned, from now on anEdit must return false from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * canUndo() and canRedo(), and must throw the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * exception on undo() or redo().</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param anEdit the edit that replaces the current edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return true if this edit should replace <code>anEdit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public boolean replaceEdit(UndoableEdit anEdit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Returns true if this edit is considered significant.  A significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * edit is typically an edit that should be presented to the user, perhaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * on a menu item or tooltip.  The <code>UndoManager</code> will undo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * or redo, all insignificant edits to the next significant edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return true if this edit is significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean isSignificant();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Returns a localized, human-readable description of this edit, suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * for use in a change log, for example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return description of this edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public String getPresentationName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns a localized, human-readable description of the undoable form of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * this edit, suitable for use as an Undo menu item, for example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * This is typically derived from <code>getPresentationName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return a description of the undoable form of this edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public String getUndoPresentationName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns a localized, human-readable description of the redoable form of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * this edit, suitable for use as a Redo menu item, for example. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * typically derived from <code>getPresentationName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return a description of the redoable form of this edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public String getRedoPresentationName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}