a8807ba41bb3e44aab2b455572fce34acc8c06f3
2 GNU Lesser General Public License
5 Copyright (C) 2001 Frits Jalvingh, Jerry Pommer & Howard Kistler
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.
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.
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
22 package com
.hexidec
.ekit
.component
;
24 import javax
.swing
.text
.Document
;
25 import javax
.swing
.text
.Element
;
26 import javax
.swing
.text
.StyleConstants
;
27 import javax
.swing
.text
.View
;
28 import javax
.swing
.text
.ViewFactory
;
29 import javax
.swing
.text
.html
.HTML
;
30 import javax
.swing
.text
.html
.HTMLEditorKit
;
31 import javax
.swing
.text
.html
.StyleSheet
;
33 import com
.hexidec
.ekit
.component
.ExtendedHTMLDocument
;
36 * This class extends HTMLEditorKit so that it can provide other renderer classes
37 * instead of the defaults. Most important is the part which renders relative
40 * @author <a href="mailto:jal@grimor.com">Frits Jalvingh</a>
44 public class ExtendedHTMLEditorKit
extends HTMLEditorKit
46 private String BaseUrl
= "";
50 public ExtendedHTMLEditorKit()
54 public ExtendedHTMLEditorKit(String baseurl
)
59 /** Method for returning a ViewFactory which handles the image rendering.
61 public ViewFactory
getViewFactory()
63 return new HTMLFactoryExtended(BaseUrl
);
66 public Document
createDefaultDocument()
68 StyleSheet styles
= getStyleSheet();
69 StyleSheet ss
= new StyleSheet();
70 ss
.addStyleSheet(styles
);
71 ExtendedHTMLDocument doc
= new ExtendedHTMLDocument(ss
);
72 doc
.setParser(getParser());
73 doc
.setAsynchronousLoadPriority(4);
74 doc
.setTokenThreshold(100);
78 /* Inner Classes --------------------------------------------- */
80 /** Class that replaces the default ViewFactory and supports
81 * the proper rendering of both URL-based and local images.
83 public static class HTMLFactoryExtended
extends HTMLFactory
implements ViewFactory
85 private String BaseUrl
;
89 public HTMLFactoryExtended(String baseurl
)
94 /** Method to handle IMG tags and
95 * invoke the image loader.
97 public View
create(Element elem
)
99 Object obj
= elem
.getAttributes().getAttribute(StyleConstants
.NameAttribute
);
100 if(obj
instanceof HTML
.Tag
)
102 HTML
.Tag tagType
= (HTML
.Tag
)obj
;
103 if(tagType
== HTML
.Tag
.IMG
)
105 return new RelativeImageView(elem
,BaseUrl
);
108 return super.create(elem
);