Search in sources :

Example 31 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project OpenAM by OpenRock.

the class TableJPanel method appendMessage.

private void appendMessage(String colorString, String s) {
    HTMLEditorKit kit = (HTMLEditorKit) messagejEditorPane.getEditorKit();
    HTMLDocument doc = (HTMLDocument) messagejEditorPane.getDocument();
    try {
        String newS = s.replaceAll("<", "&lt;");
        newS = newS.replaceAll(">", "&gt;");
        newS = newS.replaceAll("\n", "<br>");
        kit.insertHTML(doc, messagejEditorPane.getCaretPosition(), "<font color=" + colorString + ">" + newS, 0, 0, HTML.Tag.FONT);
        messagejEditorPane.setCaretPosition(doc.getLength() - 1);
    } catch (Exception ex) {
        //ex.printStackTrace();
        System.out.println("Exception in TableJPanel :" + ex.getMessage());
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Example 32 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project intellij-community by JetBrains.

the class StudySwingToolWindow method createTaskInfoPanel.

@Override
public JComponent createTaskInfoPanel(Project project) {
    myTaskTextPane = new JTextPane();
    final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane);
    myTaskTextPane.setContentType(new HTMLEditorKit().getContentType());
    final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
    int fontSize = editorColorsScheme.getEditorFontSize();
    final String fontName = editorColorsScheme.getEditorFontName();
    final Font font = new Font(fontName, Font.PLAIN, fontSize);
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }" + "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" + "code {font-family: Courier; display: flex; float: left; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}";
    ((HTMLDocument) myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
    myTaskTextPane.setEditable(false);
    if (!UIUtil.isUnderDarcula()) {
        myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
    }
    myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10));
    myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
    return scrollPane;
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EmptyBorder(javax.swing.border.EmptyBorder) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 33 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.

the class LargeQuickDoc method main.

public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        JFrame f = new JFrame();
        JEditorPane editorPane = new javax.swing.JEditorPane("text/html", "");
        editorPane.setEditorKit(new HTMLEditorKit());
        editorPane.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(editorPane);
        scrollPane.setBorder(null);
        try {
            editorPane.setText(getText());
        } catch (IOException | ArrayIndexOutOfBoundsException e) {
            throw new RuntimeException(e);
        }
        f.getContentPane().add(scrollPane);
        f.setSize(500, 500);
        f.setVisible(true);
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JFrame(javax.swing.JFrame) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException)

Example 34 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.

the class bug8058120 method createAndShowGUI.

private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());
    document = (HTMLDocument) editorPane.getDocument();
    editorPane.setText(text);
    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Example 35 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.

the class bug8028616 method main.

public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    htmlDoc.getParser().parse(new StringReader(text), cb, true);
    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }
    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }
    if (exception != null) {
        throw exception;
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) StringReader(java.io.StringReader) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

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