KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > rtf > MockAttributeSet


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
9 import java.util.Dictionary JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import javax.swing.text.AttributeSet JavaDoc;
12 import javax.swing.text.MutableAttributeSet JavaDoc;
13
14
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 JavaDoc, MutableAttributeSet JavaDoc
19 {
20     public Dictionary JavaDoc backing;
21
22     public boolean isEmpty()
23     {
24          return backing.isEmpty();
25     }
26     
27     public int getAttributeCount()
28     {
29          return backing.size();
30     }
31
32     public boolean isDefined(Object JavaDoc name)
33     {
34          return ( backing.get(name) ) != null;
35     }
36
37     public boolean isEqual(AttributeSet JavaDoc attr)
38     {
39          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
40     }
41
42     public AttributeSet JavaDoc copyAttributes()
43     {
44          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
45     }
46     
47     public Object JavaDoc getAttribute(Object JavaDoc name)
48     {
49         return backing.get(name);
50     }
51
52     public void addAttribute(Object JavaDoc name, Object JavaDoc value)
53     {
54         backing.put(name, value);
55     }
56     
57     public void addAttributes(AttributeSet JavaDoc attr)
58     {
59         Enumeration JavaDoc as = attr.getAttributeNames();
60     while(as.hasMoreElements()) {
61         Object JavaDoc el = as.nextElement();
62         backing.put(el, attr.getAttribute(el));
63     }
64     }
65
66     public void removeAttribute(Object JavaDoc name)
67     {
68         backing.remove(name);
69     }
70
71     public void removeAttributes(AttributeSet JavaDoc attr)
72     {
73          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
74     }
75
76     public void removeAttributes(Enumeration JavaDoc<?> en)
77     {
78          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
79     }
80
81     public void setResolveParent(AttributeSet JavaDoc pp)
82     {
83          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
84     }
85
86     
87     public Enumeration JavaDoc getAttributeNames()
88     {
89          return backing.keys();
90     }
91     
92     public boolean containsAttribute(Object JavaDoc name, Object JavaDoc value)
93     {
94          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
95     }
96
97     public boolean containsAttributes(AttributeSet JavaDoc attr)
98     {
99          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
100     }
101
102     public AttributeSet JavaDoc getResolveParent()
103     {
104          throw new InternalError JavaDoc("MockAttributeSet: charade revealed!");
105     }
106 }
107     
108     
109
Popular Tags