The class SHTMLEditorKit

Class HTMLEditorKit in package javax.swing.text.html automatically associates a style sheet with any newly created HTMLDocument. The style sheet used is taken from the Java Runtime Environment and holds default styles for all possible HTML tags.

To use a different set of styles, we can either load another style sheet afterwards and delegate it to the HTMLDocument or we have to override this behaviour at its original location.

Class SHTMLEditorKit overrides all methods in HTMLEditorKit dealing with the default style sheet and uses our own set of styles.

Method getStyleSheet

This method returns the style sheet found in field defaultStyles of SHTMLEditorKit. If this field points to a StyleSheet object, this StyleSheet is returned.

If defaultStyles is not initialized so far, a new StyleSheet object is created. Then the default style sheet, identified by constant DEFAULT_CSS , is located by calling method getResourceAsStream inherited from class Class. getResourceAsStream looks for the style sheet file in the class path and returns an InputStream for it if found.

A CSS file ' default.css' is distributed with the classes of application SimplyHTML so that it can be loaded as default in this way. A new BufferedReader is created which reads from a new InputStreamReader used on the InputStream. Method loadRules of class StyleSheet then reads all styles from the BufferedReader.