Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / component / ExtendedHTMLEditorKit.java
CommitLineData
c2da4d40
JL
1/*
2GNU Lesser General Public License
3
4ExtendedHTMLEditorKit
5Copyright (C) 2001-2002 Frits Jalvingh & Howard Kistler
6
7This library is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/
21
22package com.hexidec.ekit.component;
23
24import javax.swing.text.Element;
25import javax.swing.text.StyleConstants;
26import javax.swing.text.View;
27import javax.swing.text.ViewFactory;
28import javax.swing.text.html.HTML;
29import javax.swing.text.html.HTMLEditorKit;
30
31/* WACKY GERMAN CODE */
32import com.hexidec.ekit.component.ExtendedHTMLDocument;
33import javax.swing.text.html.StyleSheet;
34import 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
45public 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}