View Javadoc

1   
2   package org.catacomb.druid.swing;
3   
4   import java.awt.Color;
5   import java.awt.Font;
6   import java.io.StringReader;
7   
8   import javax.swing.JEditorPane;
9   import javax.swing.text.html.HTMLDocument;
10  import javax.swing.text.html.HTMLEditorKit;
11  import javax.swing.text.html.StyleSheet;
12  
13  
14  public class DEditorPane extends JEditorPane {
15      static final long serialVersionUID = 1001;
16  
17      static Font plainfont;
18  
19      static Font boldfont;
20  
21  
22      HTMLEditorKit htmlEditorKit;
23      StyleSheet styleSheet;
24  
25  
26  
27  
28      public DEditorPane() {
29          super();
30          htmlEditorKit = new HTMLEditorKit();
31          setEditorKit(htmlEditorKit);
32          setPlainFont();
33  
34      }
35  
36  
37      public void setBg(Color c) {
38          setBackground(c);
39      }
40  
41  
42      public void setStyleSheet(StyleSheet ss) {
43          styleSheet = ss;
44          htmlEditorKit.setStyleSheet(ss);
45      }
46  
47  
48      public StyleSheet getStyleSheet() {
49          return styleSheet;
50      }
51  
52  
53      public void showHTML(String s) {
54          //      hek.createDefaultDocument();
55  
56          HTMLDocument doc = new HTMLDocument(styleSheet);
57  
58          try {
59              htmlEditorKit.read(new StringReader(s), doc, 0);
60          } catch (Exception ex) {
61  
62          }
63          setDocument(doc);
64  
65          /*
66          StyleSheet styles = doc.getStyleSheet();
67          E.info("doc ss " + styles.hashCode() + "   src ss " + styleSheet.hashCode());
68  
69          E.info("doc ek " + htmlEditorKit.hashCode() + "   src ek " + getEditorKit().hashCode());
70          */
71      }
72  
73  
74      public void setPlainFont() {
75          if (plainfont == null) {
76              plainfont = new Font("SansSerif", Font.PLAIN, 10);
77          }
78  
79          //      setFont(plainfont);
80      }
81  
82  
83      public void setBoldFont() {
84          if (boldfont == null) {
85              boldfont = new Font("SansSerif", Font.BOLD, 10);
86          }
87          //      setFont(boldfont);
88      }
89  }