KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > Element


1 /*
2  * @(#)Element.java 1.23 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.text;
8
9 /**
10  * Interface to describe a structural piece of a document. It
11  * is intended to capture the spirit of an SGML element.
12  *
13  * @author Timothy Prinzing
14  * @version 1.23 12/19/03
15  */

16 public interface Element {
17
18     /**
19      * Fetches the document associated with this element.
20      *
21      * @return the document
22      */

23     public Document JavaDoc getDocument();
24
25     /**
26      * Fetches the parent element. If the element is a root level
27      * element returns <code>null</code>.
28      *
29      * @return the parent element
30      */

31     public Element JavaDoc getParentElement();
32
33     /**
34      * Fetches the name of the element. If the element is used to
35      * represent some type of structure, this would be the type
36      * name.
37      *
38      * @return the element name
39      */

40     public String JavaDoc getName();
41
42     /**
43      * Fetches the collection of attributes this element contains.
44      *
45      * @return the attributes for the element
46      */

47     public AttributeSet JavaDoc getAttributes();
48
49     /**
50      * Fetches the offset from the beginning of the document
51      * that this element begins at. If this element has
52      * children, this will be the offset of the first child.
53      * As a document position, there is an implied forward bias.
54      *
55      * @return the starting offset >= 0 and < getEndOffset();
56      * @see Document
57      * @see AbstractDocument
58      */

59     public int getStartOffset();
60
61     /**
62      * Fetches the offset from the beginning of the document
63      * that this element ends at. If this element has
64      * children, this will be the end offset of the last child.
65      * As a document position, there is an implied backward bias.
66      * <p>
67      * All the default <code>Document</code> implementations
68      * descend from <code>AbstractDocument</code>.
69      * <code>AbstractDocument</code> models an implied break at the end of
70      * the document. As a result of this, it is possible for this to
71      * return a value greater than the length of the document.
72      *
73      * @return the ending offset > getStartOffset() and
74      * <= getDocument().getLength() + 1
75      * @see Document
76      * @see AbstractDocument
77      */

78     public int getEndOffset();
79
80     /**
81      * Gets the child element index closest to the given offset.
82      * The offset is specified relative to the beginning of the
83      * document. Returns <code>-1</code> if the
84      * <code>Element</code> is a leaf, otherwise returns
85      * the index of the <code>Element</code> that best represents
86      * the given location. Returns <code>0</code> if the location
87      * is less than the start offset. Returns
88      * <code>getElementCount() - 1</code> if the location is
89      * greater than or equal to the end offset.
90      *
91      * @param offset the specified offset >= 0
92      * @return the element index >= 0
93      */

94     public int getElementIndex(int offset);
95
96     /**
97      * Gets the number of child elements contained by this element.
98      * If this element is a leaf, a count of zero is returned.
99      *
100      * @return the number of child elements >= 0
101      */

102     public int getElementCount();
103
104     /**
105      * Fetches the child element at the given index.
106      *
107      * @param index the specified index >= 0
108      * @return the child element
109      */

110     public Element JavaDoc getElement(int index);
111
112     /**
113      * Is this element a leaf element? An element that
114      * <i>may</i> have children, even if it currently
115      * has no children, would return <code>false</code>.
116      *
117      * @return true if a leaf element else false
118      */

119     public boolean isLeaf();
120
121
122 }
123
124
Popular Tags