1. /*
  2. * @(#)StyledDocument.java 1.18 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. import java.awt.Font;
  12. import java.awt.Color;
  13. /**
  14. * Interface for a generic styled document.
  15. *
  16. * @author Timothy Prinzing
  17. * @version 1.18 02/02/00
  18. */
  19. public interface StyledDocument extends Document {
  20. /**
  21. * Adds a new style into the logical style hierarchy. Style attributes
  22. * resolve from bottom up so an attribute specified in a child
  23. * will override an attribute specified in the parent.
  24. *
  25. * @param nm the name of the style (must be unique within the
  26. * collection of named styles). The name may be null if the style
  27. * is unnamed, but the caller is responsible
  28. * for managing the reference returned as an unnamed style can't
  29. * be fetched by name. An unnamed style may be useful for things
  30. * like character attribute overrides such as found in a style
  31. * run.
  32. * @param parent the parent style. This may be null if unspecified
  33. * attributes need not be resolved in some other style.
  34. * @return the style
  35. */
  36. public Style addStyle(String nm, Style parent);
  37. /**
  38. * Removes a named style previously added to the document.
  39. *
  40. * @param nm the name of the style to remove
  41. */
  42. public void removeStyle(String nm);
  43. /**
  44. * Fetches a named style previously added.
  45. *
  46. * @param nm the name of the style
  47. * @return the style
  48. */
  49. public Style getStyle(String nm);
  50. /**
  51. * Changes the content element attributes used for the given range of
  52. * existing content in the document. All of the attributes
  53. * defined in the given Attributes argument are applied to the
  54. * given range. This method can be used to completely remove
  55. * all content level attributes for the given range by
  56. * giving an Attributes argument that has no attributes defined
  57. * and setting replace to true.
  58. *
  59. * @param offset the start of the change >= 0
  60. * @param length the length of the change >= 0
  61. * @param s the non-null attributes to change to. Any attributes
  62. * defined will be applied to the text for the given range.
  63. * @param replace indicates whether or not the previous
  64. * attributes should be cleared before the new attributes
  65. * as set. If true, the operation will replace the
  66. * previous attributes entirely. If false, the new
  67. * attributes will be merged with the previous attributes.
  68. */
  69. public void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace);
  70. /**
  71. * Sets paragraph attributes.
  72. *
  73. * @param offset the start of the change >= 0
  74. * @param length the length of the change >= 0
  75. * @param s the non-null attributes to change to. Any attributes
  76. * defined will be applied to the text for the given range.
  77. * @param replace indicates whether or not the previous
  78. * attributes should be cleared before the new attributes
  79. * are set. If true, the operation will replace the
  80. * previous attributes entirely. If false, the new
  81. * attributes will be merged with the previous attributes.
  82. */
  83. public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace);
  84. /**
  85. * Sets the logical style to use for the paragraph at the
  86. * given position. If attributes aren't explicitly set
  87. * for character and paragraph attributes they will resolve
  88. * through the logical style assigned to the paragraph, which
  89. * in turn may resolve through some hierarchy completely
  90. * independent of the element hierarchy in the document.
  91. *
  92. * @param pos the starting position >= 0
  93. * @param s the style to set
  94. */
  95. public void setLogicalStyle(int pos, Style s);
  96. /**
  97. * Gets a logical style for a given position in a paragraph.
  98. *
  99. * @param p the position >= 0
  100. * @return the style
  101. */
  102. public Style getLogicalStyle(int p);
  103. /**
  104. * Gets the element that represents the paragraph that
  105. * encloses the given offset within the document.
  106. *
  107. * @param pos the offset >= 0
  108. * @return the element
  109. */
  110. public Element getParagraphElement(int pos);
  111. /**
  112. * Gets the element that represents the character that
  113. * is at the given offset within the document.
  114. *
  115. * @param pos the offset >= 0
  116. * @return the element
  117. */
  118. public Element getCharacterElement(int pos);
  119. /**
  120. * Takes a set of attributes and turn it into a foreground color
  121. * specification. This might be used to specify things
  122. * like brighter, more hue, etc.
  123. *
  124. * @param attr the set of attributes
  125. * @return the color
  126. */
  127. public Color getForeground(AttributeSet attr);
  128. /**
  129. * Takes a set of attributes and turn it into a background color
  130. * specification. This might be used to specify things
  131. * like brighter, more hue, etc.
  132. *
  133. * @param attr the set of attributes
  134. * @return the color
  135. */
  136. public Color getBackground(AttributeSet attr);
  137. /**
  138. * Takes a set of attributes and turn it into a font
  139. * specification. This can be used to turn things like
  140. * family, style, size, etc into a font that is available
  141. * on the system the document is currently being used on.
  142. *
  143. * @param attr the set of attributes
  144. * @return the font
  145. */
  146. public Font getFont(AttributeSet attr);
  147. }