Search in sources :

Example 46 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project open-ecard by ecsec.

the class AboutDialog method createTabContent.

private JPanel createTabContent(String resourceName) {
    HTMLEditorKit kit = new HTMLEditorKit();
    // don't follow form link, use hyperlink handler instead
    kit.setAutoFormSubmission(false);
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);
    editorPane.setEditorKit(kit);
    editorPane.setDocument(doc);
    try {
        URL url = LANG.translationForFile(resourceName, "html");
        editorPane.setPage(url);
    } catch (IOException ex) {
        editorPane.setText("Page not found.");
    }
    editorPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            openUrl(e);
        }
    });
    JScrollPane scrollPane = new JScrollPane(editorPane);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) HyperlinkEvent(javax.swing.event.HyperlinkEvent) BorderLayout(java.awt.BorderLayout) HyperlinkListener(javax.swing.event.HyperlinkListener) HTMLDocument(javax.swing.text.html.HTMLDocument) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException) URL(java.net.URL)

Example 47 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUIUtil method createDescriptionPane.

@NotNull
public static JTextPane createDescriptionPane() {
    JTextPane result = new JTextPane();
    result.addHyperlinkListener(new BrowserHyperlinkListener());
    result.setContentType("text/html");
    Font descriptionFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
    HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit();
    editorKit.getStyleSheet().addRule("body, p {" + "color:#" + ColorUtil.toHex(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)) + ";" + "font-family:" + descriptionFont.getFamily() + ";" + "font-size:" + descriptionFont.getSize() + "pt;}");
    result.setHighlighter(null);
    result.setEditorKit(editorKit);
    return result;
}
Also used : BrowserHyperlinkListener(com.intellij.ui.BrowserHyperlinkListener) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)47 HTMLDocument (javax.swing.text.html.HTMLDocument)18 JEditorPane (javax.swing.JEditorPane)10 StyleSheet (javax.swing.text.html.StyleSheet)9 IOException (java.io.IOException)8 JScrollPane (javax.swing.JScrollPane)8 Dimension (java.awt.Dimension)7 URL (java.net.URL)7 Document (javax.swing.text.Document)6 MouseEvent (java.awt.event.MouseEvent)5 StringReader (java.io.StringReader)5 HyperlinkEvent (javax.swing.event.HyperlinkEvent)5 ActionListener (java.awt.event.ActionListener)4 HyperlinkListener (javax.swing.event.HyperlinkListener)4 BorderLayout (java.awt.BorderLayout)3 ActionEvent (java.awt.event.ActionEvent)3 InputStream (java.io.InputStream)3 BadLocationException (javax.swing.text.BadLocationException)3 MouseAdapter (java.awt.event.MouseAdapter)2 InputStreamReader (java.io.InputStreamReader)2