blob: 0f0f812fa5833e667537a25ec857ee92eb474311 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package com.c2kernel.gui.tabs.outcome.form;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLEditorKit;
import com.c2kernel.utils.Language;
/**************************************************************************
*
* $Revision: 1.3 $
* $Date: 2004/08/24 12:44:02 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
public class HelpPane extends JEditorPane {
public static final String header = "<h2><font color=\"blue\">"+Language.translate("Help")+"</font></h2>";
public HelpPane() {
super();
setEditable(false);
setEditorKit(new HTMLEditorKit());
setContentType("text/html");
setPreferredSize(new java.awt.Dimension(200,400));
}
public void setHelp(String title, String helpText) {
setText(header+"<h3>"+title+"</h3><br>"+toHTML(helpText));
}
/**
* Unfortunately JEditorPane will only display HTML3.2, whereas to embed HTML in an xsd we must
* use XHTML so it will be valid XML. This method does a quick and dirty removal of stuff that
* the JEditorPane cannot display
*
* @param xhtml
* @return
*/
public static String toHTML(String xhtml) {
int startPos, endPos;
//remove xml header
while((startPos = xhtml.indexOf("<?")) != -1 &&
(endPos = xhtml.indexOf("?>")) != -1) {
xhtml = xhtml.substring(0,startPos)+xhtml.substring(endPos+2);
}
// remove slash in <tags/>
while ((startPos = xhtml.indexOf("/>")) != -1) {
xhtml = xhtml.substring(0, startPos)+xhtml.substring(startPos+1);
}
return xhtml;
}
}
|