1. /*
  2. * @(#)MockAttributeSet.java 1.7 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.rtf;
  11. import java.util.Dictionary;
  12. import java.util.Enumeration;
  13. import javax.swing.text.AttributeSet;
  14. import javax.swing.text.MutableAttributeSet;
  15. /* This AttributeSet is made entirely out of tofu and Ritz Crackers
  16. and yet has a remarkably attribute-set-like interface! */
  17. class MockAttributeSet
  18. implements AttributeSet, MutableAttributeSet
  19. {
  20. public Dictionary backing;
  21. public boolean isEmpty()
  22. {
  23. return backing.isEmpty();
  24. }
  25. public int getAttributeCount()
  26. {
  27. return backing.size();
  28. }
  29. public boolean isDefined(Object name)
  30. {
  31. return ( backing.get(name) ) != null;
  32. }
  33. public boolean isEqual(AttributeSet attr)
  34. {
  35. throw new InternalError("MockAttributeSet: charade revealed!");
  36. }
  37. public AttributeSet copyAttributes()
  38. {
  39. throw new InternalError("MockAttributeSet: charade revealed!");
  40. }
  41. public Object getAttribute(Object name)
  42. {
  43. return backing.get(name);
  44. }
  45. public void addAttribute(Object name, Object value)
  46. {
  47. backing.put(name, value);
  48. }
  49. public void addAttributes(AttributeSet attr)
  50. {
  51. Enumeration as = attr.getAttributeNames();
  52. while(as.hasMoreElements()) {
  53. Object el = as.nextElement();
  54. backing.put(el, attr.getAttribute(el));
  55. }
  56. }
  57. public void removeAttribute(Object name)
  58. {
  59. backing.remove(name);
  60. }
  61. public void removeAttributes(AttributeSet attr)
  62. {
  63. throw new InternalError("MockAttributeSet: charade revealed!");
  64. }
  65. public void removeAttributes(Enumeration en)
  66. {
  67. throw new InternalError("MockAttributeSet: charade revealed!");
  68. }
  69. public void setResolveParent(AttributeSet pp)
  70. {
  71. throw new InternalError("MockAttributeSet: charade revealed!");
  72. }
  73. public Enumeration getAttributeNames()
  74. {
  75. return backing.keys();
  76. }
  77. public boolean containsAttribute(Object name, Object value)
  78. {
  79. throw new InternalError("MockAttributeSet: charade revealed!");
  80. }
  81. public boolean containsAttributes(AttributeSet attr)
  82. {
  83. throw new InternalError("MockAttributeSet: charade revealed!");
  84. }
  85. public AttributeSet getResolveParent()
  86. {
  87. throw new InternalError("MockAttributeSet: charade revealed!");
  88. }
  89. }