1 19 package org.openide.text; 20 21 import org.openide.util.WeakListeners; 22 23 import javax.swing.event.*; 24 import javax.swing.text.*; 25 26 27 32 class BackwardPosition extends Object implements Position, DocumentListener { 33 34 private int offset; 35 36 38 private BackwardPosition(int offset) { 39 this.offset = offset; 40 } 41 42 46 public static Position create(Document doc, int offset) { 47 BackwardPosition p = new BackwardPosition(offset); 48 doc.addDocumentListener(org.openide.util.WeakListeners.document(p, doc)); 49 50 return p; 51 } 52 53 57 59 public int getOffset() { 60 return offset; 61 } 62 63 67 68 public void insertUpdate(DocumentEvent e) { 69 if (e.getOffset() < offset) { 71 offset += e.getLength(); 72 } 73 } 74 75 76 public void removeUpdate(DocumentEvent e) { 77 int o = e.getOffset(); 78 79 if (o < offset) { 80 offset -= e.getLength(); 81 82 if (offset < o) { 84 offset = o; 85 } 86 } 87 } 88 89 90 public void changedUpdate(DocumentEvent e) { 91 } 92 } 93 | Popular Tags |