List of usage examples for javax.swing.text.html HTMLDocument putProperty
public final void putProperty(Object key, Object value)
From source file:ReplaceReader.java
public static void main(String[] args) { try {// w w w. ja v a 2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("JEditorPane with Custom Reader"); JEditorPane ep = new JEditorPane(); f.getContentPane().add(new JScrollPane(ep)); f.setSize(400, 300); f.setVisible(true); HTMLEditorKit kit = new HTMLEditorKit() { public Document createDefaultDocument() { HTMLDocument doc = new CustomHTMLDocument(getStyleSheet()); doc.setAsynchronousLoadPriority(4); doc.setTokenThreshold(100); return doc; } }; ep.setEditorKit(kit); try { Document doc = ep.getDocument(); doc.putProperty("IgnoreCharsetDirective", new Boolean(true)); kit.read(new FileReader(args[0]), doc, 0); } catch (Exception e) { System.out.println("Exception while reading HTML " + e); } }
From source file:fedroot.dacs.swingdemo.DacsSwingDemo.java
/** * Sets the HTML content to be displayed. * * @param content an HTML document string */// w w w . jav a 2 s . co m private void setDocumentContent(String contenttype, String content) { HTMLDocument doc = new HTMLDocument(); try { doc.remove(0, doc.getLength()); } catch (BadLocationException ex) { logger.log(Level.WARNING, ex.getMessage()); } doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE); try { htmlPane.setContentType(contenttype); htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc); htmlPane.setDocument(doc); htmlPane.setCaretPosition(0); } catch (IOException ex) { logger.log(Level.WARNING, ex.getMessage()); } responseTextArea.setText(content); responseTextArea.setCaretPosition(0); responseTextArea.requestFocus(); }
From source file:fedroot.dacs.swingdemo.DacsClientFrame.java
/** * Sets the HTML content to be displayed. * * @param content an HTML document string *//*from w w w . j av a 2 s . com*/ private void setDocumentContent(String contenttype, String content) { HTMLDocument doc = new HTMLDocument(); try { doc.remove(0, doc.getLength()); } catch (BadLocationException e) { e.printStackTrace(); } doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE); try { htmlPane.setContentType(contenttype); htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc); htmlPane.setDocument(doc); htmlPane.setCaretPosition(0); } catch (IOException e) { e.printStackTrace(); } responseTextArea.setText(content); responseTextArea.setCaretPosition(0); responseTextArea.requestFocus(); }
From source file:EditorPaneExample16.java
public HTMLDocument loadDocument(HTMLDocument doc, URL url, String charSet) throws IOException { doc.putProperty(Document.StreamDescriptionProperty, url); /*// w w w . j a v a2 s. c o m * This loop allows the document read to be retried if the character * encoding changes during processing. */ InputStream in = null; boolean ignoreCharSet = false; for (;;) { try { // Remove any document content doc.remove(0, doc.getLength()); URLConnection urlc = url.openConnection(); in = urlc.getInputStream(); Reader reader = (charSet == null) ? new InputStreamReader(in) : new InputStreamReader(in, charSet); HTMLEditorKit.Parser parser = getParser(); HTMLEditorKit.ParserCallback htmlReader = getParserCallback(doc); parser.parse(reader, htmlReader, ignoreCharSet); htmlReader.flush(); // All done break; } catch (BadLocationException ex) { // Should not happen - throw an IOException throw new IOException(ex.getMessage()); } catch (ChangedCharSetException e) { // The character set has changed - restart charSet = getNewCharSet(e); // Prevent recursion by suppressing further exceptions ignoreCharSet = true; // Close original input stream in.close(); // Continue the loop to read with the correct encoding } } return doc; }