Java Doc for UndoManager.java in  » 6.0-JDK-Core » swing » javax » swing » undo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.undo 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.swing.undo.AbstractUndoableEdit
      javax.swing.undo.CompoundEdit
         javax.swing.undo.UndoManager

UndoManager
public class UndoManager extends CompoundEdit implements UndoableEditListener(Code)
UndoManager manages a list of UndoableEdits , providing a way to undo or redo the appropriate edits. There are two ways to add edits to an UndoManager. Add the edit directly using the addEdit method, or add the UndoManager to a bean that supports UndoableEditListener. The following examples creates an UndoManager and adds it as an UndoableEditListener to a JTextField:
 UndoManager undoManager = new UndoManager();
 JTextField tf = ...;
 tf.getDocument().addUndoableEditListener(undoManager);
 

UndoManager maintains an ordered list of edits and the index of the next edit in that list. The index of the next edit is either the size of the current list of edits, or if undo has been invoked it corresponds to the index of the last significant edit that was undone. When undo is invoked all edits from the index of the next edit to the last significant edit are undone, in reverse order. For example, consider an UndoManager consisting of the following edits: A b c D. Edits with a upper-case letter in bold are significant, those in lower-case and italicized are insignificant.

Figure 1

As shown in figure 1, if D was just added, the index of the next edit will be 4. Invoking undo results in invoking undo on D and setting the index of the next edit to 3 (edit c), as shown in the following figure.

Figure 2

The last significant edit is A, so that invoking undo again invokes undo on c, b, and A, in that order, setting the index of the next edit to 0, as shown in the following figure.

Figure 3

Invoking redo results in invoking redo on all edits between the index of the next edit and the next significant edit (or the end of the list). Continuing with the previous example if redo were invoked, redo would in turn be invoked on A, b and c. In addition the index of the next edit is set to 3 (as shown in figure 2).

Adding an edit to an UndoManager results in removing all edits from the index of the next edit to the end of the list. Continuing with the previous example, if a new edit, e, is added the edit D is removed from the list (after having die invoked on it). If c is not incorporated by the next edit (c.addEdit(e) returns true), or replaced by it (e.replaceEdit(c) returns true), the new edit is added after c, as shown in the following figure.

Figure 4

Once end has been invoked on an UndoManager the superclass behavior is used for all UndoableEdit methods. Refer to CompoundEdit for more details on its behavior.

Unlike the rest of Swing, this class is thread safe.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder .
author:
   Ray Ryan
version:
   1.45, 05/05/07



Field Summary
 intindexOfNextAdd
    
 intlimit
    

Constructor Summary
public  UndoManager()
     Creates a new UndoManager.

Method Summary
public synchronized  booleanaddEdit(UndoableEdit anEdit)
     Adds an UndoableEdit to this UndoManager, if it's possible.
public synchronized  booleancanRedo()
     Returns true if edits may be redone.
public synchronized  booleancanUndo()
     Returns true if edits may be undone.
public synchronized  booleancanUndoOrRedo()
     Returns true if it is possible to invoke undo or redo.
public synchronized  voiddiscardAllEdits()
     Empties the undo manager sending each edit a die message in the process.
protected  UndoableEditeditToBeRedone()
     Returns the the next significant edit to be redone if redo is invoked.
protected  UndoableEditeditToBeUndone()
     Returns the the next significant edit to be undone if undo is invoked.
public synchronized  voidend()
     Turns this UndoManager into a normal CompoundEdit.
public synchronized  intgetLimit()
     Returns the maximum number of edits this UndoManager holds.
public synchronized  StringgetRedoPresentationName()
     Returns a description of the redoable form of this edit.
public synchronized  StringgetUndoOrRedoPresentationName()
     Convenience method that returns either getUndoPresentationName or getRedoPresentationName.
public synchronized  StringgetUndoPresentationName()
     Returns a description of the undoable form of this edit.
public synchronized  voidredo()
     Redoes the appropriate edits.
protected  voidredoTo(UndoableEdit edit)
     Redoes all changes from the index of the next edit to edit, updating the index of the next edit appropriately.
public synchronized  voidsetLimit(int l)
     Sets the maximum number of edits this UndoManager holds.
public  StringtoString()
     Returns a string that displays and identifies this object's properties.
protected  voidtrimEdits(int from, int to)
     Removes edits in the specified range. All edits in the given range (inclusive, and in reverse order) will have die invoked on them and are removed from the list of edits.
protected  voidtrimForLimit()
     Reduces the number of queued edits to a range of size limit, centered on the index of the next edit.
public synchronized  voidundo()
     Undoes the appropriate edits.
public synchronized  voidundoOrRedo()
     Convenience method that invokes one of undo or redo.
protected  voidundoTo(UndoableEdit edit)
     Undoes all changes from the index of the next edit to edit, updating the index of the next edit appropriately.
public  voidundoableEditHappened(UndoableEditEvent e)
     An UndoableEditListener method.

Field Detail
indexOfNextAdd
int indexOfNextAdd(Code)



limit
int limit(Code)




Constructor Detail
UndoManager
public UndoManager()(Code)
Creates a new UndoManager.




Method Detail
addEdit
public synchronized boolean addEdit(UndoableEdit anEdit)(Code)
Adds an UndoableEdit to this UndoManager, if it's possible. This removes all edits from the index of the next edit to the end of the edits list. If end has been invoked the edit is not added and false is returned. If end hasn't been invoked this returns true.
Parameters:
  anEdit - the edit to be added true if anEdit can be incorporated into thisedit
See Also:   CompoundEdit.end
See Also:   CompoundEdit.addEdit



canRedo
public synchronized boolean canRedo()(Code)
Returns true if edits may be redone. If end has been invoked, this returns the value from super. Otherwise, this returns true if there are any edits to be redone (editToBeRedone returns non-null). true if there are edits to be redone
See Also:   CompoundEdit.canRedo
See Also:   UndoManager.editToBeRedone



canUndo
public synchronized boolean canUndo()(Code)
Returns true if edits may be undone. If end has been invoked, this returns the value from super. Otherwise this returns true if there are any edits to be undone (editToBeUndone returns non-null). true if there are edits to be undone
See Also:   CompoundEdit.canUndo
See Also:   UndoManager.editToBeUndone



canUndoOrRedo
public synchronized boolean canUndoOrRedo()(Code)
Returns true if it is possible to invoke undo or redo. true if invoking canUndoOrRedo is valid
See Also:   UndoManager.undoOrRedo



discardAllEdits
public synchronized void discardAllEdits()(Code)
Empties the undo manager sending each edit a die message in the process.
See Also:   AbstractUndoableEdit.die



editToBeRedone
protected UndoableEdit editToBeRedone()(Code)
Returns the the next significant edit to be redone if redo is invoked. This returns null if there are no edits to be redone. the next significant edit to be redone



editToBeUndone
protected UndoableEdit editToBeUndone()(Code)
Returns the the next significant edit to be undone if undo is invoked. This returns null if there are no edits to be undone. the next significant edit to be undone



end
public synchronized void end()(Code)
Turns this UndoManager into a normal CompoundEdit. This removes all edits that have been undone.
See Also:   CompoundEdit.end



getLimit
public synchronized int getLimit()(Code)
Returns the maximum number of edits this UndoManager holds. A value less than 0 indicates the number of edits is not limited. the maximum number of edits this UndoManager holds
See Also:   UndoManager.addEdit
See Also:   UndoManager.setLimit



getRedoPresentationName
public synchronized String getRedoPresentationName()(Code)
Returns a description of the redoable form of this edit. If end has been invoked this calls into super. Otherwise if there are edits to be redone, this returns the value from the next significant edit that will be redone. If there are no edits to be redone and end has not been invoked this returns the value from the UIManager property "AbstractUndoableEdit.redoText". a description of the redoable form of this edit
See Also:   UndoManager.redo
See Also:   CompoundEdit.getRedoPresentationName



getUndoOrRedoPresentationName
public synchronized String getUndoOrRedoPresentationName()(Code)
Convenience method that returns either getUndoPresentationName or getRedoPresentationName. If the index of the next edit equals the size of the edits list, getUndoPresentationName is returned, otherwise getRedoPresentationName is returned. undo or redo name



getUndoPresentationName
public synchronized String getUndoPresentationName()(Code)
Returns a description of the undoable form of this edit. If end has been invoked this calls into super. Otherwise if there are edits to be undone, this returns the value from the next significant edit that will be undone. If there are no edits to be undone and end has not been invoked this returns the value from the UIManager property "AbstractUndoableEdit.undoText". a description of the undoable form of this edit
See Also:   UndoManager.undo
See Also:   CompoundEdit.getUndoPresentationName



redo
public synchronized void redo() throws CannotRedoException(Code)
Redoes the appropriate edits. If end has been invoked this calls through to the superclass. Otherwise this invokes redo on all edits between the index of the next edit and the next significant edit, updating the index of the next edit appropriately.
throws:
  CannotRedoException - if one of the edits throwsCannotRedoException or there are no editsto be redone
See Also:   CompoundEdit.end
See Also:   UndoManager.canRedo
See Also:   UndoManager.editToBeRedone



redoTo
protected void redoTo(UndoableEdit edit) throws CannotRedoException(Code)
Redoes all changes from the index of the next edit to edit, updating the index of the next edit appropriately.
throws:
  CannotRedoException - if one of the edits throwsCannotRedoException



setLimit
public synchronized void setLimit(int l)(Code)
Sets the maximum number of edits this UndoManager holds. A value less than 0 indicates the number of edits is not limited. If edits need to be discarded to shrink the limit, die will be invoked on them in the reverse order they were added. The default is 100.
Parameters:
  l - the new limit
throws:
  RuntimeException - if this UndoManager is not in progress( end has been invoked)
See Also:   UndoManager.isInProgress
See Also:   UndoManager.end
See Also:   UndoManager.addEdit
See Also:   UndoManager.getLimit



toString
public String toString()(Code)
Returns a string that displays and identifies this object's properties. a String representation of this object



trimEdits
protected void trimEdits(int from, int to)(Code)
Removes edits in the specified range. All edits in the given range (inclusive, and in reverse order) will have die invoked on them and are removed from the list of edits. This has no effect if from > to.
Parameters:
  from - the minimum index to remove
Parameters:
  to - the maximum index to remove



trimForLimit
protected void trimForLimit()(Code)
Reduces the number of queued edits to a range of size limit, centered on the index of the next edit.



undo
public synchronized void undo() throws CannotUndoException(Code)
Undoes the appropriate edits. If end has been invoked this calls through to the superclass, otherwise this invokes undo on all edits between the index of the next edit and the last significant edit, updating the index of the next edit appropriately.
throws:
  CannotUndoException - if one of the edits throwsCannotUndoException or there are no editsto be undone
See Also:   CompoundEdit.end
See Also:   UndoManager.canUndo
See Also:   UndoManager.editToBeUndone



undoOrRedo
public synchronized void undoOrRedo() throws CannotRedoException, CannotUndoException(Code)
Convenience method that invokes one of undo or redo. If any edits have been undone (the index of the next edit is less than the length of the edits list) this invokes redo, otherwise it invokes undo.
See Also:   UndoManager.canUndoOrRedo
See Also:   UndoManager.getUndoOrRedoPresentationName
throws:
  CannotUndoException - if one of the edits throwsCannotUndoException
throws:
  CannotRedoException - if one of the edits throwsCannotRedoException



undoTo
protected void undoTo(UndoableEdit edit) throws CannotUndoException(Code)
Undoes all changes from the index of the next edit to edit, updating the index of the next edit appropriately.
throws:
  CannotUndoException - if one of the edits throwsCannotUndoException



undoableEditHappened
public void undoableEditHappened(UndoableEditEvent e)(Code)
An UndoableEditListener method. This invokes addEdit with e.getEdit().
Parameters:
  e - the UndoableEditEvent theUndoableEditEvent will be added from
See Also:   UndoManager.addEdit



Fields inherited from javax.swing.undo.CompoundEdit
protected Vector<UndoableEdit> edits(Code)(Java Doc)
boolean inProgress(Code)(Java Doc)

Methods inherited from javax.swing.undo.CompoundEdit
public boolean addEdit(UndoableEdit anEdit)(Code)(Java Doc)
public boolean canRedo()(Code)(Java Doc)
public boolean canUndo()(Code)(Java Doc)
public void die()(Code)(Java Doc)
public void end()(Code)(Java Doc)
public String getPresentationName()(Code)(Java Doc)
public String getRedoPresentationName()(Code)(Java Doc)
public String getUndoPresentationName()(Code)(Java Doc)
public boolean isInProgress()(Code)(Java Doc)
public boolean isSignificant()(Code)(Java Doc)
protected UndoableEdit lastEdit()(Code)(Java Doc)
public void redo() throws CannotRedoException(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public void undo() throws CannotUndoException(Code)(Java Doc)

Fields inherited from javax.swing.undo.AbstractUndoableEdit
final protected static String RedoName(Code)(Java Doc)
final protected static String UndoName(Code)(Java Doc)
boolean alive(Code)(Java Doc)
boolean hasBeenDone(Code)(Java Doc)

Methods inherited from javax.swing.undo.AbstractUndoableEdit
public boolean addEdit(UndoableEdit anEdit)(Code)(Java Doc)
public boolean canRedo()(Code)(Java Doc)
public boolean canUndo()(Code)(Java Doc)
public void die()(Code)(Java Doc)
public String getPresentationName()(Code)(Java Doc)
public String getRedoPresentationName()(Code)(Java Doc)
public String getUndoPresentationName()(Code)(Java Doc)
public boolean isSignificant()(Code)(Java Doc)
public void redo() throws CannotRedoException(Code)(Java Doc)
public boolean replaceEdit(UndoableEdit anEdit)(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public void undo() throws CannotUndoException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.