JavaSwingText components and DocumentHTML: HTMLEditorKit


HTMLEditorKit

Features

default style sheet management

createDocument creates an HTMLDocument with parser/style sheet

read uses Parser to read into HTMLDocuments

write uses HTMLWriter for HTMLDocument, MinimalHTMLWriter for StyledDocument

input attribute logic (removes some attributes), why getInputAttributes from StyleSheet?

View factory for HTML views

Actions to navigate/follow links

Mouse listener to follow links+Cursor settings

Method to insert HTML strings (insertHTML), only used by unused Actions - why is it not like the other HTML methods in HTMLDocument?

Actions to insert HTML strings (nontrivial insertion logic), internally unused

AccessibleHTML

Parsers

Properties

HTMLEditorKit has a default parser that is set on each document on creation.

Still, read and insertHTML do not use the document's parser, but the HTMLEditorKit's (even since in Swing 1.1.1).

OTOH, HTMLDocument.insertHTML (called from insertXXX, setXXXHTML) uses the Document's parser.

Implementations

The only implementation of Parser is ParserDelegator in the parser package.

The only implementation of ParserCallback is HTMLReader in HTMLDocument.

Parser invocations

HTMLEditorKit.read

HTMLEditorKit.insertHTML

HTMLDocument.insertHTML (called from various public methods)

Nested parser-classes use

Parser package (only Parser, Parser callback)

HTMLDocument (only Parser, ParserCallback)

Uses

FormView: only for createDefaultDocument, not really needed, but:

JEditorPane: read special (seems to be used only by FormView), accessibility different

BasicHTML: uses subclass

Not using HTMLEditorKit

Reasons

not serializable (for a silly reason: Position.Bias is not serializable), in 1.4 also non-transient reference to component

link actions/mouse listener are non-extendible and sometimes undesirable (in the way it is done) (Actions could be replaced completely by changing getActions).

magic for JEditorPane

fixes/features in subclasses of StyledEditorKit can also be taken for a new html editor kit (instead of duplicating them in a subclass of HTMLEditorKit)

How to

default style sheet management: trivially done, even better

createDocument creates an HTMLDocument with parser/style sheet: trivially done

read uses Parser to read into HTMLDocuments: trivially done

write uses HTMLWriter for HTMLDocument: trivially done, MinimalHTMLWriter for StyledDocument: useless

input attribute logic (removes some attributes): trivially done

View factory for HTML views: can take from internal HTMLEditorKit (static anyway), only FormView (which is bad anyway) causes problems. For a very useful subset of HTML, a custom ViewFactory without falling back can be used (TableView should be rewritten anyway)

insertHTML: trivially moved into HTMLDocument where it belongs

Actions to insert HTML strings (nontrivial insertion logic), internally unused: analyse and generalize (can also be taken directly if insertHTML is changed to call the document's) if they prove to be useful

Actions to navigate/follow links: rewrite (better)

Mouse listener to follow links+Cursor settings (cause problems): rewrite (better)

AccessibleHTML: rewrite (if really necessary that way)


(C) 2001-2009 Christian Kaufhold (swing@chka.de)