List of usage examples for com.google.gwt.core.client ScriptInjector fromString
public static FromString fromString(String scriptBody)
From source file:com.github.gwtcannonjs.demo.client.impl.BunnyDemo.java
License:Open Source License
@Override public void run() { ScriptInjector.fromString(BunnyResource.INSTANCE.source().getText()).inject(); final Demo demo = CANNON.newDemo(); demo.addScene("Bunny", new AddSceneCallback() { @Override/* w ww . ja v a 2s . com*/ public void execute() { World world = demo.getWorld(); world.getGravity().set(0, 0, -20); world.setBroadphase(CANNON.newNaiveBroadphase()); ((GSSolver) world.getSolver().cast()).setIterations(20); world.getDefaultContactMaterial().setContactEquationStiffness(1e10); world.getDefaultContactMaterial().setContactEquationRelaxation(10); JsArray<CustomPolyhedron> bunny = getBunny(); Body bunnyBody = CANNON.newBody(CANNON.newBodyOptions().withMass(1)); for (int i = 0; i < bunny.length(); i++) { JsArrayNumber rawVerts = bunny.get(i).getVertices(); JsArrayNumber rawFaces = bunny.get(i).getFaces(); JsArrayNumber rawOffset = bunny.get(i).getOffset(); JsArray<Vec3> verts = JsArray.createArray().cast(); JsArray<JsArrayInteger> faces = JsArray.createArray().cast(); Vec3 offset; // Get vertices for (int j = 0; j < rawVerts.length(); j += 3) { verts.push(CANNON.newVec3(rawVerts.get(j), rawVerts.get(j + 1), rawVerts.get(j + 2))); } // Get faces for (int j = 0; j < rawFaces.length(); j += 3) { JsArrayInteger face = JsArray.createArray().cast(); face.push((int) rawFaces.get(j)); face.push((int) rawFaces.get(j + 1)); face.push((int) rawFaces.get(j + 2)); faces.push(face); } // Get offset offset = CANNON.newVec3(rawOffset.get(0), rawOffset.get(1), rawOffset.get(2)); // Construct polyhedron Shape bunnyPart = CANNON.newConvexPolyhedron(verts, faces); // Add to compound bunnyBody.addShape(bunnyPart, offset); } // Create body bunnyBody.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), -Math.PI / 2); Quaternion z180 = CANNON.newQuaternion(); z180.setFromAxisAngle(CANNON.newVec3(0, 0, 1), Math.PI); bunnyBody.setQuaternion(z180.mult(bunnyBody.getQuaternion(), null)); world.addBody(bunnyBody); demo.addVisual(bunnyBody); // ground plane Shape groundShape = CANNON.newPlane(); Body groundBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0)); groundBody.addShape(groundShape); groundBody.getPosition().set(0, 0, -5); world.addBody(groundBody); demo.addVisual(groundBody); } }); demo.start(); }
From source file:com.google.gerrit.client.Gerrit.java
License:Apache License
private void loadPlugins(HostPageData hpd, final String token) { if (hpd.plugins != null) { for (final String url : hpd.plugins) { ScriptInjector.fromUrl(url).setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { }/*from ww w. j a v a 2 s . co m*/ @Override public void onFailure(Exception reason) { ErrorDialog d = new ErrorDialog(reason); d.setTitle(M.pluginFailed(url)); d.center(); } }).inject(); } } CallbackHandle<Void> cb = new CallbackHandle<Void>(new ResultDeserializer<Void>() { @Override public Void fromResult(JavaScriptObject responseObject) { return null; } }, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { display(token); } }); cb.install(); ScriptInjector.fromString(cb.getFunctionName() + "();").setWindow(ScriptInjector.TOP_WINDOW).inject(); }
From source file:com.googlecode.google_code_prettify.GoogleCodePrettifyUtil.java
License:Open Source License
public static void run() { bundle.prettifyCss().ensureInjected(); if (!injected) { ScriptInjector.fromString(bundle.prettifyJavaScript().getText()).setWindow(window()).inject(); injected = true;// ww w . j a v a2 s. co m } ProfileGinjector.get.instance().getScheduler().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { doPrettify(); } }); }
From source file:com.himamis.retex.renderer.web.font.opentype.Opentype.java
License:Open Source License
private Opentype() { ScriptInjector.fromString(JsResources.INSTANCE.opentypeJs().getText()).setRemoveTag(false).inject(); listeners = new ArrayList<OpentypeFontStatusListener>(); fonts = new HashMap<String, FontContainer>(); }
From source file:com.hydro4ge.raphaelgwt.client.Injector.java
License:Apache License
static public void ensureInjected() { if (!loaded) { loaded = true;//from w ww . ja v a 2 s . c o m JsResources bundle = GWT.create(JsResources.class); JsPicker picker = GWT.create(JsPicker.class); ScriptInjector.fromString(picker.pick(bundle).getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); } }
From source file:com.mecatran.otp.gwt.client.PlannerWidgetEntryPoint.java
License:Open Source License
@Override public void onModuleLoad() { /* Check for config */ config = getConfig();//from ww w.j a va 2s .com if (config == null) { Window.alert("Unable to find JS object widget config 'otpPlannerWidgetConfig' in host page."); return; } /* Check for root panel where we want to insert the widget. */ RootPanel mapPanel = RootPanel.get(config.getWidgetDivId()); if (mapPanel == null) { Window.alert("Unable to find <div id='" + config.getWidgetDivId() + "'> in host page."); return; } /* Load javascript libraries. */ ScriptInjector.fromString(PlannerResources.INSTANCE.gwtOpenLayersUtilsJs().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); /* Note: must load OSM after OpenLayers */ ScriptInjector.fromString(PlannerResources.INSTANCE.gwtOpenStreetMapJs().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); PlannerResources.INSTANCE.css().ensureInjected(); mapPanel.clear(); /* Create a controller and get it's widget onto the root panel */ PlannerController controller = new PlannerController(getConfig()); mapPanel.add(controller.getPlannerWidget()); /* If parameters where provided, try to restore state */ Map<String, List<String>> parameters = Window.Location.getParameterMap(); if (parameters.size() > 0) { controller.restoreState(new PlannerState(parameters)); } /* Display dialog box if config has set a message. */ showIntroDialogBox(); }
From source file:com.wso2.jsplumb.client.injectors.ScriptInjectorHelper.java
License:Open Source License
public static void injectScript() { ScriptInjector.fromString(JsClientBundle.INSTANCE.jquerysource().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); ScriptInjector.fromString(JsClientBundle.INSTANCE.jqueryuimin().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); ScriptInjector.fromString(JsClientBundle.INSTANCE.jsplumbsource().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); ScriptInjector.fromString(JsClientBundle.INSTANCE.gwtresource().getText()) .setWindow(ScriptInjector.TOP_WINDOW).inject(); }
From source file:de.fhrt.codenvy.bpmn.editor.widget.diagram.BpmnEditorDiagramWidget.java
License:Open Source License
private void initDiagramSourceWidget() { ScriptInjector.fromString(bpmnResource.codemirrorModeXml().getText()).setWindow(ScriptInjector.TOP_WINDOW) .inject();/* w w w.ja va 2s. c o m*/ cmWidget = new BpmnEditorSourceWidget("xml", "codenvy"); cmWidget.setEnabled(false); }
From source file:de.fhrt.codenvy.bpmn.editor.widget.diagram.BpmnEditorDiagramWidget.java
License:Open Source License
@Override protected void onAttach() { super.onAttach(); Log.info(BpmnEditorDiagramWidget.class, "onAttach"); ScriptInjector.fromString(bpmnResource.bpmnIoIndexJsFile().getText()).setWindow(ScriptInjector.TOP_WINDOW) .setRemoveTag(false).inject(); bpmnIoModelerJso = BpmnIoModelerJso.nativeCreateInstance(diagramHtmlWrapperId, this); }
From source file:gwt.material.design.addins.client.MaterialResourceInjector.java
License:Apache License
public static void injectJs(TextResource resource, final boolean removeTag, boolean sourceUrl, boolean isScheduleDeferred) { final String text = resource.getText() + (sourceUrl ? "//# sourceURL=" + resource.getName() + ".js" : ""); if (isScheduleDeferred) { Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { @Override/*from w w w . ja v a2s. co m*/ public void execute() { // Inject the script resource ScriptInjector.fromString(text).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(removeTag) .inject(); } }); } else { ScriptInjector.fromString(text).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(removeTag).inject(); } }