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

  1. package com.sun.java.swing.text;
  2.  
  3. import com.sun.java.swing.event.DocumentEvent;
  4. import com.sun.java.swing.event.DocumentEvent.EventType;
  5. import com.sun.java.swing.undo.CannotRedoException;
  6. import com.sun.java.swing.undo.CannotUndoException;
  7. import com.sun.java.swing.undo.CompoundEdit;
  8. import com.sun.java.swing.undo.UndoableEdit;
  9. import java.util.Hashtable;
  10.  
  11. public class AbstractDocument$DefaultDocumentEvent extends CompoundEdit implements DocumentEvent {
  12.    // $FF: synthetic field
  13.    private final AbstractDocument this$0;
  14.    private int offset;
  15.    private int length;
  16.    private Hashtable changeLookup;
  17.    private DocumentEvent.EventType type;
  18.  
  19.    public AbstractDocument$DefaultDocumentEvent(AbstractDocument var1, int var2, int var3, DocumentEvent.EventType var4) {
  20.       this.this$0 = var1;
  21.       this.this$0 = var1;
  22.       this.offset = var2;
  23.       this.length = var3;
  24.       this.type = var4;
  25.    }
  26.  
  27.    public String toString() {
  28.       return super.edits.toString();
  29.    }
  30.  
  31.    public boolean addEdit(UndoableEdit var1) {
  32.       if (this.changeLookup == null && super.edits.size() > 10) {
  33.          this.changeLookup = new Hashtable();
  34.          int var2 = super.edits.size();
  35.  
  36.          for(int var3 = 0; var3 < var2; ++var3) {
  37.             Object var4 = super.edits.elementAt(var3);
  38.             if (var4 instanceof DocumentEvent.ElementChange) {
  39.                DocumentEvent.ElementChange var5 = (DocumentEvent.ElementChange)var4;
  40.                this.changeLookup.put(var5.getElement(), var5);
  41.             }
  42.          }
  43.       }
  44.  
  45.       if (this.changeLookup != null && var1 instanceof DocumentEvent.ElementChange) {
  46.          DocumentEvent.ElementChange var6 = (DocumentEvent.ElementChange)var1;
  47.          this.changeLookup.put(var6.getElement(), var6);
  48.       }
  49.  
  50.       return super.addEdit(var1);
  51.    }
  52.  
  53.    public void redo() throws CannotRedoException {
  54.       this.this$0.writeLock();
  55.  
  56.       try {
  57.          super.redo();
  58.          if (this.type == EventType.INSERT) {
  59.             this.this$0.fireInsertUpdate(this);
  60.          } else if (this.type == EventType.REMOVE) {
  61.             this.this$0.fireRemoveUpdate(this);
  62.          } else {
  63.             this.this$0.fireChangedUpdate(this);
  64.          }
  65.       } finally {
  66.          this.this$0.writeUnlock();
  67.       }
  68.  
  69.    }
  70.  
  71.    public void undo() throws CannotUndoException {
  72.       this.this$0.writeLock();
  73.  
  74.       try {
  75.          super.undo();
  76.          if (this.type == EventType.REMOVE) {
  77.             this.this$0.fireInsertUpdate(this);
  78.          } else if (this.type == EventType.INSERT) {
  79.             this.this$0.fireRemoveUpdate(this);
  80.          } else {
  81.             this.this$0.fireChangedUpdate(this);
  82.          }
  83.       } finally {
  84.          this.this$0.writeUnlock();
  85.       }
  86.  
  87.    }
  88.  
  89.    public boolean isSignificant() {
  90.       return true;
  91.    }
  92.  
  93.    public String getPresentationName() {
  94.       DocumentEvent.EventType var1 = this.getType();
  95.       if (var1 == EventType.INSERT) {
  96.          return "addition";
  97.       } else {
  98.          return var1 == EventType.REMOVE ? "deletion" : "style change";
  99.       }
  100.    }
  101.  
  102.    public String getUndoPresentationName() {
  103.       return "Undo " + this.getPresentationName();
  104.    }
  105.  
  106.    public String getRedoPresentationName() {
  107.       return "Redo " + this.getPresentationName();
  108.    }
  109.  
  110.    public DocumentEvent.EventType getType() {
  111.       return this.type;
  112.    }
  113.  
  114.    public int getOffset() {
  115.       return this.offset;
  116.    }
  117.  
  118.    public int getLength() {
  119.       return this.length;
  120.    }
  121.  
  122.    public Document getDocument() {
  123.       return this.this$0;
  124.    }
  125.  
  126.    public DocumentEvent.ElementChange getChange(Element var1) {
  127.       if (this.changeLookup != null) {
  128.          return (DocumentEvent.ElementChange)this.changeLookup.get(var1);
  129.       } else {
  130.          int var2 = super.edits.size();
  131.  
  132.          for(int var3 = 0; var3 < var2; ++var3) {
  133.             Object var4 = super.edits.elementAt(var3);
  134.             if (var4 instanceof DocumentEvent.ElementChange) {
  135.                DocumentEvent.ElementChange var5 = (DocumentEvent.ElementChange)var4;
  136.                if (var5.getElement() == var1) {
  137.                   return var5;
  138.                }
  139.             }
  140.          }
  141.  
  142.          return null;
  143.       }
  144.    }
  145. }
  146.