1
2 package org.catacomb.druid.gui.edit;
3
4 import org.catacomb.druid.swing.DHTMLPane;
5 import org.catacomb.interlish.content.StringValue;
6 import org.catacomb.interlish.structure.*;
7
8
9 import java.awt.Color;
10
11
12 public class DruHTMLPanel extends DruGCPanel
13 implements TextSettable, PageDisplay, HyperlinkHandler, ValueWatcher {
14
15 static final long serialVersionUID = 1001;
16
17 DHTMLPane dHTMLPane;
18
19
20
21 StringValue stringValue;
22
23 boolean preformatted = false;
24
25 public DruHTMLPanel() {
26 super();
27 setSingle();
28 dHTMLPane = new DHTMLPane();
29 dHTMLPane.setDefaultStyleSheet();
30 addDComponent(dHTMLPane);
31 }
32
33
34 public void setText(String s) {
35 setContent(s);
36 }
37
38 public void setPreformatted(boolean b) {
39 preformatted = b;
40 }
41
42 public void setBg(Color c) {
43 dHTMLPane.setBg(c);
44 super.setBg(c);
45 }
46
47
48 public void setContent(String s) {
49 dHTMLPane.showHTML(s);
50 }
51
52
53 public void setPageSupplier(PageSupplier ps) {
54
55 showPage(ps.getPage("/"));
56 }
57
58
59 public void setPage(Page p) {
60 showPage(p);
61 }
62
63
64 public void showHTML(String txt) {
65 dHTMLPane.showHTML(txt);
66 }
67
68
69 public void showPage(Page p) {
70 dHTMLPane.showHTML(p.getHTMLText());
71 }
72
73
74 public void setLinkAction(String linkAction) {
75 methodName = linkAction;
76 dHTMLPane.setHyperlinkHandler(this);
77 }
78
79
80 public void hyperlinkClicked(String tgt) {
81 action(tgt);
82 }
83
84 public void setStringValue(StringValue sv) {
85 if (stringValue != null) {
86 stringValue.removeValueWatcher(this);
87 }
88 stringValue = sv;
89 if (stringValue == null) {
90 dHTMLPane.showHTML("");
91 } else {
92 exportStringValueContent();
93
94 stringValue.addValueWatcher(this);
95 }
96 }
97
98
99 public void valueChangedBy(Value pv, Object src) {
100 exportStringValueContent();
101 }
102
103
104 private void exportStringValueContent() {
105 String s = "";
106 if (stringValue != null) {
107 s = stringValue.getString();
108 }
109 if (preformatted) {
110 s = "<pre>\n" + s + "\n</pre>\n";
111 }
112 dHTMLPane.showHTML(s);
113 }
114
115
116 }