private static void checkImages() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { public void run() { HTMLEditorKit c = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); try { c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0); } catch (Exception e) { throw new RuntimeException("The test failed", e); } Element elem = doc.getElement("test"); ImageView iv = new ImageView(elem); if (iv.getLoadingImageIcon() == null) { throw new RuntimeException("getLoadingImageIcon returns null"); } if (iv.getNoImageIcon() == null) { throw new RuntimeException("getNoImageIcon returns null"); } } }); }
@Override public ViewFactory getViewFactory() { return new HTMLFactory() { @Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView) view).setLoadsSynchronously(true); } return view; } }; }
@Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView)view).setLoadsSynchronously(true); } return view; }
public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView)view).setLoadsSynchronously(true); } return view; }
public View create(Element elem) { View result; result = oldFactory.create(elem); if (result instanceof ImageView) { String src = (String)elem.getAttributes(). getAttribute(HTML.Attribute.SRC); if ("res:".equals(src.substring(0, 4))) { result = new NewImageView(elem); } } return result; }
private boolean canBePaintedSafely(View delegate) { if (delegate instanceof ImageView && hasNoImage((ImageView) delegate)) { return false; } return true; }
public ViewFactory getViewFactory() { return new HTMLFactory() { public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView)view).setLoadsSynchronously(true); } return view; } }; }
/** * <p>setHTMLEditorKit.</p> * * @param editorPane a {@link javax.swing.JEditorPane} object. */ static public void setHTMLEditorKit(JEditorPane editorPane) { editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written. // Extend all this shit to cache images. editorPane.setEditorKit(new HTMLEditorKit() { private static final long serialVersionUID = -562969765076450440L; public ViewFactory getViewFactory() { return new HTMLFactory() { public View create(Element elem) { Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); if (o instanceof HTML.Tag) { HTML.Tag kind = (HTML.Tag) o; if (kind == HTML.Tag.IMG) return new ImageView(elem) { public URL getImageURL() { URL url = super.getImageURL(); // Put an image into the cache to be read by other ImageView methods. if (url != null && imageCache.get(url) == null) try { imageCache.put(url.toURI(), Toolkit.getDefaultToolkit().createImage(url)); } catch (URISyntaxException e) { } return url; } }; } return super.create(elem); } }; } }); }
private boolean hasNoImage(ImageView delegate) { return delegate.getImage() == null; }