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);
}
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");
}
}
}
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();
}
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);
}
}
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;
}
Aggregations