Search in sources :

Example 6 with HTMLDocument

use of javax.swing.text.html.HTMLDocument 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 7 with HTMLDocument

use of javax.swing.text.html.HTMLDocument 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 8 with HTMLDocument

use of javax.swing.text.html.HTMLDocument 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 9 with HTMLDocument

use of javax.swing.text.html.HTMLDocument 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)

Example 10 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project EnrichmentMapApp by BaderLab.

the class CreationParametersPanel method getInfoPane.

JTextPane getInfoPane() {
    if (infoPane == null) {
        infoPane = new JTextPane();
        infoPane.setEditable(false);
        infoPane.setContentType("text/html");
        ((HTMLDocument) infoPane.getDocument()).setPreservesUnknownTags(false);
        infoPane.setText(getInfoText());
        makeSmall(infoPane);
    }
    return infoPane;
}
Also used : JTextPane(javax.swing.JTextPane) HTMLDocument(javax.swing.text.html.HTMLDocument)

Aggregations

HTMLDocument (javax.swing.text.html.HTMLDocument)30 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)10 Element (javax.swing.text.Element)6 StyleSheet (javax.swing.text.html.StyleSheet)6 URL (java.net.URL)5 AttributeSet (javax.swing.text.AttributeSet)5 BadLocationException (javax.swing.text.BadLocationException)5 IOException (java.io.IOException)4 Document (javax.swing.text.Document)4 Style (javax.swing.text.Style)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 StringReader (java.io.StringReader)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 HTMLFrameHyperlinkEvent (javax.swing.text.html.HTMLFrameHyperlinkEvent)2 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1