package net.sourceforge.pain.tools.guitool.action;
import net.sourceforge.pain.tools.guitool.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.io.*;
import java.util.*;
public class HtmlComponentRegistry {
private HtmlComponentRegistry() {
}
private static final HashMap componentByClass = new HashMap();
private static StyleSheet commonStyleSheet = null;
public static synchronized JEditorPane get(Class clazz) throws IOException, BadLocationException {
JEditorPane instance = (JEditorPane) componentByClass.get(clazz);
if (instance == null) {
String text = GuiTool.readTextFile(clazz, "/" + clazz.getName().replace('.', '/') + ".html");
instance = new JEditorPane();
instance.setContentType("text/html");
instance.setEditable(false);
StyleSheet styles = getCommonStyleSheet();
HTMLEditorKit kit = new HTMLEditorKit();
kit.setStyleSheet(styles);
Document doc = kit.createDefaultDocument();
kit.read(new StringReader(text), doc, 0);
instance.setDocument(doc);
}
return instance;
}
private static StyleSheet getCommonStyleSheet() throws IOException {
if (commonStyleSheet == null) {
commonStyleSheet = new StyleSheet();
commonStyleSheet.loadRules(new StringReader(GuiTool.readTextFile(null, "pain.css")), null);
}
return commonStyleSheet;
}
}