1 19 20 package org.netbeans.editor; 21 22 import javax.swing.text.Document ; 23 import javax.swing.text.Element ; 24 import javax.swing.text.AttributeSet ; 25 import javax.swing.text.SimpleAttributeSet ; 26 27 34 35 public abstract class BaseElement implements Element { 36 37 38 public static final String ElementNameAttribute = "$ename"; 40 41 protected BaseDocument doc; 42 43 44 protected BaseElement parent; 45 46 47 protected AttributeSet attrs; 48 49 public BaseElement(BaseDocument doc, BaseElement parent, AttributeSet attrs) { 50 this.doc = doc; 51 this.parent = parent; 52 this.attrs = attrs; 53 } 54 55 56 public Document getDocument() { 57 return doc; 58 } 59 60 61 public Element getParentElement() { 62 return parent; 63 } 64 65 66 public String getName() { 67 AttributeSet as = attrs; 68 if (as != null && as.isDefined(ElementNameAttribute)) { 69 return (String )as.getAttribute(ElementNameAttribute); 70 } else { 71 return null; 72 } 73 } 74 75 76 public AttributeSet getAttributes() { 77 AttributeSet as = attrs; 78 return as == null ? SimpleAttributeSet.EMPTY : as; 79 } 80 81 82 public abstract int getStartOffset(); 83 84 85 public abstract Mark getStartMark(); 86 87 88 public abstract int getEndOffset(); 89 90 91 public abstract Mark getEndMark(); 92 93 94 public abstract Element getElement(int index); 95 96 97 public abstract int getElementIndex(int offset); 98 99 100 public abstract int getElementCount(); 101 102 103 public abstract boolean isLeaf(); 104 105 } 106 | Popular Tags |