FileDocCategorySizeDatePackage
UndoableEditSupport.javaAPI DocJava SE 5 API4425Fri Aug 26 14:58:22 BST 2005javax.swing.undo

UndoableEditSupport

public class UndoableEditSupport extends Object
A support class used for managing UndoableEdit listeners.
author
Ray Ryan
version
1.20 05/05/04

Fields Summary
protected int
updateLevel
protected CompoundEdit
compoundEdit
protected Vector
listeners
protected Object
realSource
Constructors Summary
public UndoableEditSupport()
Constructs an UndoableEditSupport object.

	this(null);
    
public UndoableEditSupport(Object r)
Constructs an UndoableEditSupport object.

param
r an Object

	realSource = r == null ? this : r;
	updateLevel = 0;
	compoundEdit = null;
	listeners = new Vector<UndoableEditListener>();
    
Methods Summary
protected void_postEdit(javax.swing.undo.UndoableEdit e)
Called only from postEdit and endUpdate. Calls undoableEditHappened in all listeners. No synchronization is performed here, since the two calling methods are synchronized.

	UndoableEditEvent ev = new UndoableEditEvent(realSource, e);
	Enumeration cursor = ((Vector)listeners.clone()).elements();
	while (cursor.hasMoreElements()) {
	    ((UndoableEditListener)cursor.nextElement()).
		undoableEditHappened(ev);	    
	}
    
public synchronized voidaddUndoableEditListener(javax.swing.event.UndoableEditListener l)
Registers an UndoableEditListener. The listener is notified whenever an edit occurs which can be undone.

param
l an UndoableEditListener object
see
#removeUndoableEditListener

	listeners.addElement(l);
    
public synchronized voidbeginUpdate()

	if (updateLevel == 0) {
	    compoundEdit = createCompoundEdit();
	}
	updateLevel++;
    
protected javax.swing.undo.CompoundEditcreateCompoundEdit()
Called only from beginUpdate. Exposed here for subclasses' use.

	return new CompoundEdit();
    
public synchronized voidendUpdate()
DEADLOCK WARNING: Calling this method may call undoableEditHappened in all listeners. It is unwise to call this method from one of its listeners.

	updateLevel--;
	if (updateLevel == 0) {
	    compoundEdit.end();
	    _postEdit(compoundEdit);
	    compoundEdit = null;
	}
    
public synchronized javax.swing.event.UndoableEditListener[]getUndoableEditListeners()
Returns an array of all the UndoableEditListeners added to this UndoableEditSupport with addUndoableEditListener().

return
all of the UndoableEditListeners added or an empty array if no listeners have been added
since
1.4

        return (UndoableEditListener[])(listeners.toArray(
                new UndoableEditListener[0]));
    
public intgetUpdateLevel()
Returns the update level value.

return
an integer representing the update level

	return updateLevel;
    
public synchronized voidpostEdit(javax.swing.undo.UndoableEdit e)
DEADLOCK WARNING: Calling this method may call undoableEditHappened in all listeners. It is unwise to call this method from one of its listeners.

	if (updateLevel == 0) {
	    _postEdit(e);
	} else {
	    // PENDING(rjrjr) Throw an exception if this fails? 
	    compoundEdit.addEdit(e);
	}
    
public synchronized voidremoveUndoableEditListener(javax.swing.event.UndoableEditListener l)
Removes an UndoableEditListener.

param
l the UndoableEditListener object to be removed
see
#addUndoableEditListener

	listeners.removeElement(l);
    
public java.lang.StringtoString()
Returns a string that displays and identifies this object's properties.

return
a String representation of this object

	return super.toString() +
	    " updateLevel: " + updateLevel +
	    " listeners: " + listeners +
	    " compoundEdit: " + compoundEdit;