Model of the JWebEngine internals

Compact model of JWebEngine internals

JWebEngine is designed to fit into the API of javax.swing.text. That's why you can use it in any JEditorPane without any further requirements. But this is only one side of JWebEngine. Depending on the requirements the renderer can be customized or even used without a parent Swing component. Another possibility is to extend JWebEngine with a spell-checker like JOrtho for instance or a text search highlighter.

To give you a feeling of how these features and extensions work, we want to give a look behind the scenes of JWebEngine.

Model and View

JWebEngine extends the Document API of javax.swing.text and therefore shares it's concepts of model and view set up.

The main entry point for the model is the document, which is the InetHtmlDocument in JWebEngine. This class is the API to modify the model directly. It contains the HTML structure in form of an element tree - similar to the W3C DOM tree - and the text content of the document. The renderer of JWebEngine is the view tree structure. Basically there is one view per HTML element. Both trees can be modified - the element tree by using the document API, the view tree by setting Highlighters or customizing the view Factory.

Involving parser and writer

The objects mentioned above are only a snapshot of a currently displayed web site for instance. There are basically three steps required from an empty document to a displayable view tree like this one: using the parser to create the element tree, using the view factory to create the view tree and finally run the layout algorithms to fit the views into your editor. All these steps are encapsulated in the EditorKit. This class provides methods to create an appropriate document, to parse HTML content, to create the views and to convert an element tree back into HTML using the writer.

Complex model of JWebEngine internals

Customizing

As the diagram shows, JWebEngine can be used without an editor as well. Simply create the document and the view factory on your own to control the loading process of a document. Another option is to extend the view factory to create your own view elements or apply highlighters to the view structure. For more information about customizing, see the Use Cases

 

© Copyright 1996 - 2017, i-net software; All Rights Reserved.