java - Can't show HTML + SVG -
i used use jeditorpane
, can display html, cannot display svg, , nested svg html cannot complete display.
then use jsvgcanvas
, can display svg, cannot display html.
is there way solve problem?
configure jeditorpane
use jsvgcanvas
canvas svg. achieve that, need specialist htmleditorkit
. here htlmeditorkit
of appleteer.
package org.pscode.ui.applet.appleteer; import java.awt.component; import java.awt.dimension; // placeholder component import javax.swing.jbutton; import javax.swing.text.html.html; import javax.swing.text.html.htmleditorkit; import javax.swing.text.view; import javax.swing.text.componentview; import javax.swing.text.plainview; import javax.swing.text.viewfactory; import javax.swing.text.element; import javax.swing.text.attributeset; import javax.swing.text.styleconstants; import org.pscode.ui.applet.appleteer.appletelement; import org.pscode.ui.applet.appleteer.appletloadercontainer; import java.util.hashmap; import java.util.enumeration; import java.net.url; import java.util.logging.*; /** appleteditorkit extends htmleditorkit support applet element. */ public class appleteditorkit extends htmleditorkit { url documentbase; pseudobrowser browser; static int appletcount; static boolean hasnamedapplet; public appleteditorkit(url documentbase, pseudobrowser browser) { this.documentbase = documentbase; this.browser = browser; appletcount = 0; hasnamedapplet = false; } public viewfactory getviewfactory() { return new applethtmlfactory(documentbase, browser); } public static class applethtmlfactory extends htmlfactory implements viewfactory { url documentbase; pseudobrowser browser; applethtmlfactory(url documentbase, pseudobrowser browser) { this.documentbase = documentbase; this.browser = browser; } public view create(element element) { attributeset set = element.getattributes(); object o = element.getattributes().getattribute(styleconstants.nameattribute); if (o instanceof html.tag) { html.tag kind = (html.tag) o; logger.getlogger("appleteer").log( level.finest, "aek.c html.tag: " + kind); if (kind == html.tag.applet ) { if(!contains(element.getattributes().getattributenames(),"endtag")) { view view; try { appletelement ae = new appletelement( element, browser, "applet" + appletcount++); view = new appletview(ae); if ( ae.getname()!=null ) { hasnamedapplet = true; } } catch(exception e) { return new plainview(element); } return view; } else { return new plainview(element); //return null; } } else if (kind == html.tag.param) { logger.getlogger("appleteer").log( level.finest, "html param: " + kind); } } return super.create( element ); } } public static boolean contains(enumeration en, string name) { while( en.hasmoreelements() ) { object o = en.nextelement(); if (o instanceof html.attribute) { logger.getlogger("appleteer").log( level.finest, "html.attribute: " + 0); if (o.tostring().equals(name)) { return true; } } } return false; } }
Comments
Post a Comment