1 package org.catacomb.druid.gui.base;
2
3 import java.awt.Color;
4
5 import org.catacomb.druid.swing.DHTMLPane;
6 import org.catacomb.interlish.structure.InfoReceiver;
7 import org.catacomb.interlish.util.JUtil;
8 import org.catacomb.report.E;
9 import org.catacomb.xdoc.TextTagger;
10 import org.catacomb.xdoc.XdocBase;
11
12
13 public class DruInfoPanel extends DruPanel implements InfoDisplay, InfoReceiver {
14
15 static final long serialVersionUID = 1001;
16
17 String htmlTemplate;
18
19 DHTMLPane htmlPane;
20
21
22 int newTextAction;
23 public final static int REPLACE = 0;
24 public final static int APPEND = 1;
25
26
27 String lastTitle;
28 String lastText;
29
30 StringBuffer textSB;
31
32
33 public DruInfoPanel() {
34 this("");
35 }
36
37
38 public DruInfoPanel(String text) {
39 this(text, 0, 0);
40 }
41
42
43 public DruInfoPanel(String text, int w, int h) {
44 super(DruPanel.SCROLLABLE);
45
46 newTextAction = REPLACE;
47
48
49 htmlPane = new DHTMLPane();
50 if (w > 0 && h > 0) {
51 htmlPane.setPrefSize(w, h);
52
53 }
54 htmlPane.setEditable(false);
55
56
57 htmlPane.setDefaultStyleSheet();
58
59 setSingle();
60 addDComponent(htmlPane);
61
62 if (text != null) {
63 showInfo(text);
64 }
65 }
66
67
68
69 public void setAppendMode() {
70 newTextAction = APPEND;
71 }
72
73
74 public void setReplaceMode() {
75 newTextAction = REPLACE;
76 }
77
78
79 public void receiveInfo(String txt) {
80 E.debugError("plain text info");
81 showInfo("", txt);
82 }
83
84
85 public void receiveInfo(String infoTitle, String txt) {
86 showInfo(infoTitle, txt);
87 }
88
89
90
91 public String getHTMLTemplate() {
92 if (htmlTemplate == null) {
93 htmlTemplate = JUtil.getRelativeResource(new XdocBase(), "InfoHTMLTemplate.txt");
94 }
95 return htmlTemplate;
96 }
97
98
99 public void showText(String s) {
100 showInfo(s);
101 }
102
103
104 public void setBg(Color c) {
105 htmlPane.setBackground(c);
106 super.setBg(c);
107 }
108
109
110 public void setText(String s) {
111 showInfo(s);
112 }
113
114
115 public void showHTMLContent(String s) {
116 showInfo(s);
117 }
118
119
120 public void showInfo(String s) {
121 showInfo("", s);
122 }
123
124
125
126 public void showInfo(String itin, String txtin) {
127 String infoTitle = itin;
128 String txt = txtin;
129 if (txt == null) {
130 txt = "";
131 }
132
133 if (infoTitle == null) {
134 infoTitle = "";
135 }
136
137 if (lastTitle == null) {
138 lastTitle = "";
139 }
140
141 if (lastText == null) {
142 lastText = "";
143 }
144
145 if (infoTitle.equals(lastTitle) && txt.equals(lastText)) {
146
147
148 } else {
149 lastTitle = infoTitle;
150 lastText = txt;
151
152 if (textSB == null || newTextAction == REPLACE) {
153 textSB = new StringBuffer();
154 }
155
156 if (infoTitle != null && infoTitle.length() > 0) {
157 textSB.append("<h2>");
158 textSB.append(infoTitle);
159 textSB.append("</h2>\n");
160 }
161
162 String[] da = txt.split("-p-");
163 for (String apar : da) {
164 String stxt = TextTagger.getTagger().htmlizeParagraph(apar);
165
166
167 stxt = stxt.replaceAll("-b-", "<br>");
168
169 textSB.append("<p>");
170 textSB.append(stxt);
171 textSB.append("</p>");
172 }
173
174 int iep = 0;
175 while (textSB.length() > 1000 && (iep = textSB.indexOf("</p>")) > 0) {
176 textSB.delete(0, iep + 4);
177 }
178
179
180 String sh = getHTMLTemplate().replaceAll("BODY", textSB.toString());
181 htmlPane.showHTML(sh);
182
183
184
185
186
187 textAdded();
188
189
190
191 }
192 }
193
194
195 public void textAdded() {
196
197 }
198
199
200
201 }