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