1. /*
  2. * @(#)AttributeSet.java 1.27 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text;
  8. import java.util.Enumeration;
  9. /**
  10. * A collection of unique attributes. This is a read-only,
  11. * immutable interface. An attribute is basically a key and
  12. * a value assigned to the key. The collection may represent
  13. * something like a style run, a logical style, etc. These
  14. * are generally used to describe features that will contribute
  15. * to some graphical representation such as a font. The
  16. * set of possible keys is unbounded and can be anything.
  17. * Typically View implementations will respond to attribute
  18. * definitions and render something to represent the attributes.
  19. * <p>
  20. * Attributes can potentially resolve in a hierarchy. If a
  21. * key doesn't resolve locally, and a resolving parent
  22. * exists, the key will be resolved through the parent.
  23. *
  24. * @author Timothy Prinzing
  25. * @version 1.27 11/29/01
  26. * @see MutableAttributeSet
  27. * @see AttributeCharacterIterator
  28. */
  29. public interface AttributeSet {
  30. /**
  31. * This interface is the type signature that is expected
  32. * to be present on any attribute key that contributes to
  33. * the determination of what font to use to render some
  34. * text. This is not considered to be a closed set, the
  35. * definition can change across version of the JDK and can
  36. * be ammended by additional user added entries that
  37. * correspond to logical settings that are specific to
  38. * some type of content.
  39. */
  40. public interface FontAttribute {
  41. }
  42. /**
  43. * This interface is the type signature that is expected
  44. * to be present on any attribute key that contributes to
  45. * presentation of color.
  46. */
  47. public interface ColorAttribute {
  48. }
  49. /**
  50. * This interface is the type signature that is expected
  51. * to be present on any attribute key that contributes to
  52. * character level presentation. This would be any attribute
  53. * that applies to a so-called <term>run</term> of
  54. * style.
  55. */
  56. public interface CharacterAttribute {
  57. }
  58. /**
  59. * This interface is the type signature that is expected
  60. * to be present on any attribute key that contributes to
  61. * the paragraph level presentation.
  62. */
  63. public interface ParagraphAttribute {
  64. }
  65. /**
  66. * Returns the number of attributes contained in this set.
  67. *
  68. * @return the number of attributes >= 0
  69. */
  70. public int getAttributeCount();
  71. /**
  72. * Checks whether the named attribute has a value specified in
  73. * the set without resolving through another attribute
  74. * set.
  75. *
  76. * @param attrName the attribute name
  77. * @return true if the attribute has a value specified
  78. */
  79. public boolean isDefined(Object attrName);
  80. /**
  81. * Determines if the two attribute sets are equivalent.
  82. *
  83. * @param attr an attribute set
  84. * @return true if the sets are equivalent
  85. */
  86. public boolean isEqual(AttributeSet attr);
  87. /**
  88. * Returns an attribute set that is guaranteed not
  89. * to change over time.
  90. *
  91. * @return a copy of the attribute set
  92. */
  93. public AttributeSet copyAttributes();
  94. /**
  95. * Fetches the value of the given attribute. If the value is not found
  96. * locally, the search is continued upward through the resolving
  97. * parent (if one exists) until the value is either
  98. * found or there are no more parents. If the value is not found,
  99. * null is returned.
  100. *
  101. * @param key the non-null key of the attribute binding
  102. * @return the value
  103. */
  104. public Object getAttribute(Object key);
  105. /**
  106. * Returns an enumeration over the names of the attributes in the set.
  107. * The elements of the enumeration are all Strings. The set does
  108. * not include the resolving parent, if one is defined.
  109. *
  110. * @return the names
  111. */
  112. public Enumeration getAttributeNames();
  113. /**
  114. * Returns true if this set contains this attribute with an equal value.
  115. *
  116. * @param name the non-null attribute name
  117. * @param value the value
  118. * @return true if the set contains the attribute with an equal value
  119. */
  120. public boolean containsAttribute(Object name, Object value);
  121. /**
  122. * Returns true if this set contains all the attributes with equal values.
  123. *
  124. * @param attributes the set of attributes to check against
  125. * @return true if this set contains all the attributes with equal values
  126. */
  127. public boolean containsAttributes(AttributeSet attributes);
  128. /**
  129. * Gets the resolving parent.
  130. *
  131. * @return the parent
  132. */
  133. public AttributeSet getResolveParent();
  134. /**
  135. * Attribute name used to name the collection of
  136. * attributes.
  137. */
  138. public static final Object NameAttribute = StyleConstants.NameAttribute;
  139. /**
  140. * Attribute name used to identifiy the resolving parent
  141. * set of attributes, if one is defined.
  142. */
  143. public static final Object ResolveAttribute = StyleConstants.ResolveAttribute;
  144. }