1 33 34 package edu.rice.cs.drjava.model; 35 36 import javax.swing.text.Position ; 37 import java.io.File ; 38 39 43 public class SimpleDocumentRegion implements DocumentRegion { 44 protected final OpenDefinitionsDocument _doc; 45 protected final File _file; 46 protected volatile int _startOffset; 47 protected volatile int _endOffset; 48 protected volatile Position _startPos = null; 49 protected volatile Position _endPos = null; 50 51 57 public SimpleDocumentRegion(OpenDefinitionsDocument doc, File file, int so, int eo) { 58 _doc = doc; 59 _file = file; 60 _startOffset = so; 61 _endOffset = eo; 62 if (_doc != null) { 63 try { 64 _startPos = _doc.createPosition(so); 65 _endPos = _doc.createPosition(eo); 66 } 67 catch(javax.swing.text.BadLocationException e) { } 68 } 69 } 70 71 72 public OpenDefinitionsDocument getDocument() { return _doc; } 73 74 75 public File getFile() { return _file; } 76 77 78 public int getStartOffset() { 79 if (_startPos != null) { 80 _startOffset = _startPos.getOffset(); 82 } 83 return _startOffset; 84 } 85 86 87 public int getEndOffset() { 88 if (_endPos != null) { 89 _endOffset = _endPos.getOffset(); 91 } 92 return _endOffset; 93 } 94 95 96 public static boolean equals(Object o1, Object o2) { 97 if (o1 == null) return o2 == null; 98 return o1.equals(o2); 99 } 100 101 102 public boolean equals(Object other) { 103 if (other == null || other.getClass() != getClass()) return false; 104 SimpleDocumentRegion o = (SimpleDocumentRegion) other; 105 return equals(_doc, o._doc) && equals(_file, o._file) && 106 _startPos.getOffset() == o._startPos.getOffset() && 107 _endPos.getOffset() == o._endPos.getOffset(); 108 } 109 110 public String toString() { 111 return (_doc != null ? _doc.toString() : "null") + " "+_startOffset+" .. "+_endOffset; 112 } 113 } 114 | Popular Tags |