1 19 20 package org.netbeans.editor; 21 22 import javax.swing.text.Element ; 23 import javax.swing.text.AttributeSet ; 24 import javax.swing.text.BadLocationException ; 25 26 32 33 public class LeafElement extends BaseElement { 34 35 36 protected Mark startMark; 37 38 39 protected Mark endMark; 40 41 42 protected boolean bol; 43 44 45 protected boolean eol; 46 47 48 public LeafElement(BaseDocument doc, BaseElement parent, AttributeSet attrs, 49 int startOffset, int endOffset, boolean bol, boolean eol) { 50 super(doc, parent, attrs); 51 this.bol = bol; 52 this.eol = eol; 53 try { 55 startMark = new Mark(true); 56 endMark = new Mark(false); 57 startMark.insert(doc, startOffset); 58 endMark.insert(doc, endOffset); 59 } catch (BadLocationException e) { 60 Utilities.annotateLoggable(e); 61 } catch (InvalidMarkException e) { 62 throw new IllegalStateException (e.toString()); 63 } 64 } 65 66 protected void finalize() throws Throwable { 67 try { 68 startMark.remove(); 69 endMark.remove(); 70 } catch (InvalidMarkException e) { 71 } 72 super.finalize(); 73 } 74 75 76 public final Mark getStartMark() { 77 return startMark; 78 } 79 80 81 public final int getStartOffset() { 82 try { 83 return startMark.getOffset(); 84 } catch (InvalidMarkException e) { 85 return 0; 86 } 87 } 88 89 90 public final Mark getEndMark() { 91 return endMark; 92 } 93 94 95 public final int getEndOffset() { 96 try { 97 return endMark.getOffset(); 98 } catch (InvalidMarkException e) { 99 return 0; 100 } 101 } 102 103 104 public final boolean isBOL() { 105 return bol; 106 } 107 108 109 public final boolean isEOL() { 110 return eol; 111 } 112 113 116 public int getElementIndex(int offset) { 117 return -1; 118 } 119 120 121 public int getElementCount() { 122 return 0; 123 } 124 125 128 public Element getElement(int index) { 129 return null; 130 } 131 132 133 public boolean isLeaf() { 134 return true; 135 } 136 137 public String toString() { 138 return "startOffset=" + getStartOffset() + ", endOffset=" + getEndMark(); } 141 142 } 143 | Popular Tags |