home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / AbstractDocument$DefaultDocumentEvent.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.1 KB  |  150 lines

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