I would like to make some really simple overlay classes in GWT to wrap some SVG stuff. I would like to get a rectangle, here is how I do it in javascript:
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('width', '100%'); svg.setAttribute('height', '100%'); document.body.appendChild(svg); var rect = document.createElementNS('http://www.w3.org/2000/svg','rect'); rect.setAttribute("width","300"); rect.setAttribute("height","100"); svg.appendChild(rect);
and now itβs hard for me to translate this to GWT. I was hoping I could make a very subtle overlay around all these calls, something like this:
public class SVGPanel extends JavaScriptObject { protected SVGPanel() {} public static native SVGPanel create(String width, String height) ; } public MyProject implements EntryPoint { public void onModuleLoad() { SVGPanel panel = SVGPanel.create("100%", "100%"); Document.get().getBody().appendChild(panel); } }
yes, but I donβt understand how we can move from the javascript representation of SVG material to the GWT Java classes. First, the SVGPanel class extends JavaScriptObject, but I can't just add it to the Document body class because it expects the element type. If someone could just point out the right way to make this bridge, I would have to leave after that.
Also, I'm not sure if this is the best way to include some simple SVG classes, should I mimic them using DOM classes instead of trying to use JSNI?
thanks
source share