2117 * with it. 2118 * <dt>Hidden 2119 * <dd>Create an element that is hidden from view when the 2120 * document is being viewed read-only, and visible when the 2121 * document is being edited. This is useful to keep the 2122 * model from losing information, and used to store things 2123 * like comments and unrecognized tags. 2124 * 2125 * </dl> 2126 * <p> 2127 * Currently, <APPLET>, <PARAM>, <MAP>, <AREA>, <LINK>, 2128 * <SCRIPT> and <STYLE> are unsupported. 2129 * 2130 * <p> 2131 * The assignment of the actions described is shown in the 2132 * following table for the tags defined in <code>HTML.Tag</code>. 2133 * 2134 * <table class="striped"> 2135 * <caption>HTML tags and assigned actions</caption> 2136 * <thead> 2137 * <tr><th>Tag</th><th>Action</th></tr> 2138 * </thead> 2139 * <tbody> 2140 * <tr><td><code>HTML.Tag.A</code> <td>CharacterAction 2141 * <tr><td><code>HTML.Tag.ADDRESS</code> <td>CharacterAction 2142 * <tr><td><code>HTML.Tag.APPLET</code> <td>HiddenAction 2143 * <tr><td><code>HTML.Tag.AREA</code> <td>AreaAction 2144 * <tr><td><code>HTML.Tag.B</code> <td>CharacterAction 2145 * <tr><td><code>HTML.Tag.BASE</code> <td>BaseAction 2146 * <tr><td><code>HTML.Tag.BASEFONT</code> <td>CharacterAction 2147 * <tr><td><code>HTML.Tag.BIG</code> <td>CharacterAction 2148 * <tr><td><code>HTML.Tag.BLOCKQUOTE</code><td>BlockAction 2149 * <tr><td><code>HTML.Tag.BODY</code> <td>BlockAction 2150 * <tr><td><code>HTML.Tag.BR</code> <td>SpecialAction 2151 * <tr><td><code>HTML.Tag.CAPTION</code> <td>BlockAction 2152 * <tr><td><code>HTML.Tag.CENTER</code> <td>BlockAction 2153 * <tr><td><code>HTML.Tag.CITE</code> <td>CharacterAction 2154 * <tr><td><code>HTML.Tag.CODE</code> <td>CharacterAction 2155 * <tr><td><code>HTML.Tag.DD</code> <td>BlockAction 2156 * <tr><td><code>HTML.Tag.DFN</code> <td>CharacterAction 2157 * <tr><td><code>HTML.Tag.DIR</code> <td>BlockAction 2158 * <tr><td><code>HTML.Tag.DIV</code> <td>BlockAction 2159 * <tr><td><code>HTML.Tag.DL</code> <td>BlockAction 2160 * <tr><td><code>HTML.Tag.DT</code> <td>ParagraphAction 2161 * <tr><td><code>HTML.Tag.EM</code> <td>CharacterAction 2162 * <tr><td><code>HTML.Tag.FONT</code> <td>CharacterAction 2163 * <tr><td><code>HTML.Tag.FORM</code> <td>As of 1.4 a BlockAction 2164 * <tr><td><code>HTML.Tag.FRAME</code> <td>SpecialAction 2165 * <tr><td><code>HTML.Tag.FRAMESET</code> <td>BlockAction 2166 * <tr><td><code>HTML.Tag.H1</code> <td>ParagraphAction 2167 * <tr><td><code>HTML.Tag.H2</code> <td>ParagraphAction 2168 * <tr><td><code>HTML.Tag.H3</code> <td>ParagraphAction 2169 * <tr><td><code>HTML.Tag.H4</code> <td>ParagraphAction 2170 * <tr><td><code>HTML.Tag.H5</code> <td>ParagraphAction 2171 * <tr><td><code>HTML.Tag.H6</code> <td>ParagraphAction 2172 * <tr><td><code>HTML.Tag.HEAD</code> <td>HeadAction 2173 * <tr><td><code>HTML.Tag.HR</code> <td>SpecialAction 2174 * <tr><td><code>HTML.Tag.HTML</code> <td>BlockAction 2175 * <tr><td><code>HTML.Tag.I</code> <td>CharacterAction 2176 * <tr><td><code>HTML.Tag.IMG</code> <td>SpecialAction 2177 * <tr><td><code>HTML.Tag.INPUT</code> <td>FormAction 2178 * <tr><td><code>HTML.Tag.ISINDEX</code> <td>IsndexAction 2179 * <tr><td><code>HTML.Tag.KBD</code> <td>CharacterAction 2180 * <tr><td><code>HTML.Tag.LI</code> <td>BlockAction 2181 * <tr><td><code>HTML.Tag.LINK</code> <td>LinkAction 2182 * <tr><td><code>HTML.Tag.MAP</code> <td>MapAction 2183 * <tr><td><code>HTML.Tag.MENU</code> <td>BlockAction 2184 * <tr><td><code>HTML.Tag.META</code> <td>MetaAction 2185 * <tr><td><code>HTML.Tag.NOFRAMES</code> <td>BlockAction 2186 * <tr><td><code>HTML.Tag.OBJECT</code> <td>SpecialAction 2187 * <tr><td><code>HTML.Tag.OL</code> <td>BlockAction 2188 * <tr><td><code>HTML.Tag.OPTION</code> <td>FormAction 2189 * <tr><td><code>HTML.Tag.P</code> <td>ParagraphAction 2190 * <tr><td><code>HTML.Tag.PARAM</code> <td>HiddenAction 2191 * <tr><td><code>HTML.Tag.PRE</code> <td>PreAction 2192 * <tr><td><code>HTML.Tag.SAMP</code> <td>CharacterAction 2193 * <tr><td><code>HTML.Tag.SCRIPT</code> <td>HiddenAction 2194 * <tr><td><code>HTML.Tag.SELECT</code> <td>FormAction 2195 * <tr><td><code>HTML.Tag.SMALL</code> <td>CharacterAction 2196 * <tr><td><code>HTML.Tag.STRIKE</code> <td>CharacterAction 2197 * <tr><td><code>HTML.Tag.S</code> <td>CharacterAction 2198 * <tr><td><code>HTML.Tag.STRONG</code> <td>CharacterAction 2199 * <tr><td><code>HTML.Tag.STYLE</code> <td>StyleAction 2200 * <tr><td><code>HTML.Tag.SUB</code> <td>CharacterAction 2201 * <tr><td><code>HTML.Tag.SUP</code> <td>CharacterAction 2202 * <tr><td><code>HTML.Tag.TABLE</code> <td>BlockAction 2203 * <tr><td><code>HTML.Tag.TD</code> <td>BlockAction 2204 * <tr><td><code>HTML.Tag.TEXTAREA</code> <td>FormAction 2205 * <tr><td><code>HTML.Tag.TH</code> <td>BlockAction 2206 * <tr><td><code>HTML.Tag.TITLE</code> <td>TitleAction 2207 * <tr><td><code>HTML.Tag.TR</code> <td>BlockAction 2208 * <tr><td><code>HTML.Tag.TT</code> <td>CharacterAction 2209 * <tr><td><code>HTML.Tag.U</code> <td>CharacterAction 2210 * <tr><td><code>HTML.Tag.UL</code> <td>BlockAction 2211 * <tr><td><code>HTML.Tag.VAR</code> <td>CharacterAction 2212 * </tbody> 2213 * </table> 2214 * <p> 2215 * Once </html> is encountered, the Actions are no longer notified. 2216 */ 2217 public class HTMLReader extends HTMLEditorKit.ParserCallback { 2218 2219 /** 2220 * Constructs an HTMLReader using default pop and push depth and no tag to insert. 2221 * 2222 * @param offset the starting offset 2223 */ 2224 public HTMLReader(int offset) { 2225 this(offset, 0, 0, null); 2226 } 2227 2228 /** 2229 * Constructs an HTMLReader. 2230 * 2231 * @param offset the starting offset 3381 } 3382 3383 /** 3384 * Action to support forms by building all of the elements 3385 * used to represent form controls. This will process 3386 * the <INPUT>, <TEXTAREA>, <SELECT>, 3387 * and <OPTION> tags. The element created by 3388 * this action is expected to have the attribute 3389 * <code>StyleConstants.ModelAttribute</code> set to 3390 * the model that holds the state for the form control. 3391 * This enables multiple views, and allows document to 3392 * be iterated over picking up the data of the form. 3393 * The following are the model assignments for the 3394 * various type of form elements. 3395 * 3396 * <table class="striped"> 3397 * <caption>Model assignments for the various types of form elements 3398 * </caption> 3399 * <thead> 3400 * <tr> 3401 * <th>Element Type 3402 * <th>Model Type 3403 * </tr> 3404 * </thead> 3405 * <tbody> 3406 * <tr> 3407 * <td>input, type button 3408 * <td>{@link DefaultButtonModel} 3409 * <tr> 3410 * <td>input, type checkbox 3411 * <td>{@link javax.swing.JToggleButton.ToggleButtonModel} 3412 * <tr> 3413 * <td>input, type image 3414 * <td>{@link DefaultButtonModel} 3415 * <tr> 3416 * <td>input, type password 3417 * <td>{@link PlainDocument} 3418 * <tr> 3419 * <td>input, type radio 3420 * <td>{@link javax.swing.JToggleButton.ToggleButtonModel} 3421 * <tr> 3422 * <td>input, type reset 3423 * <td>{@link DefaultButtonModel} 3424 * <tr> 3425 * <td>input, type submit 3426 * <td>{@link DefaultButtonModel} 3427 * <tr> 3428 * <td>input, type text or type is null. 3429 * <td>{@link PlainDocument} 3430 * <tr> 3431 * <td>select 3432 * <td>{@link DefaultComboBoxModel} or an {@link DefaultListModel}, with an item type of Option 3433 * <tr> 3434 * <td>textarea 3435 * <td>{@link PlainDocument} 3436 * </tbody> 3437 * </table> 3438 * 3439 */ 3440 public class FormAction extends SpecialAction { 3441 3442 public void start(HTML.Tag t, MutableAttributeSet attr) { 3443 if (t == HTML.Tag.INPUT) { 3444 String type = (String) 3445 attr.getAttribute(HTML.Attribute.TYPE); 3446 /* 3447 * if type is not defined the default is 3448 * assumed to be text. 3449 */ 3450 if (type == null) { 3451 type = "text"; 3452 attr.addAttribute(HTML.Attribute.TYPE, "text"); 3453 } 3454 setModel(type, attr); 3455 } else if (t == HTML.Tag.TEXTAREA) { 3456 inTextArea = true; 3457 textAreaDocument = new TextAreaDocument(); 3458 attr.addAttribute(StyleConstants.ModelAttribute, | 2117 * with it. 2118 * <dt>Hidden 2119 * <dd>Create an element that is hidden from view when the 2120 * document is being viewed read-only, and visible when the 2121 * document is being edited. This is useful to keep the 2122 * model from losing information, and used to store things 2123 * like comments and unrecognized tags. 2124 * 2125 * </dl> 2126 * <p> 2127 * Currently, <APPLET>, <PARAM>, <MAP>, <AREA>, <LINK>, 2128 * <SCRIPT> and <STYLE> are unsupported. 2129 * 2130 * <p> 2131 * The assignment of the actions described is shown in the 2132 * following table for the tags defined in <code>HTML.Tag</code>. 2133 * 2134 * <table class="striped"> 2135 * <caption>HTML tags and assigned actions</caption> 2136 * <thead> 2137 * <tr> 2138 * <th scope="col">Tag 2139 * <th scope="col">Action 2140 * </thead> 2141 * <tbody> 2142 * <tr> 2143 * <th scope="row">{@code HTML.Tag.A} 2144 * <td>CharacterAction 2145 * <tr> 2146 * <th scope="row">{@code HTML.Tag.ADDRESS} 2147 * <td>CharacterAction 2148 * <tr> 2149 * <th scope="row">{@code HTML.Tag.APPLET} 2150 * <td>HiddenAction 2151 * <tr> 2152 * <th scope="row">{@code HTML.Tag.AREA} 2153 * <td>AreaAction 2154 * <tr> 2155 * <th scope="row">{@code HTML.Tag.B} 2156 * <td>CharacterAction 2157 * <tr> 2158 * <th scope="row">{@code HTML.Tag.BASE} 2159 * <td>BaseAction 2160 * <tr> 2161 * <th scope="row">{@code HTML.Tag.BASEFONT} 2162 * <td>CharacterAction 2163 * <tr> 2164 * <th scope="row">{@code HTML.Tag.BIG} 2165 * <td>CharacterAction 2166 * <tr> 2167 * <th scope="row">{@code HTML.Tag.BLOCKQUOTE} 2168 * <td>BlockAction 2169 * <tr> 2170 * <th scope="row">{@code HTML.Tag.BODY} 2171 * <td>BlockAction 2172 * <tr> 2173 * <th scope="row">{@code HTML.Tag.BR} 2174 * <td>SpecialAction 2175 * <tr> 2176 * <th scope="row">{@code HTML.Tag.CAPTION} 2177 * <td>BlockAction 2178 * <tr> 2179 * <th scope="row">{@code HTML.Tag.CENTER} 2180 * <td>BlockAction 2181 * <tr> 2182 * <th scope="row">{@code HTML.Tag.CITE} 2183 * <td>CharacterAction 2184 * <tr> 2185 * <th scope="row">{@code HTML.Tag.CODE} 2186 * <td>CharacterAction 2187 * <tr> 2188 * <th scope="row">{@code HTML.Tag.DD} 2189 * <td>BlockAction 2190 * <tr> 2191 * <th scope="row">{@code HTML.Tag.DFN} 2192 * <td>CharacterAction 2193 * <tr> 2194 * <th scope="row">{@code HTML.Tag.DIR} 2195 * <td>BlockAction 2196 * <tr> 2197 * <th scope="row">{@code HTML.Tag.DIV} 2198 * <td>BlockAction 2199 * <tr> 2200 * <th scope="row">{@code HTML.Tag.DL} 2201 * <td>BlockAction 2202 * <tr> 2203 * <th scope="row">{@code HTML.Tag.DT} 2204 * <td>ParagraphAction 2205 * <tr> 2206 * <th scope="row">{@code HTML.Tag.EM} 2207 * <td>CharacterAction 2208 * <tr> 2209 * <th scope="row">{@code HTML.Tag.FONT} 2210 * <td>CharacterAction 2211 * <tr> 2212 * <th scope="row">{@code HTML.Tag.FORM} 2213 * <td>As of 1.4 a BlockAction 2214 * <tr> 2215 * <th scope="row">{@code HTML.Tag.FRAME} 2216 * <td>SpecialAction 2217 * <tr> 2218 * <th scope="row">{@code HTML.Tag.FRAMESET} 2219 * <td>BlockAction 2220 * <tr> 2221 * <th scope="row">{@code HTML.Tag.H1} 2222 * <td>ParagraphAction 2223 * <tr> 2224 * <th scope="row">{@code HTML.Tag.H2} 2225 * <td>ParagraphAction 2226 * <tr> 2227 * <th scope="row">{@code HTML.Tag.H3} 2228 * <td>ParagraphAction 2229 * <tr> 2230 * <th scope="row">{@code HTML.Tag.H4} 2231 * <td>ParagraphAction 2232 * <tr> 2233 * <th scope="row">{@code HTML.Tag.H5} 2234 * <td>ParagraphAction 2235 * <tr> 2236 * <th scope="row">{@code HTML.Tag.H6} 2237 * <td>ParagraphAction 2238 * <tr> 2239 * <th scope="row">{@code HTML.Tag.HEAD} 2240 * <td>HeadAction 2241 * <tr> 2242 * <th scope="row">{@code HTML.Tag.HR} 2243 * <td>SpecialAction 2244 * <tr> 2245 * <th scope="row">{@code HTML.Tag.HTML} 2246 * <td>BlockAction 2247 * <tr> 2248 * <th scope="row">{@code HTML.Tag.I} 2249 * <td>CharacterAction 2250 * <tr> 2251 * <th scope="row">{@code HTML.Tag.IMG} 2252 * <td>SpecialAction 2253 * <tr> 2254 * <th scope="row">{@code HTML.Tag.INPUT} 2255 * <td>FormAction 2256 * <tr> 2257 * <th scope="row">{@code HTML.Tag.ISINDEX} 2258 * <td>IsndexAction 2259 * <tr> 2260 * <th scope="row">{@code HTML.Tag.KBD} 2261 * <td>CharacterAction 2262 * <tr> 2263 * <th scope="row">{@code HTML.Tag.LI} 2264 * <td>BlockAction 2265 * <tr> 2266 * <th scope="row">{@code HTML.Tag.LINK} 2267 * <td>LinkAction 2268 * <tr> 2269 * <th scope="row">{@code HTML.Tag.MAP} 2270 * <td>MapAction 2271 * <tr> 2272 * <th scope="row">{@code HTML.Tag.MENU} 2273 * <td>BlockAction 2274 * <tr> 2275 * <th scope="row">{@code HTML.Tag.META} 2276 * <td>MetaAction 2277 * <tr> 2278 * <th scope="row">{@code HTML.Tag.NOFRAMES} 2279 * <td>BlockAction 2280 * <tr> 2281 * <th scope="row">{@code HTML.Tag.OBJECT} 2282 * <td>SpecialAction 2283 * <tr> 2284 * <th scope="row">{@code HTML.Tag.OL} 2285 * <td>BlockAction 2286 * <tr> 2287 * <th scope="row">{@code HTML.Tag.OPTION} 2288 * <td>FormAction 2289 * <tr> 2290 * <th scope="row">{@code HTML.Tag.P} 2291 * <td>ParagraphAction 2292 * <tr> 2293 * <th scope="row">{@code HTML.Tag.PARAM} 2294 * <td>HiddenAction 2295 * <tr> 2296 * <th scope="row">{@code HTML.Tag.PRE} 2297 * <td>PreAction 2298 * <tr> 2299 * <th scope="row">{@code HTML.Tag.SAMP} 2300 * <td>CharacterAction 2301 * <tr> 2302 * <th scope="row">{@code HTML.Tag.SCRIPT} 2303 * <td>HiddenAction 2304 * <tr> 2305 * <th scope="row">{@code HTML.Tag.SELECT} 2306 * <td>FormAction 2307 * <tr> 2308 * <th scope="row">{@code HTML.Tag.SMALL} 2309 * <td>CharacterAction 2310 * <tr> 2311 * <th scope="row">{@code HTML.Tag.STRIKE} 2312 * <td>CharacterAction 2313 * <tr> 2314 * <th scope="row">{@code HTML.Tag.S} 2315 * <td>CharacterAction 2316 * <tr> 2317 * <th scope="row">{@code HTML.Tag.STRONG} 2318 * <td>CharacterAction 2319 * <tr> 2320 * <th scope="row">{@code HTML.Tag.STYLE} 2321 * <td>StyleAction 2322 * <tr> 2323 * <th scope="row">{@code HTML.Tag.SUB} 2324 * <td>CharacterAction 2325 * <tr> 2326 * <th scope="row">{@code HTML.Tag.SUP} 2327 * <td>CharacterAction 2328 * <tr> 2329 * <th scope="row">{@code HTML.Tag.TABLE} 2330 * <td>BlockAction 2331 * <tr> 2332 * <th scope="row">{@code HTML.Tag.TD} 2333 * <td>BlockAction 2334 * <tr> 2335 * <th scope="row">{@code HTML.Tag.TEXTAREA} 2336 * <td>FormAction 2337 * <tr> 2338 * <th scope="row">{@code HTML.Tag.TH} 2339 * <td>BlockAction 2340 * <tr> 2341 * <th scope="row">{@code HTML.Tag.TITLE} 2342 * <td>TitleAction 2343 * <tr> 2344 * <th scope="row">{@code HTML.Tag.TR} 2345 * <td>BlockAction 2346 * <tr> 2347 * <th scope="row">{@code HTML.Tag.TT} 2348 * <td>CharacterAction 2349 * <tr> 2350 * <th scope="row">{@code HTML.Tag.U} 2351 * <td>CharacterAction 2352 * <tr> 2353 * <th scope="row">{@code HTML.Tag.UL} 2354 * <td>BlockAction 2355 * <tr> 2356 * <th scope="row">{@code HTML.Tag.VAR} 2357 * <td>CharacterAction 2358 * </tbody> 2359 * </table> 2360 * <p> 2361 * Once </html> is encountered, the Actions are no longer notified. 2362 */ 2363 public class HTMLReader extends HTMLEditorKit.ParserCallback { 2364 2365 /** 2366 * Constructs an HTMLReader using default pop and push depth and no tag to insert. 2367 * 2368 * @param offset the starting offset 2369 */ 2370 public HTMLReader(int offset) { 2371 this(offset, 0, 0, null); 2372 } 2373 2374 /** 2375 * Constructs an HTMLReader. 2376 * 2377 * @param offset the starting offset 3527 } 3528 3529 /** 3530 * Action to support forms by building all of the elements 3531 * used to represent form controls. This will process 3532 * the <INPUT>, <TEXTAREA>, <SELECT>, 3533 * and <OPTION> tags. The element created by 3534 * this action is expected to have the attribute 3535 * <code>StyleConstants.ModelAttribute</code> set to 3536 * the model that holds the state for the form control. 3537 * This enables multiple views, and allows document to 3538 * be iterated over picking up the data of the form. 3539 * The following are the model assignments for the 3540 * various type of form elements. 3541 * 3542 * <table class="striped"> 3543 * <caption>Model assignments for the various types of form elements 3544 * </caption> 3545 * <thead> 3546 * <tr> 3547 * <th scope="col">Element Type 3548 * <th scope="col">Model Type 3549 * </thead> 3550 * <tbody> 3551 * <tr> 3552 * <th scope="row">input, type button 3553 * <td>{@link DefaultButtonModel} 3554 * <tr> 3555 * <th scope="row">input, type checkbox 3556 * <td>{@link JToggleButton.ToggleButtonModel} 3557 * <tr> 3558 * <th scope="row">input, type image 3559 * <td>{@link DefaultButtonModel} 3560 * <tr> 3561 * <th scope="row">input, type password 3562 * <td>{@link PlainDocument} 3563 * <tr> 3564 * <th scope="row">input, type radio 3565 * <td>{@link JToggleButton.ToggleButtonModel} 3566 * <tr> 3567 * <th scope="row">input, type reset 3568 * <td>{@link DefaultButtonModel} 3569 * <tr> 3570 * <th scope="row">input, type submit 3571 * <td>{@link DefaultButtonModel} 3572 * <tr> 3573 * <th scope="row">input, type text or type is null. 3574 * <td>{@link PlainDocument} 3575 * <tr> 3576 * <th scope="row">select 3577 * <td>{@link DefaultComboBoxModel} or an {@link DefaultListModel}, 3578 * with an item type of Option 3579 * <tr> 3580 * <td>textarea 3581 * <td>{@link PlainDocument} 3582 * </tbody> 3583 * </table> 3584 */ 3585 public class FormAction extends SpecialAction { 3586 3587 public void start(HTML.Tag t, MutableAttributeSet attr) { 3588 if (t == HTML.Tag.INPUT) { 3589 String type = (String) 3590 attr.getAttribute(HTML.Attribute.TYPE); 3591 /* 3592 * if type is not defined the default is 3593 * assumed to be text. 3594 */ 3595 if (type == null) { 3596 type = "text"; 3597 attr.addAttribute(HTML.Attribute.TYPE, "text"); 3598 } 3599 setModel(type, attr); 3600 } else if (t == HTML.Tag.TEXTAREA) { 3601 inTextArea = true; 3602 textAreaDocument = new TextAreaDocument(); 3603 attr.addAttribute(StyleConstants.ModelAttribute, |