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 / StateEdit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.7 KB  |  69 lines

  1. package javax.swing.undo;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5. import java.util.Vector;
  6.  
  7. public class StateEdit extends AbstractUndoableEdit {
  8.    protected static final String RCSID = "$Id: StateEdit.java,v 1.6 1997/10/01 20:05:51 sandipc Exp $";
  9.    protected StateEditable object;
  10.    protected Hashtable preState;
  11.    protected Hashtable postState;
  12.    protected String undoRedoName;
  13.  
  14.    public StateEdit(StateEditable var1) {
  15.       this.init(var1, (String)null);
  16.    }
  17.  
  18.    public StateEdit(StateEditable var1, String var2) {
  19.       this.init(var1, var2);
  20.    }
  21.  
  22.    protected void init(StateEditable var1, String var2) {
  23.       this.object = var1;
  24.       this.preState = new Hashtable(11);
  25.       this.object.storeState(this.preState);
  26.       this.postState = null;
  27.       this.undoRedoName = var2;
  28.    }
  29.  
  30.    public void end() {
  31.       this.postState = new Hashtable(11);
  32.       this.object.storeState(this.postState);
  33.       this.removeRedundantState();
  34.    }
  35.  
  36.    public void undo() {
  37.       super.undo();
  38.       this.object.restoreState(this.preState);
  39.    }
  40.  
  41.    public void redo() {
  42.       super.redo();
  43.       this.object.restoreState(this.postState);
  44.    }
  45.  
  46.    public String getPresentationName() {
  47.       return this.undoRedoName;
  48.    }
  49.  
  50.    protected void removeRedundantState() {
  51.       Vector var1 = new Vector();
  52.       Enumeration var2 = this.preState.keys();
  53.  
  54.       while(var2.hasMoreElements()) {
  55.          Object var3 = var2.nextElement();
  56.          if (this.postState.containsKey(var3) && this.postState.get(var3).equals(this.preState.get(var3))) {
  57.             var1.addElement(var3);
  58.          }
  59.       }
  60.  
  61.       for(int var5 = var1.size() - 1; var5 >= 0; --var5) {
  62.          Object var4 = var1.elementAt(var5);
  63.          this.preState.remove(var4);
  64.          this.postState.remove(var4);
  65.       }
  66.  
  67.    }
  68. }
  69.