24 */ 25 package javax.swing.text; 26 27 /** 28 * Interface to describe a structural piece of a document. It 29 * is intended to capture the spirit of an SGML element. 30 * 31 * @author Timothy Prinzing 32 */ 33 public interface Element { 34 35 /** 36 * Fetches the document associated with this element. 37 * 38 * @return the document 39 */ 40 public Document getDocument(); 41 42 /** 43 * Fetches the parent element. If the element is a root level 44 * element returns <code>null</code>. 45 * 46 * @return the parent element 47 */ 48 public Element getParentElement(); 49 50 /** 51 * Fetches the name of the element. If the element is used to 52 * represent some type of structure, this would be the type 53 * name. 54 * 55 * @return the element name 56 */ 57 public String getName(); 58 59 /** 60 * Fetches the collection of attributes this element contains. 61 * 62 * @return the attributes for the element 63 */ 64 public AttributeSet getAttributes(); 65 66 /** 67 * Fetches the offset from the beginning of the document 68 * that this element begins at. If this element has 69 * children, this will be the offset of the first child. 70 * As a document position, there is an implied forward bias. 71 * 72 * @return the starting offset >= 0 and < getEndOffset(); 73 * @see Document 74 * @see AbstractDocument 75 */ 76 public int getStartOffset(); 77 78 /** 79 * Fetches the offset from the beginning of the document 80 * that this element ends at. If this element has 81 * children, this will be the end offset of the last child. 82 * As a document position, there is an implied backward bias. 83 * <p> 84 * All the default <code>Document</code> implementations 85 * descend from <code>AbstractDocument</code>. 86 * <code>AbstractDocument</code> models an implied break at the end of 87 * the document. As a result of this, it is possible for this to 88 * return a value greater than the length of the document. 89 * 90 * @return the ending offset > getStartOffset() and 91 * <= getDocument().getLength() + 1 92 * @see Document 93 * @see AbstractDocument 94 */ 95 public int getEndOffset(); 96 97 /** 98 * Gets the child element index closest to the given offset. 99 * The offset is specified relative to the beginning of the 100 * document. Returns <code>-1</code> if the 101 * <code>Element</code> is a leaf, otherwise returns 102 * the index of the <code>Element</code> that best represents 103 * the given location. Returns <code>0</code> if the location 104 * is less than the start offset. Returns 105 * <code>getElementCount() - 1</code> if the location is 106 * greater than or equal to the end offset. 107 * 108 * @param offset the specified offset >= 0 109 * @return the element index >= 0 110 */ 111 public int getElementIndex(int offset); 112 113 /** 114 * Gets the number of child elements contained by this element. 115 * If this element is a leaf, a count of zero is returned. 116 * 117 * @return the number of child elements >= 0 118 */ 119 public int getElementCount(); 120 121 /** 122 * Fetches the child element at the given index. 123 * 124 * @param index the specified index >= 0 125 * @return the child element 126 */ 127 public Element getElement(int index); 128 129 /** 130 * Is this element a leaf element? An element that 131 * <i>may</i> have children, even if it currently 132 * has no children, would return <code>false</code>. 133 * 134 * @return true if a leaf element else false 135 */ 136 public boolean isLeaf(); 137 138 139 } | 24 */ 25 package javax.swing.text; 26 27 /** 28 * Interface to describe a structural piece of a document. It 29 * is intended to capture the spirit of an SGML element. 30 * 31 * @author Timothy Prinzing 32 */ 33 public interface Element { 34 35 /** 36 * Fetches the document associated with this element. 37 * 38 * @return the document 39 */ 40 public Document getDocument(); 41 42 /** 43 * Fetches the parent element. If the element is a root level 44 * element returns {@code null}. 45 * 46 * @return the parent element 47 */ 48 public Element getParentElement(); 49 50 /** 51 * Fetches the name of the element. If the element is used to 52 * represent some type of structure, this would be the type 53 * name. 54 * 55 * @return the element name 56 */ 57 public String getName(); 58 59 /** 60 * Fetches the collection of attributes this element contains. 61 * 62 * @return the attributes for the element 63 */ 64 public AttributeSet getAttributes(); 65 66 /** 67 * Fetches the offset from the beginning of the document 68 * that this element begins at. If this element has 69 * children, this will be the offset of the first child. 70 * As a document position, there is an implied forward bias. 71 * 72 * @return the starting offset >= 0 and < getEndOffset(); 73 * @see Document 74 * @see AbstractDocument 75 */ 76 public int getStartOffset(); 77 78 /** 79 * Fetches the offset from the beginning of the document 80 * that this element ends at. If this element has 81 * children, this will be the end offset of the last child. 82 * As a document position, there is an implied backward bias. 83 * <p> 84 * All the default {@code Document} implementations 85 * descend from {@code AbstractDocument}. 86 * {@code AbstractDocument} models an implied break at the end of 87 * the document. As a result of this, it is possible for this to 88 * return a value greater than the length of the document. 89 * 90 * @return the ending offset > getStartOffset() and 91 * <= getDocument().getLength() + 1 92 * @see Document 93 * @see AbstractDocument 94 */ 95 public int getEndOffset(); 96 97 /** 98 * Gets the child element index closest to the given offset. 99 * The offset is specified relative to the beginning of the 100 * document. Returns {@code -1} if the 101 * {@code Element} is a leaf, otherwise returns 102 * the index of the {@code Element} that best represents 103 * the given location. Returns {@code 0} if the location 104 * is less than the start offset. Returns 105 * {@code getElementCount() - 1} if the location is 106 * greater than or equal to the end offset. 107 * 108 * @param offset the specified offset >= 0 109 * @return the element index >= 0 110 */ 111 public int getElementIndex(int offset); 112 113 /** 114 * Gets the number of child elements contained by this element. 115 * If this element is a leaf, a count of zero is returned. 116 * 117 * @return the number of child elements >= 0 118 */ 119 public int getElementCount(); 120 121 /** 122 * Fetches the child element at the given index. 123 * 124 * @param index the specified index >= 0 125 * @return the child element 126 */ 127 public Element getElement(int index); 128 129 /** 130 * Is this element a leaf element? An element that 131 * <i>may</i> have children, even if it currently 132 * has no children, would return {@code false}. 133 * 134 * @return true if a leaf element else false 135 */ 136 public boolean isLeaf(); 137 138 139 } |