From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- .../c2kernel/gui/tabs/outcome/form/HelpPane.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 source/com/c2kernel/gui/tabs/outcome/form/HelpPane.java (limited to 'source/com/c2kernel/gui/tabs/outcome/form/HelpPane.java') diff --git a/source/com/c2kernel/gui/tabs/outcome/form/HelpPane.java b/source/com/c2kernel/gui/tabs/outcome/form/HelpPane.java new file mode 100755 index 0000000..0f0f812 --- /dev/null +++ b/source/com/c2kernel/gui/tabs/outcome/form/HelpPane.java @@ -0,0 +1,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 = "

"+Language.translate("Help")+"

"; + + 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+"

"+title+"


"+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) { + xhtml = xhtml.substring(0,startPos)+xhtml.substring(endPos+2); + } + // remove slash in + while ((startPos = xhtml.indexOf("/>")) != -1) { + xhtml = xhtml.substring(0, startPos)+xhtml.substring(startPos+1); + } + return xhtml; + } +} -- cgit v1.2.3