Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | /* |
2 | GNU Lesser General Public License | |
3 | ||
4 | ExtendedHTMLEditorKit | |
5 | Copyright (C) 2001-2002 Frits Jalvingh & Howard Kistler | |
6 | ||
7 | This library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
11 | ||
12 | This library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
18 | License along with this library; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
22 | package com.hexidec.ekit.component; | |
23 | ||
24 | import javax.swing.text.Element; | |
25 | import javax.swing.text.StyleConstants; | |
26 | import javax.swing.text.View; | |
27 | import javax.swing.text.ViewFactory; | |
28 | import javax.swing.text.html.HTML; | |
29 | import javax.swing.text.html.HTMLEditorKit; | |
30 | ||
31 | /* WACKY GERMAN CODE */ | |
32 | import com.hexidec.ekit.component.ExtendedHTMLDocument; | |
33 | import javax.swing.text.html.StyleSheet; | |
34 | import javax.swing.text.Document; | |
35 | ||
36 | /** | |
37 | * This class extends HTMLEditorKit so that it can provide other renderer classes | |
38 | * instead of the defaults. Most important is the part which renders relative | |
39 | * image paths. | |
40 | * | |
41 | * @author <a href="mailto:jal@grimor.com">Frits Jalvingh</a> | |
42 | * @version 1.0 | |
43 | */ | |
44 | ||
45 | public class ExtendedHTMLEditorKit extends HTMLEditorKit | |
46 | { | |
47 | /** Constructor | |
48 | */ | |
49 | public ExtendedHTMLEditorKit() | |
50 | { | |
51 | } | |
52 | ||
53 | /** Method for returning a ViewFactory which handles the image rendering. | |
54 | */ | |
55 | public ViewFactory getViewFactory() | |
56 | { | |
57 | return new HTMLFactoryExtended(); | |
58 | } | |
59 | ||
60 | /* WACKY GERMAN CODE */ | |
61 | public Document createDefaultDocument() { | |
62 | StyleSheet styles = getStyleSheet(); | |
63 | StyleSheet ss = new StyleSheet(); | |
64 | ss.addStyleSheet(styles); | |
65 | ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss); | |
66 | doc.setParser(getParser()); | |
67 | doc.setAsynchronousLoadPriority(4); | |
68 | doc.setTokenThreshold(100); | |
69 | return doc; | |
70 | } | |
71 | ||
72 | /* Inner Classes --------------------------------------------- */ | |
73 | ||
74 | /** Class that replaces the default ViewFactory and supports | |
75 | * the proper rendering of both URL-based and local images. | |
76 | */ | |
77 | public static class HTMLFactoryExtended extends HTMLFactory implements ViewFactory | |
78 | { | |
79 | /** Constructor | |
80 | */ | |
81 | public HTMLFactoryExtended() | |
82 | { | |
83 | } | |
84 | ||
85 | /** Method to handle IMG tags and | |
86 | * invoke the image loader. | |
87 | */ | |
88 | public View create(Element elem) | |
89 | { | |
90 | Object obj = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); | |
91 | if(obj instanceof HTML.Tag) | |
92 | { | |
93 | HTML.Tag tagType = (HTML.Tag)obj; | |
94 | if(tagType == HTML.Tag.IMG) | |
95 | { | |
96 | return new RelativeImageView(elem); | |
97 | } | |
98 | } | |
99 | return super.create(elem); | |
100 | } | |
101 | } | |
102 | } |