class RaphaelJS extends JavaScriptObject { protected static class Shape extends JavaScriptObject { public final native Shape rotate(double degree, boolean abs) /*-{ return this.rotate(degree, abs); }-*/; public final native Shape scale(double sx, double sy) /*-{ return this.scale(sx, sy); }-*/; public final native Shape translate(double dx, double dy) /*-{ return this.translate(dx, dy); }-*/; // ... } /** * factory method */ static public final native RaphaelJS create(Element e, int w, int h) /*-{ return $wnd.Raphael(e, w, h); }-*/; public final native Element node() /*-{ return this.node; }-*/; public final native Shape circle(double x, double y, double r) /*-{ return this.circle(x,y,r); }-*/; public final native Shape rect(double x, double y, double w, double h) /*-{ return this.rect(x, y, w, h); }-*/; // ... }
public class Raphael extends Widget { private RaphaelJS overlay; public class Shape extends Widget { protected RaphaelJS.Shape rs; protected Shape(RaphaelJS.Shape s) { setElement(s.node()); rs = s; } public Shape rotate(double degree, boolean isAbsolute) { rs.rotate(degree, isAbsolute); return this; } public Shape scale(double sx, double sy) { rs.scale(sx, sy); return this; } public Shape translate(double dx, double dy) { rs.translate(dx, dy); return this; } // ... } public class Circle extends Shape { public Circle(double x, double y, double r) { super(overlay.circle(x, y, r)); } } public class Rectangle extends Shape { public Rectangle(double x, double y, double w, double h) { super(overlay.rect(x, y, w, h)); } public Rectangle(double x, double y, double w, double h, double r) { super(overlay.rect(x, y, w, h, r)); } } public class Text extends Shape { public Text(double x, double y, String str) { super(overlay.text(x, y, str)); } } // ... public Raphael(int width, int height) { Element raphaelDiv = DOM.createDiv(); setElement(raphaelDiv); overlay = RaphaelJS.create(raphaelDiv, width, height); } }
public class MyDrawing extends Raphael { public MyDrawing(int width, int height) { super(width, height); Circle c = new Circle(width/2, height/2, 20); // Raphael automatically appends the Circle to this drawing } } public class MyApp implements EntryPoint { public void onModuleLoad() { MyDrawing d = new MyDrawing(Window.getClientWidth(), Window.getClientHeight()); RootPanel.get().add(d); } }
public class SelectRoleHandler implements DatabaseRequest.Handler { public void handle(DatabaseRequest.Result result) { for (int row=0; row < result.getRowCount(); row++) { JSONObject data_row = result.getRowValues(row); Role r = new Role(data_row); // process role... } } }
public class SelectRoleCallback implements RequestCallback { public void onError(Request request, Throwable exception) { Window.alert("Couldn't retrieve JSON"); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { JSONArray data_set = JSONParser.parse(response.getText()).isArray(); if (data_set != null) { for (int row=0; row < data_set.size(); row++) { JSONObject data_row = data_set.get(row).isObject(); Role r = new Role(data_row); // process role... } } } else { Window.alert("Couldn't retrieve JSON (" + response.getStatusText() + ")"); } } }