| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.widgets;
|
|---|
| 3 |
|
|---|
| 4 | import javax.swing.text.ViewFactory;
|
|---|
| 5 | import javax.swing.text.html.HTMLEditorKit;
|
|---|
| 6 | import javax.swing.text.html.StyleSheet;
|
|---|
| 7 |
|
|---|
| 8 | /**
|
|---|
| 9 | * A subclass of {@link HTMLEditorKit} that fixes an uncommon design choice that shares the set stylesheet between all instances.
|
|---|
| 10 | * This class stores a single stylesheet per instance, as it should have be done by Sun in the first place.
|
|---|
| 11 | * Moreover it allows to display SVG images.
|
|---|
| 12 | * @since 6040
|
|---|
| 13 | */
|
|---|
| 14 | public class JosmHTMLEditorKit extends HTMLEditorKit {
|
|---|
| 15 |
|
|---|
| 16 | /** Shared factory for creating HTML Views. */
|
|---|
| 17 | private static final ViewFactory FACTORY = new JosmHTMLFactory();
|
|---|
| 18 |
|
|---|
| 19 | private StyleSheet ss = super.getStyleSheet();
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * Set the set of styles to be used to render the various HTML elements.
|
|---|
| 23 | * These styles are specified in terms of CSS specifications.
|
|---|
| 24 | * Each document produced by the kit will have a copy of the sheet which
|
|---|
| 25 | * it can add the document specific styles to.
|
|---|
| 26 | *
|
|---|
| 27 | * Unlike the base implementation, the StyleSheet specified is NOT shared
|
|---|
| 28 | * by all HTMLEditorKit instances, to provide a finer granularity.
|
|---|
| 29 |
|
|---|
| 30 | * @see #getStyleSheet
|
|---|
| 31 | */
|
|---|
| 32 | @Override
|
|---|
| 33 | public void setStyleSheet(StyleSheet s) {
|
|---|
| 34 | ss = s;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Get the set of styles currently being used to render the HTML elements.
|
|---|
| 39 | *
|
|---|
| 40 | * Unlike the base implementation, the StyleSheet specified is NOT shared
|
|---|
| 41 | * by all HTMLEditorKit instances, to provide a finer granularity.
|
|---|
| 42 | *
|
|---|
| 43 | * @see #setStyleSheet
|
|---|
| 44 | */
|
|---|
| 45 | @Override
|
|---|
| 46 | public StyleSheet getStyleSheet() {
|
|---|
| 47 | return ss;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override
|
|---|
| 51 | public ViewFactory getViewFactory() {
|
|---|
| 52 | return FACTORY;
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|