01: package salomeTMF_plug.requirements.ihm;
02:
03: import java.awt.BorderLayout;
04: import java.awt.Dimension;
05: import java.awt.Font;
06: import java.io.StringReader;
07:
08: import javax.swing.JPanel;
09: import javax.swing.JScrollPane;
10: import javax.swing.JTextPane;
11: import javax.swing.text.DefaultStyledDocument;
12: import javax.swing.text.StyleContext;
13: import javax.swing.text.StyledDocument;
14: import javax.swing.text.html.HTMLDocument;
15: import javax.swing.text.html.HTMLEditorKit;
16: import javax.swing.text.rtf.RTFEditorKit;
17:
18: public class HistoryDescViewPanel extends JPanel {
19: HTMLDocument m_oDocument;
20: HTMLEditorKit m_oHTML;
21: JTextPane m_txtTexte;
22:
23: HistoryDescViewPanel(String htmlText) {
24: setLayout(new BorderLayout());
25: m_oHTML = new HTMLEditorKit();
26: m_oDocument = new HTMLDocument();
27: m_txtTexte = new JTextPane();
28: m_txtTexte.setEditorKit(m_oHTML);
29: m_txtTexte.setDocument(m_oDocument);
30: m_txtTexte.setEditable(false);
31: m_txtTexte.setMinimumSize(new Dimension(400, 400));
32: JScrollPane sclScroll = new JScrollPane(m_txtTexte);
33: sclScroll.setPreferredSize(new Dimension(400, 400));
34: if (htmlText != null) {
35: loadText(htmlText);
36: }
37: add(sclScroll, BorderLayout.CENTER);
38: }
39:
40: void loadText(String htmlText) {
41: try {
42: StringReader input = new StringReader(htmlText);
43: m_txtTexte.setText("");
44: m_oHTML.read(input, m_oDocument, 0);
45: input.close();
46: } catch (Exception ex) {
47: ex.printStackTrace();
48: System.out.println("Impossible de charger le document : "
49: + ex.toString());
50: }
51: }
52: }
|