1. /*
  2. * @(#)AttributeSet.java 1.40 04/05/05
  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. 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.40 05/05/04
  26. * @see MutableAttributeSet
  27. */
  28. public interface AttributeSet {
  29. /**
  30. * This interface is the type signature that is expected
  31. * to be present on any attribute key that contributes to
  32. * the determination of what font to use to render some
  33. * text. This is not considered to be a closed set, the
  34. * definition can change across version of the platform and can
  35. * be amended by additional user added entries that
  36. * correspond to logical settings that are specific to
  37. * some type of content.
  38. */
  39. public interface FontAttribute {
  40. }
  41. /**
  42. * This interface is the type signature that is expected
  43. * to be present on any attribute key that contributes to
  44. * presentation of color.
  45. */
  46. public interface ColorAttribute {
  47. }
  48. /**
  49. * This interface is the type signature that is expected
  50. * to be present on any attribute key that contributes to
  51. * character level presentation. This would be any attribute
  52. * that applies to a so-called <term>run</term> of
  53. * style.
  54. */
  55. public interface CharacterAttribute {
  56. }
  57. /**
  58. * This interface is the type signature that is expected
  59. * to be present on any attribute key that contributes to
  60. * the paragraph level presentation.
  61. */
  62. public interface ParagraphAttribute {
  63. }
  64. /**
  65. * Returns the number of attributes contained in this set.
  66. *
  67. * @return the number of attributes >= 0
  68. */
  69. public int getAttributeCount();
  70. /**
  71. * Checks whether the named attribute has a value specified in
  72. * the set without resolving through another attribute
  73. * set.
  74. *
  75. * @param attrName the attribute name
  76. * @return true if the attribute has a value specified
  77. */
  78. public boolean isDefined(Object attrName);
  79. /**
  80. * Determines if the two attribute sets are equivalent.
  81. *
  82. * @param attr an attribute set
  83. * @return true if the sets are equivalent
  84. */
  85. public boolean isEqual(AttributeSet attr);
  86. /**
  87. * Returns an attribute set that is guaranteed not
  88. * to change over time.
  89. *
  90. * @return a copy of the attribute set
  91. */
  92. public AttributeSet copyAttributes();
  93. /**
  94. * Fetches the value of the given attribute. If the value is not found
  95. * locally, the search is continued upward through the resolving
  96. * parent (if one exists) until the value is either
  97. * found or there are no more parents. If the value is not found,
  98. * null is returned.
  99. *
  100. * @param key the non-null key of the attribute binding
  101. * @return the value
  102. */
  103. public Object getAttribute(Object key);
  104. /**
  105. * Returns an enumeration over the names of the attributes in the set.
  106. * The values of the <code>Enumeration</code> may be anything
  107. * and are not constrained to a particular <code>Object</code> type.
  108. * The set does 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 identify the resolving parent
  141. * set of attributes, if one is defined.
  142. */
  143. public static final Object ResolveAttribute = StyleConstants.ResolveAttribute;
  144. }