1 19 20 package org.netbeans.editor; 21 22 import javax.swing.text.Document ; 23 import javax.swing.text.AbstractDocument ; 24 import javax.swing.text.Element ; 25 import javax.swing.text.AttributeSet ; 26 import javax.swing.text.Position ; 27 import javax.swing.text.SimpleAttributeSet ; 28 29 42 final class LineElement implements Element , Position { 43 44 45 private final LineRootElement root; 46 47 48 private final Position startPos; 49 50 51 private final Position endPos; 52 53 54 private AttributeSet attributes = null; 55 56 private Syntax.StateInfo syntaxStateInfo; 57 58 LineElement(LineRootElement root, Position startPos, Position endPos) { 59 assert(startPos != null); 60 assert(endPos != null); 61 62 this.root = root; 63 this.startPos = startPos; 64 this.endPos = endPos; 65 } 66 67 public Document getDocument() { 68 return root.getDocument(); 69 } 70 71 public int getOffset() { 72 return getStartOffset(); 73 } 74 75 public int getStartOffset() { 76 return startPos.getOffset(); 77 } 78 79 Position getStartPosition() { 80 return startPos; 81 } 82 83 public int getEndOffset() { 84 return endPos.getOffset(); 85 } 86 87 Position getEndPosition() { 88 return endPos; 89 } 90 91 public Element getParentElement() { 92 return root; 93 } 94 95 public String getName() { 96 return AbstractDocument.ParagraphElementName; 97 } 98 99 public AttributeSet getAttributes() { 100 AttributeSet as = attributes; 101 return as == null ? SimpleAttributeSet.EMPTY : as; 102 } 103 104 public void setAttributes(AttributeSet attributes) { 105 this.attributes = attributes; 106 } 107 108 public int getElementIndex(int offset) { 109 return -1; 110 } 111 112 public int getElementCount() { 113 return 0; 114 } 115 116 public Element getElement(int index) { 117 return null; 118 } 119 120 public boolean isLeaf() { 121 return true; 122 } 123 124 Syntax.StateInfo getSyntaxStateInfo() { 125 return syntaxStateInfo; 126 } 127 128 void updateSyntaxStateInfo(Syntax syntax) { 129 if (syntaxStateInfo == null) { 130 syntaxStateInfo = syntax.createStateInfo(); 131 assert (syntaxStateInfo != null); 132 } 133 syntax.storeState(syntaxStateInfo); 134 } 135 136 void clearSyntaxStateInfo() { 137 syntaxStateInfo = null; 138 } 139 140 public String toString() { 141 return "getStartOffset()=" + getStartOffset() + ", getEndOffset()=" + getEndOffset() + ", syntaxStateInfo=" + getSyntaxStateInfo(); } 145 146 } 147 | Popular Tags |