home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / undo / UndoableEditSupport.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  2.6 KB  |  81 lines

  1. package com.sun.java.swing.undo;
  2.  
  3. import com.sun.java.swing.event.UndoableEditEvent;
  4. import com.sun.java.swing.event.UndoableEditListener;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  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.    public int getUpdateLevel() {
  52.       return this.updateLevel;
  53.    }
  54.  
  55.    public synchronized void beginUpdate() {
  56.       if (this.updateLevel == 0) {
  57.          this.compoundEdit = this.createCompoundEdit();
  58.       }
  59.  
  60.       ++this.updateLevel;
  61.    }
  62.  
  63.    protected CompoundEdit createCompoundEdit() {
  64.       return new CompoundEdit();
  65.    }
  66.  
  67.    public synchronized void endUpdate() {
  68.       --this.updateLevel;
  69.       if (this.updateLevel == 0) {
  70.          this.compoundEdit.end();
  71.          this._postEdit(this.compoundEdit);
  72.          this.compoundEdit = null;
  73.       }
  74.  
  75.    }
  76.  
  77.    public String toString() {
  78.       return super.toString() + " updateLevel: " + this.updateLevel + " listeners: " + this.listeners + " compoundEdit: " + this.compoundEdit;
  79.    }
  80. }
  81.