KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > BaseElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.editor;
21
22 import javax.swing.text.Document JavaDoc;
23 import javax.swing.text.Element JavaDoc;
24 import javax.swing.text.AttributeSet JavaDoc;
25 import javax.swing.text.SimpleAttributeSet JavaDoc;
26
27 /**
28 * Element implementation. It serves as parent class
29 * for both leaf and branch elements.
30 *
31 * @author Miloslav Metelka
32 * @version 1.00
33 */

34
35 public abstract class BaseElement implements Element JavaDoc {
36
37     /** Element name attribute */
38     public static final String JavaDoc ElementNameAttribute = "$ename"; // NOI18N
39

40     /** Reference to document this element is part of */
41     protected BaseDocument doc;
42
43     /** Parent element */
44     protected BaseElement parent;
45
46     /** Atributes of this element */
47     protected AttributeSet JavaDoc attrs;
48
49     public BaseElement(BaseDocument doc, BaseElement parent, AttributeSet JavaDoc attrs) {
50         this.doc = doc;
51         this.parent = parent;
52         this.attrs = attrs;
53     }
54
55     /** Get document this element is part of */
56     public Document JavaDoc getDocument() {
57         return doc;
58     }
59
60     /** Get parent element */
61     public Element JavaDoc getParentElement() {
62         return parent;
63     }
64
65     /** Get element name if defined */
66     public String JavaDoc getName() {
67         AttributeSet JavaDoc as = attrs;
68         if (as != null && as.isDefined(ElementNameAttribute)) {
69             return (String JavaDoc)as.getAttribute(ElementNameAttribute);
70         } else {
71             return null;
72         }
73     }
74
75     /** Get attributes of this element */
76     public AttributeSet JavaDoc getAttributes() {
77         AttributeSet JavaDoc as = attrs;
78         return as == null ? SimpleAttributeSet.EMPTY : as;
79     }
80
81     /** Get start offset of this element */
82     public abstract int getStartOffset();
83
84     /** Get start mark of this element */
85     public abstract Mark getStartMark();
86
87     /** Get end offset of this element */
88     public abstract int getEndOffset();
89
90     /** Get end mark of this element */
91     public abstract Mark getEndMark();
92
93     /** Get child of this element at specified index */
94     public abstract Element JavaDoc getElement(int index);
95
96     /** Gets the child element index closest to the given offset. */
97     public abstract int getElementIndex(int offset);
98
99     /** Get number of children of this element */
100     public abstract int getElementCount();
101
102     /** Does this element have any children? */
103     public abstract boolean isLeaf();
104
105 }
106
Popular Tags