1. /*
  2. * @(#)Element.java 1.17 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.text;
  11. /**
  12. * Interface to describe a structural piece of a document. It
  13. * is intended to capture the spirit of an SGML element.
  14. *
  15. * @author Timothy Prinzing
  16. * @version 1.17 02/02/00
  17. */
  18. public interface Element {
  19. /**
  20. * Fetches the document associated with this element.
  21. *
  22. * @return the document
  23. */
  24. public Document getDocument();
  25. /**
  26. * Fetches the parent element. If the element is a root level
  27. * element returns null.
  28. *
  29. * @return the parent element
  30. */
  31. public Element getParentElement();
  32. /**
  33. * Fetches the name of the element. If the element is used to
  34. * represent some type of structure, this would be the type
  35. * name.
  36. *
  37. * @return the element name
  38. */
  39. public String getName();
  40. /**
  41. * Fetches the collection of attributes this element contains.
  42. *
  43. * @return the attributes for the element
  44. */
  45. public AttributeSet getAttributes();
  46. /**
  47. * Fetches the offset from the beginning of the document
  48. * that this element begins at. If this element has
  49. * children, this will be the offset of the first child.
  50. *
  51. * @return the starting offset >= 0
  52. */
  53. public int getStartOffset();
  54. /**
  55. * Fetches the offset from the beginning of the document
  56. * that this element ends at. If this element has
  57. * children, this will be the end offset of the last child.
  58. * <p>
  59. * All the default Document implementations descend from AbstractDocument.
  60. * AbstractDocument models an implied break at the end of
  61. * the document. As a result of this, it is possible for this to
  62. * return a value greater than the length of the document.
  63. *
  64. * @return the ending offset >= 0
  65. * @see AbstractDocument
  66. */
  67. public int getEndOffset();
  68. /**
  69. * Gets the child element index closest to the given offset.
  70. * The offset is specified relative to the begining of the
  71. * document.
  72. *
  73. * @param offset the specified offset >= 0
  74. * @return the element index >= 0
  75. */
  76. public int getElementIndex(int offset);
  77. /**
  78. * Gets the number of child elements contained by this element.
  79. * If this element is a leaf, a count of zero is returned.
  80. *
  81. * @return the number of child elements >= 0
  82. */
  83. public int getElementCount();
  84. /**
  85. * Fetches the child element at the given index.
  86. *
  87. * @param index the specified index >= 0
  88. * @return the child element
  89. */
  90. public Element getElement(int index);
  91. /**
  92. * Is this element a leaf element?
  93. *
  94. * @return true if a leaf element else false
  95. */
  96. public boolean isLeaf();
  97. }