001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.widgets; 003 004import javax.swing.text.ViewFactory; 005import javax.swing.text.html.HTMLEditorKit; 006import javax.swing.text.html.StyleSheet; 007 008/** 009 * A subclass of {@link HTMLEditorKit} that fixes an uncommon design choice that shares the set stylesheet between all instances. 010 * This class stores a single stylesheet per instance, as it should have be done by Sun in the first place. 011 * Moreover it allows to display SVG images. 012 * @since 6040 013 */ 014public class JosmHTMLEditorKit extends HTMLEditorKit { 015 016 /** Shared factory for creating HTML Views. */ 017 private static final ViewFactory FACTORY = new JosmHTMLFactory(); 018 019 private StyleSheet ss = super.getStyleSheet(); 020 021 /** 022 * Set the set of styles to be used to render the various HTML elements. 023 * These styles are specified in terms of CSS specifications. 024 * Each document produced by the kit will have a copy of the sheet which 025 * it can add the document specific styles to. 026 * 027 * Unlike the base implementation, the StyleSheet specified is NOT shared 028 * by all HTMLEditorKit instances, to provide a finer granularity. 029 030 * @see #getStyleSheet 031 */ 032 @Override 033 public void setStyleSheet(StyleSheet s) { 034 ss = s; 035 } 036 037 /** 038 * Get the set of styles currently being used to render the HTML elements. 039 * 040 * Unlike the base implementation, the StyleSheet specified is NOT shared 041 * by all HTMLEditorKit instances, to provide a finer granularity. 042 * 043 * @see #setStyleSheet 044 */ 045 @Override 046 public StyleSheet getStyleSheet() { 047 return ss; 048 } 049 050 @Override 051 public ViewFactory getViewFactory() { 052 return FACTORY; 053 } 054}