home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / undo / UndoableEditSupport.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.1 KB  |  82 lines

  1. package javax.swing.undo;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Vector;
  5. import javax.swing.event.UndoableEditEvent;
  6. import javax.swing.event.UndoableEditListener;
  7.  
  8. public class UndoableEditSupport {
  9.    protected int updateLevel;
  10.    protected CompoundEdit compoundEdit;
  11.    protected Vector listeners;
  12.    protected Object realSource;
  13.  
  14.    public UndoableEditSupport() {
  15.       this((Object)null);
  16.    }
  17.  
  18.    public UndoableEditSupport(Object var1) {
  19.       this.realSource = var1 == null ? this : var1;
  20.       this.updateLevel = 0;
  21.       this.compoundEdit = null;
  22.       this.listeners = new Vector();
  23.    }
  24.  
  25.    public synchronized void addUndoableEditListener(UndoableEditListener var1) {
  26.       this.listeners.addElement(var1);
  27.    }
  28.  
  29.    public synchronized void removeUndoableEditListener(UndoableEditListener var1) {
  30.       this.listeners.removeElement(var1);
  31.    }
  32.  
  33.    protected void _postEdit(UndoableEdit var1) {
  34.       UndoableEditEvent var2 = new UndoableEditEvent(this.realSource, var1);
  35.       Enumeration var3 = this.listeners.elements();
  36.  
  37.       while(var3.hasMoreElements()) {
  38.          ((UndoableEditListener)var3.nextElement()).undoableEditHappened(var2);
  39.       }
  40.  
  41.    }
  42.  
  43.    public synchronized void postEdit(UndoableEdit var1) {
  44.       if (this.updateLevel == 0) {
  45.          this._postEdit(var1);
  46.       } else {
  47.          this.compoundEdit.addEdit(var1);
  48.       }
  49.  
  50.    }
  51.  
  52.    public int getUpdateLevel() {
  53.       return this.updateLevel;
  54.    }
  55.  
  56.    public synchronized void beginUpdate() {
  57.       if (this.updateLevel == 0) {
  58.          this.compoundEdit = this.createCompoundEdit();
  59.       }
  60.  
  61.       ++this.updateLevel;
  62.    }
  63.  
  64.    protected CompoundEdit createCompoundEdit() {
  65.       return new CompoundEdit();
  66.    }
  67.  
  68.    public synchronized void endUpdate() {
  69.       --this.updateLevel;
  70.       if (this.updateLevel == 0) {
  71.          this.compoundEdit.end();
  72.          this._postEdit(this.compoundEdit);
  73.          this.compoundEdit = null;
  74.       }
  75.  
  76.    }
  77.  
  78.    public String toString() {
  79.       return super.toString() + " updateLevel: " + this.updateLevel + " listeners: " + this.listeners + " compoundEdit: " + this.compoundEdit;
  80.    }
  81. }
  82.