01: /*
02: * Sun Public License Notice
03: *
04: * The contents of this file are subject to the Sun Public License
05: * Version 1.0 (the "License"). You may not use this file except in
06: * compliance with the License. A copy of the License is available at
07: * http://www.sun.com/
08: *
09: * The Original Code is NetBeans. The Initial Developer of the Original
10: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11: * Microsystems, Inc. All Rights Reserved.
12: */
13:
14: package org.netbeans.editor;
15:
16: import javax.swing.text.AttributeSet;
17: import javax.swing.text.Document;
18: import javax.swing.text.Element;
19:
20: /**
21: * Element implementation. It serves as parent class for both leaf and branch
22: * elements.
23: *
24: * @author Miloslav Metelka
25: * @version 1.00
26: */
27:
28: public abstract class BaseElement implements Element {
29:
30: /** Element name attribute */
31: public static final String ElementNameAttribute = "$ename"; // NOI18N
32:
33: /** Reference to document this element is part of */
34: protected BaseDocument doc;
35:
36: /** Parent element */
37: protected BaseElement parent;
38:
39: /** Atributes of this element */
40: protected AttributeSet attrs;
41:
42: public BaseElement(BaseDocument doc, BaseElement parent,
43: AttributeSet attrs) {
44: this .doc = doc;
45: this .parent = parent;
46: this .attrs = attrs;
47: }
48:
49: /** Get document this element is part of */
50: public Document getDocument() {
51: return doc;
52: }
53:
54: /** Get parent element */
55: public Element getParentElement() {
56: return parent;
57: }
58:
59: /** Get element name if defined */
60: public String getName() {
61: if (attrs.isDefined(ElementNameAttribute)) {
62: return (String) attrs.getAttribute(ElementNameAttribute);
63: }
64: return null;
65: }
66:
67: /** Get attributes of this element */
68: public AttributeSet getAttributes() {
69: return attrs;
70: }
71:
72: /** Get start offset of this element */
73: public abstract int getStartOffset();
74:
75: /** Get start mark of this element */
76: public abstract Mark getStartMark();
77:
78: /** Get end offset of this element */
79: public abstract int getEndOffset();
80:
81: /** Get end mark of this element */
82: public abstract Mark getEndMark();
83:
84: /** Get child of this element at specified index */
85: public abstract Element getElement(int index);
86:
87: /** Gets the child element index closest to the given offset. */
88: public abstract int getElementIndex(int offset);
89:
90: /** Get number of children of this element */
91: public abstract int getElementCount();
92:
93: /** Does this element have any children? */
94: public abstract boolean isLeaf();
95:
96: }
|