38 |
|
|
39 |
package javax.swing.text.html; |
package javax.swing.text.html; |
40 |
|
|
41 |
|
import javax.swing.text.AttributeSet; |
42 |
import javax.swing.text.DefaultStyledDocument; |
import javax.swing.text.DefaultStyledDocument; |
43 |
|
import javax.swing.text.ElementIterator; |
44 |
|
import javax.swing.text.html.HTML.Tag; |
45 |
|
|
46 |
/** |
/** |
47 |
* TODO: This class is not yet completetely implemented. |
* TODO: This class is not yet completetely implemented. |
50 |
*/ |
*/ |
51 |
public class HTMLDocument extends DefaultStyledDocument |
public class HTMLDocument extends DefaultStyledDocument |
52 |
{ |
{ |
53 |
|
|
54 |
|
/** |
55 |
|
* An iterator to iterate through LeafElements in the document. |
56 |
|
*/ |
57 |
|
class LeafIterator extends Iterator |
58 |
|
{ |
59 |
|
HTML.Tag tag; |
60 |
|
HTMLDocument doc; |
61 |
|
ElementIterator it; |
62 |
|
|
63 |
|
public LeafIterator (HTML.Tag t, HTMLDocument d) |
64 |
|
{ |
65 |
|
doc = d; |
66 |
|
tag = t; |
67 |
|
it = new ElementIterator(doc); |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
|
* Return the attributes for the tag associated with this iteartor |
72 |
|
* @return the AttributeSet |
73 |
|
*/ |
74 |
|
public AttributeSet getAttributes() |
75 |
|
{ |
76 |
|
if (it.current() != null) |
77 |
|
return it.current().getAttributes(); |
78 |
|
return null; |
79 |
|
} |
80 |
|
|
81 |
|
/** |
82 |
|
* Get the end of the range for the current occurrence of the tag |
83 |
|
* being defined and having the same attributes. |
84 |
|
* @return the end of the range |
85 |
|
*/ |
86 |
|
public int getEndOffset() |
87 |
|
{ |
88 |
|
if (it.current() != null) |
89 |
|
return it.current().getEndOffset(); |
90 |
|
return -1; |
91 |
|
} |
92 |
|
|
93 |
|
/** |
94 |
|
* Get the start of the range for the current occurrence of the tag |
95 |
|
* being defined and having the same attributes. |
96 |
|
* @return the start of the range (-1 if it can't be found). |
97 |
|
*/ |
98 |
|
|
99 |
|
public int getStartOffset() |
100 |
|
{ |
101 |
|
if (it.current() != null) |
102 |
|
return it.current().getStartOffset(); |
103 |
|
return -1; |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
|
* Advance the iterator to the next LeafElement . |
108 |
|
*/ |
109 |
|
public void next() |
110 |
|
{ |
111 |
|
it.next(); |
112 |
|
while (it.current()!= null && !it.current().isLeaf()) |
113 |
|
it.next(); |
114 |
|
} |
115 |
|
|
116 |
|
/** |
117 |
|
* Indicates whether or not the iterator currently represents an occurrence |
118 |
|
* of the tag. |
119 |
|
* @return true if the iterator currently represents an occurrence of the |
120 |
|
* tag. |
121 |
|
*/ |
122 |
|
public boolean isValid() |
123 |
|
{ |
124 |
|
return it.current() != null; |
125 |
|
} |
126 |
|
|
127 |
|
/** |
128 |
|
* Type of tag for this iterator. |
129 |
|
*/ |
130 |
|
public Tag getTag() |
131 |
|
{ |
132 |
|
return tag; |
133 |
|
} |
134 |
|
|
135 |
|
} |
136 |
|
|
137 |
public void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent event) |
public void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent event) |
138 |
{ |
{ |
139 |
} |
} |
140 |
|
|
141 |
|
/** |
142 |
|
* Gets an iterator for the given HTML.Tag. |
143 |
|
* @param t the requested HTML.Tag |
144 |
|
* @return the Iterator |
145 |
|
*/ |
146 |
|
public HTMLDocument.Iterator getIterator (HTML.Tag t) |
147 |
|
{ |
148 |
|
return new HTMLDocument.LeafIterator(t, this); |
149 |
|
} |
150 |
|
|
151 |
|
/** |
152 |
|
* An iterator over a particular type of tag. |
153 |
|
*/ |
154 |
|
public abstract static class Iterator |
155 |
|
{ |
156 |
|
/** |
157 |
|
* Return the attribute set for this tag. |
158 |
|
* @return the <code>AttributeSet</code> (null if none found). |
159 |
|
*/ |
160 |
|
public abstract AttributeSet getAttributes(); |
161 |
|
|
162 |
|
/** |
163 |
|
* Get the end of the range for the current occurrence of the tag |
164 |
|
* being defined and having the same attributes. |
165 |
|
* @return the end of the range |
166 |
|
*/ |
167 |
|
public abstract int getEndOffset(); |
168 |
|
|
169 |
|
/** |
170 |
|
* Get the start of the range for the current occurrence of the tag |
171 |
|
* being defined and having the same attributes. |
172 |
|
* @return the start of the range (-1 if it can't be found). |
173 |
|
*/ |
174 |
|
public abstract int getStartOffset(); |
175 |
|
|
176 |
|
/** |
177 |
|
* Move the iterator forward. |
178 |
|
*/ |
179 |
|
public abstract void next(); |
180 |
|
|
181 |
|
/** |
182 |
|
* Indicates whether or not the iterator currently represents an occurrence |
183 |
|
* of the tag. |
184 |
|
* @return true if the iterator currently represents an occurrence of the |
185 |
|
* tag. |
186 |
|
*/ |
187 |
|
public abstract boolean isValid(); |
188 |
|
|
189 |
|
/** |
190 |
|
* Type of tag this iterator represents. |
191 |
|
* @return the tag. |
192 |
|
*/ |
193 |
|
public abstract HTML.Tag getTag(); |
194 |
|
} |
195 |
} |
} |