Search in sources :

Example 11 with HTMLEditorKit

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

the class Test8017492 method main.

public static void main(String[] args) throws Exception {
    Runnable task = new Runnable() {

        @Override
        public void run() {
            try {
                SunToolkit.createNewAppContext();
                DTD dtd = DTD.getDTD("dtd");
                dtd.elements = new Vector<Element>() {

                    @Override
                    public synchronized int size() {
                        return Integer.MAX_VALUE;
                    }
                };
                dtd.getElement("element");
            } catch (Exception exception) {
                throw new Error("unexpected", exception);
            }
        }
    };
    // run task with different AppContext
    Thread thread = new Thread(new ThreadGroup("$$$"), task);
    thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            throwable.printStackTrace();
            System.exit(1);
        }
    });
    thread.start();
    thread.join();
    // add error handling
    HTMLDocument document = new HTMLDocument() {

        @Override
        public HTMLEditorKit.ParserCallback getReader(int pos) {
            return getReader(pos, 0, 0, null);
        }

        @Override
        public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) {
            return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) {

                @Override
                public void handleError(String error, int pos) {
                    throw new Error(error);
                }
            };
        }
    };
    // run parser
    new HTMLEditorKit().insertHTML(document, 0, "<html><body>text", 0, 0, null);
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.html.parser.Element) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) DTD(javax.swing.text.html.parser.DTD)

Example 12 with HTMLEditorKit

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

the class bug8005391 method main.

public static void main(String[] args) throws Exception {
    int N = 10;
    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();
        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) CharArrayWriter(java.io.CharArrayWriter)

Example 13 with HTMLEditorKit

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

the class bug7165725 method execute.

public void execute(final String urlStr, final GoldenElement goldenElement) throws Exception {
    System.out.println();
    System.out.println("***** TEST: " + urlStr + " *****");
    System.out.println();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            try {
                editorPane = new JEditorPane();
                editorPane.setEditorKit(new HTMLEditorKit() {

                    public Document createDefaultDocument() {
                        AbstractDocument doc = (AbstractDocument) super.createDefaultDocument();
                        doc.setAsynchronousLoadPriority(-1);
                        return doc;
                    }
                });
                editorPane.setPage(new URL(urlStr));
            } catch (IOException ex) {
                throw new RuntimeException("Test failed", ex);
            }
            editorPane.setEditable(false);
            JScrollPane scroller = new JScrollPane();
            JViewport vp = scroller.getViewport();
            vp.add(editorPane);
            add(scroller, BorderLayout.CENTER);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(400, 400);
            setLocationRelativeTo(null);
            setVisible(true);
        }
    });
    ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
            doc.dump(System.out);
            goldenElement.checkStructureEquivalence((AbstractElement) doc.getDefaultRootElement());
            dispose();
        }
    });
    System.out.println();
    System.out.println("*********************************");
    System.out.println();
}
Also used : AbstractDocument(javax.swing.text.AbstractDocument) AbstractElement(javax.swing.text.AbstractDocument.AbstractElement) HTMLDocument(javax.swing.text.html.HTMLDocument) SunToolkit(sun.awt.SunToolkit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException) URL(java.net.URL)

Example 14 with HTMLEditorKit

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

the class bug8015853 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();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane editorPane = new JEditorPane();
    HTMLEditorKit editorKit = new HTMLEditorKit();
    editorPane.setEditorKit(editorKit);
    editorPane.setText(text);
    frame.add(editorPane);
    frame.setVisible(true);
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Example 15 with HTMLEditorKit

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

the class bug8048110 method createAndShowGUI.

private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    HTMLEditorKit editorKit = new HTMLEditorKit();
    JTextPane textPane = new JTextPane();
    textPane.setContentType("text/html");
    textPane.setEditorKit(editorKit);
    textPane.setText("Initial text without table");
    JFrame frame = new JFrame("bug8048110");
    frame.getContentPane().add(textPane, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setSize(500, 200);
    frame.setVisible(true);
    textPane.setDocument(textPane.getEditorKit().createDefaultDocument());
    HTMLDocument htmlDocument = (HTMLDocument) textPane.getDocument();
    Element firstParagraph = findFirstElement(textPane.getDocument().getDefaultRootElement(), "p");
    try {
        htmlDocument.setInnerHTML(firstParagraph, htmlText);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) 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