Loading documents from file
When a document is loaded into a DocumentPane, the DocumentPane and its components need to be initialized properly. This is done in method loadDocument.
Method loadDocument
In method loadDocument , first the editor kit object is taken from the editor pane of this DocumentPane object. With method createDefaultDocument of the editor kit a properly initialized empty document object is created with the appropriate style sheet attached. The document base is set from the URL the document is to be loaded from. The document base is necessary so that all relative URLs probably contained in the document are correctly resolved.
The contents of the HTML file are then loaded into the new document object by opening an InputStream from the URL and using method read of the editor kit. The DocumentPane registers itself as DocumentListener with the new document, causing the document to notify its DocumentPane about all changes.
Finally the new HTMLDocument is assigned to the editor pane and the URL, the document was loaded from is stored in field sourceUrl of the DocumentPane.
How the style sheet is associated
Application SimplyHTML assumes that every HTML document is associated with a style sheet in a separate CSS file. This style sheet must be referenced by a link in the <head> tag of the HTML document as it is generated by method insertStyleRef.
If such a reference link is contained in the <head> tag of an HTMLDocument and the style sheet file can be found at the referenced location, the read method of the editor kit handles the style sheet reference correctly and the editor pane renders the HTML document with the associated styles.