List of usage examples for com.google.gwt.user.client Event setEventListener
public static void setEventListener(Element elem, EventListener listener)
From source file:com.dianaui.universal.core.client.ui.DateTimePicker.java
License:Apache License
@Override protected void onShow() { container.clear();/*from w w w. j a va2s .c o m*/ if (dateEnabled && timeEnabled) { UnorderedList list = new UnorderedList(); list.setStyleName(Styles.LIST_UNSTYLED); if (dateCollapse == null) { dateCollapse = new Collapse(LIElement.TAG); initDateContainer(); dateCollapse.add(dateContainer); } if (timeCollapse == null) { timeCollapse = new Collapse(LIElement.TAG); timeCollapse.setToggle(false); initTimeContainer(); timeCollapse.add(timeContainer); } AnchorListItem switchItem = new AnchorListItem(); switchItem.setStyleName(Styles.DATETIMEPICKER_SWITCH); switchItem.setGlyphicon(GlyphiconType.TIME); switchItem.getAnchor().setStyleName(Styles.BTN); switchItem.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { days.setDate(CalendarUtil.copyDate(value)); time.setDate(CalendarUtil.copyDate(value)); dateCollapse.toggle(); timeCollapse.toggle(); } }); list.add(dateCollapse); list.add(switchItem); list.add(timeCollapse); container.add(list); days.setDate(CalendarUtil.copyDate(value)); } else if (dateEnabled) { initDateContainer(); container.add(dateContainer); days.setDate(CalendarUtil.copyDate(value)); } else { initTimeContainer(); container.add(timeContainer); time.setDate(CalendarUtil.copyDate(value)); } Event.setEventListener(getElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt() && event.getEventTarget().equals(getElement())) { hide(); } } }); setVisible(true); super.onShow(); }
From source file:com.dianaui.universal.core.client.ui.TimePicker.java
License:Apache License
@Override protected void onShow() { initContainer();/* w ww . j ava 2 s .c o m*/ // redraw inputs setValue(value != null ? value : new Date()); Event.setEventListener(getElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt() && event.getEventTarget().equals(getElement())) hide(); } }); container.addStyleName(Styles.OPEN); super.onShow(); }
From source file:com.github.gwtcannonjs.demo.client.impl.RaycastVehicleDemo.java
License:Open Source License
@Override public void run() { final Demo demo = CANNON.newDemo(); final double mass = 150; demo.addScene("car", new AddSceneCallback() { @Override/*from www .j a va 2 s .c om*/ public void execute() { World world = demo.getWorld(); world.setBroadphase(CANNON.newSAPBroadphase(world)); world.getGravity().set(0, 0, -10); world.getDefaultContactMaterial().setFriction(0); Material groundMaterial = CANNON.newMaterial("groundMaterial"); Material wheelMaterial = CANNON.newMaterial("wheelMaterial"); ContactMaterial wheelGroundContactMaterial = /* window.wheelGroundContactMaterial = */ CANNON .newContactMaterial(wheelMaterial, groundMaterial, CANNON.newContactMaterialOptions() .withFriction(0.3).withRestitution(0).withContactEquationStiffness(1000)); // We must add the contact materials to the world world.addContactMaterial(wheelGroundContactMaterial); Shape chassisShape; chassisShape = CANNON.newBox(CANNON.newVec3(2, 1, 0.5)); Body chassisBody = CANNON.newBody(CANNON.newBodyOptions().withMass(mass)); chassisBody.addShape(chassisShape); chassisBody.getPosition().set(0, 0, 4); chassisBody.getAngularVelocity().set(0, 0, 0.5); demo.addVisual(chassisBody); WheelInfoOptions options = CANNON.newWheelInfoOptions().withRadius(0.5) .withDirectionLocal(CANNON.newVec3(0, 0, -1)).withSuspensionStiffness(30) .withSuspensionRestLength(0.3).withFrictionSlip(5).withDampingRelaxation(2.3) .withDampingCompression(4.4).withMaxSuspensionForce(100000).withRollInfluence(0.01) .withAxleLocal(CANNON.newVec3(0, 1, 0)) .withChassisConnectionPointLocal(CANNON.newVec3(1, 1, 0)).withMaxSuspensionTravel(0.3) .withCustomSlidingRotationalSpeed(-30).withUseCustomSlidingRotationalSpeed(true); // Create the vehicle final RaycastVehicle vehicle = CANNON .newRaycastVehicle(CANNON.newRaycastVehicleOptions().withChassisBody(chassisBody)); options.getChassisConnectionPointLocal().set(1, 1, 0); vehicle.addWheel(options); options.getChassisConnectionPointLocal().set(1, -1, 0); vehicle.addWheel(options); options.getChassisConnectionPointLocal().set(-1, 1, 0); vehicle.addWheel(options); options.getChassisConnectionPointLocal().set(-1, -1, 0); vehicle.addWheel(options); vehicle.addToWorld(world); final JsArray<Body> wheelBodies = JsArray.createArray().cast(); for (int i = 0; i < vehicle.getWheelInfos().length(); i++) { WheelInfo wheel = vehicle.getWheelInfos().get(i); Cylinder cylinderShape = CANNON.newCylinder(wheel.getRadius(), wheel.getRadius(), wheel.getRadius() / 2, 20); Body wheelBody = CANNON.newBody(CANNON.newBodyOptions().withMass(1)); Quaternion q = CANNON.newQuaternion(); q.setFromAxisAngle(CANNON.newVec3(1, 0, 0), Math.PI / 2); wheelBody.addShape(cylinderShape, CANNON.newVec3(), q); wheelBodies.push(wheelBody); demo.addVisual(wheelBody); } // Update wheels world.addEventListener("postStep", new com.github.gwtcannonjs.client.utils.EventListener() { public void onEvent(com.github.gwtcannonjs.client.utils.Event event) { for (int i = 0; i < vehicle.getWheelInfos().length(); i++) { Transform t = vehicle.getWheelInfos().get(i).getWorldTransform(); wheelBodies.get(i).getPosition().copy(t.getPosition()); wheelBodies.get(i).getQuaternion().copy(t.getQuaternion()); } } }); JsArray<JsArrayNumber> matrix = JsArray.createArray().cast(); double sizeX = 64, sizeY = 64; for (int i = 0; i < sizeX; i++) { matrix.push((JsArrayNumber) JsArray.createArray().cast()); for (int j = 0; j < sizeY; j++) { double height = Math.cos(i / sizeX * Math.PI * 5) * Math.cos(j / sizeY * Math.PI * 5) * 2 + 2; if (i == 0 || i == sizeX - 1 || j == 0 || j == sizeY - 1) height = 3; matrix.get(i).push(height); } } Heightfield hfShape = CANNON.newHeightfield(matrix, CANNON.newHeightfieldOptions().withElementSize(100 / sizeX)); Body hfBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0)); hfBody.addShape(hfShape); hfBody.getPosition().set(-sizeX * hfShape.getElementSize() / 2, -sizeY * hfShape.getElementSize() / 2, -1); world.addBody(hfBody); demo.addVisual(hfBody); Event.sinkEvents(Document.get().getDocumentElement(), Event.ONKEYDOWN | Event.ONKEYUP); Event.setEventListener(Document.get().getDocumentElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { switch (event.getTypeInt()) { case Event.ONKEYDOWN: case Event.ONKEYUP: handler(event, vehicle); break; } } }); } }); demo.start(); }
From source file:com.github.gwtcannonjs.demo.client.impl.RigidVehicleDemo.java
License:Open Source License
@Override public void run() { final Demo demo = CANNON.newDemo(); final double mass = 1; demo.addScene("car", new AddSceneCallback() { @Override//from w w w . j av a 2 s .c o m public void execute() { World world = demo.getWorld(); world.getGravity().set(0, 0, -30); world.setBroadphase(CANNON.newSAPBroadphase(world)); world.getDefaultContactMaterial().setFriction(0.2); Material groundMaterial = CANNON.newMaterial("groundMaterial"); Material wheelMaterial = CANNON.newMaterial("wheelMaterial"); ContactMaterial wheelGroundContactMaterial = CANNON.newContactMaterial(wheelMaterial, groundMaterial, CANNON.newContactMaterialOptions().withFriction(0.3).withRestitution(0) .withContactEquationStiffness(1000)); // We must add the contact materials to the world world.addContactMaterial(wheelGroundContactMaterial); Shape chassisShape; Vec3 centerOfMassAdjust = CANNON.newVec3(0, 0, -1); chassisShape = CANNON.newBox(CANNON.newVec3(5, 2, 0.5)); Body chassisBody = CANNON.newBody(CANNON.newBodyOptions().withMass(1)); chassisBody.addShape(chassisShape, centerOfMassAdjust); chassisBody.getPosition().set(0, 0, 0); // Create the vehicle final RigidVehicle vehicle = CANNON .newRigidVehicle(CANNON.newRigidVehicleOptions().withChassisBody(chassisBody)); double axisWidth = 7; Shape wheelShape = CANNON.newSphere(1.5); Vec3 down = CANNON.newVec3(0, 0, -1); Body wheelBody = CANNON.newBody(CANNON.newBodyOptions().withMass(mass).withMaterial(wheelMaterial)); wheelBody.addShape(wheelShape); vehicle.addWheel(CANNON.newRigidVehicleOptions().withBody(wheelBody) .withPosition(CANNON.newVec3(5, axisWidth / 2, 0).vadd(centerOfMassAdjust, null)) .withAxis(CANNON.newVec3(0, 1, 0)).withDirection(down)); wheelBody = CANNON.newBody(CANNON.newBodyOptions().withMass(mass).withMaterial(wheelMaterial)); wheelBody.addShape(wheelShape); vehicle.addWheel(CANNON.newRigidVehicleOptions().withBody(wheelBody) .withPosition(CANNON.newVec3(5, -axisWidth / 2, 0).vadd(centerOfMassAdjust, null)) .withAxis(CANNON.newVec3(0, -1, 0)).withDirection(down)); wheelBody = CANNON.newBody(CANNON.newBodyOptions().withMass(mass).withMaterial(wheelMaterial)); wheelBody.addShape(wheelShape); vehicle.addWheel(CANNON.newRigidVehicleOptions().withBody(wheelBody) .withPosition(CANNON.newVec3(-5, axisWidth / 2, 0).vadd(centerOfMassAdjust, null)) .withAxis(CANNON.newVec3(0, 1, 0)).withDirection(down)); wheelBody = CANNON.newBody(CANNON.newBodyOptions().withMass(mass).withMaterial(wheelMaterial)); wheelBody.addShape(wheelShape); vehicle.addWheel(CANNON.newRigidVehicleOptions().withBody(wheelBody) .withPosition(CANNON.newVec3(-5, -axisWidth / 2, 0).vadd(centerOfMassAdjust, null)) .withAxis(CANNON.newVec3(0, -1, 0)).withDirection(down)); // Some damping to not spin wheels too fast for (int i = 0; i < vehicle.getWheelBodies().length(); i++) { vehicle.getWheelBodies().get(i).setAngularDamping(0.4); } // Add visuals demo.addVisual(vehicle.getChassisBody()); for (int i = 0; i < vehicle.getWheelBodies().length(); i++) { demo.addVisual(vehicle.getWheelBodies().get(i)); } vehicle.addToWorld(world); boolean mock = false; JsArray<JsArrayNumber> matrix = JsArray.createArray().cast(); double sizeX = 64, sizeY = sizeX; for (int i = 0; i < sizeX; i++) { matrix.push((JsArrayNumber) JsArray.createArray().cast()); for (int j = 0; j < sizeY; j++) { double height = Math.sin(i / sizeX * Math.PI * 8) * Math.sin(j / sizeY * Math.PI * 8) * 8 + 8; if (i == 0 || i == sizeX - 1 || j == 0 || j == sizeY - 1) height = 10; matrix.get(i).push(height); } } Heightfield hfShape = CANNON.newHeightfield(matrix, CANNON.newHeightfieldOptions().withElementSize(300 / sizeX)); Body hfBody; Quaternion quat = CANNON.newQuaternion(); Vec3 pos = CANNON.newVec3(-sizeX * hfShape.getElementSize() / 2, -20, -20); // Use normal hfBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0).withMaterial(groundMaterial)); hfBody.addShape(hfShape, CANNON.newVec3(0, 0, -1), CANNON.newQuaternion()); hfBody.getPosition().copy(pos); hfBody.getQuaternion().copy(quat); if (!mock) { world.addBody(hfBody); demo.addVisual(hfBody); } if (mock) { for (int i = 0; i < sizeX - 1; i++) { for (int j = 0; j < sizeY - 1; j++) { for (int k = 0; k < 2; k++) { hfShape.getConvexTrianglePillar(i, j, k != 0); Body convexBody = CANNON .newBody(CANNON.newBodyOptions().withMass(0).withMaterial(groundMaterial)); convexBody.addShape(hfShape.getPillarConvex()); hfBody.pointToWorldFrame(hfShape.getPillarOffset(), convexBody.getPosition()); world.addBody(convexBody); demo.addVisual(convexBody); } } } } Event.sinkEvents(Document.get().getDocumentElement(), Event.ONKEYDOWN | Event.ONKEYUP); Event.setEventListener(Document.get().getDocumentElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { switch (event.getTypeInt()) { case Event.ONKEYDOWN: case Event.ONKEYUP: handler(event, vehicle); break; } } }); } }); demo.start(); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.window.CubaWindowWidget.java
License:Apache License
public CubaWindowWidget() { DOM.sinkEvents(header, DOM.getEventsSunk(header) | Event.ONCONTEXTMENU); addStyleName(NONMODAL_WINDOW_CLASSNAME); Event.sinkEvents(getModalityCurtain(), Event.ONCLICK); Event.setEventListener(getModalityCurtain(), event -> { if (closeOnClickOutside) { if (clickOnModalityCurtain != null) { clickOnModalityCurtain.run(); }//from www. j a v a2 s .c o m } }); }
From source file:com.jythonui.client.dialog.util.BiWidget.java
License:Apache License
void addHelperButton() { if (fi == null || !fi.isHelper()) return;//from w ww . j a v a2 s. c o m verifyOp(OPTYPE.HELPER); PaperInput i = getPaperInput(); String he = fi.getHelper(); Element ele = i.getElementById(he); if (ele == null) Utils.errAlertB(iR.getD().getDialog().getId(), M.M().CannotFindElementById(ICommonConsts.HELPER, fi.getId(), he)); Event.sinkEvents(ele, Event.ONCLICK); Event.setEventListener(ele, e -> { if (e.getTypeInt() == Event.ONCLICK) iBus.publish(new ClickHelperEvent(), fi); }); }
From source file:com.lizardtech.djvu.DjVuPage.java
License:Open Source License
private GPixmap decodeJPEG(CachedInputStream iff) throws IOException { final GPixmap result = new GPixmap(); final Image image = new Image(); final ImageElement imageElement = image.getElement().cast(); imageElement.getStyle().setProperty("visibility", "hidden"); Event.setEventListener(imageElement, new EventListener() { @Override//from w w w . ja v a 2s .c om public void onBrowserEvent(Event event) { if (Event.ONLOAD == event.getTypeInt()) { final int w = imageElement.getWidth(), h = imageElement.getHeight(); final Canvas canvas = Canvas.createIfSupported(); canvas.setWidth(w + "px"); canvas.setCoordinateSpaceWidth(w); canvas.setHeight(h + "px"); canvas.setCoordinateSpaceHeight(h); canvas.getContext2d().drawImage(imageElement, 0, 0); result.init(h, w, null); result.setImageData(canvas.getContext2d().getImageData(0, 0, w, h)); } } }); StringBuilder data = new StringBuilder(); int b; while ((b = iff.read()) != -1) { data.append((char) b); } String dataURL = "data:image/jpeg;base64," + btoa(data.toString()); image.setUrl(dataURL); return result; }
From source file:com.urlisit.siteswrapper.cloud.utilities.UrleLoader.java
License:Apache License
private static void init() { if (loadingArea == null) { loadingArea = DOM.createDiv();/* ww w.jav a2 s .c o m*/ loadingArea.getStyle().setProperty("visibility", "hidden"); loadingArea.getStyle().setProperty("position", "absolute"); loadingArea.getStyle().setProperty("width", "1px"); loadingArea.getStyle().setProperty("height", "1px"); loadingArea.getStyle().setProperty("overflow", "hidden"); Document.get().getBody().appendChild(loadingArea); Event.setEventListener(loadingArea, new EventListener() { @Override public void onBrowserEvent(Event event) { boolean success; if (Event.ONLOAD == event.getTypeInt()) { success = true; } else if (Event.ONERROR == event.getTypeInt()) { success = false; } else { return; } if (!ImageElement.is(event.getCurrentEventTarget())) { return; } ImageElement image = ImageElement.as(Element.as(event.getCurrentEventTarget())); int index = findImageInPool(image); ImageLoader loader = activeLoaders.get(index); Dimensions dim = null; if (success) { dim = new Dimensions(image.getWidth(), image.getHeight()); dimensionCache.put(loader.url, dim); } else { dimensionCache.put(loader.url, new Dimensions(-1, -1)); } loadingArea.removeChild(image); activeLoaders.remove(index); ImageLoadEvent evt = new ImageLoadEvent(image, dim); loader.fireHandlers(evt); } }); } }
From source file:com.urlisit.siteswrapper.cloud.widgets.BackgroundImage.java
License:Apache License
/** * //from w w w.jav a2 s. co m */ public BackgroundImage(View view) { this.view = view; div = DOM.createDiv(); div.getStyle().setProperty("visibility", "hidden"); div.getStyle().setProperty("position", "absolute"); div.getStyle().setProperty("width", "1px"); div.getStyle().setProperty("height", "1px"); div.getStyle().setProperty("overflow", "hidden"); Document.get().getBody().appendChild(div); img = DOM.createImg().cast(); div.appendChild(img); Event.sinkEvents(img, Event.ONLOAD | Event.ONERROR); Event.setEventListener(div, this); img.setSrc(view.getPage().getBackgroundImageUrls(view.getLiterals().zero())); image = new Image(); image.setVisible(false); initWidget(image); view.getPanel().insert(this.asWidget(), 0, 0, 0); }
From source file:com.urlisit.siteswrapper.cloud.widgets.OldBackgroundImage.java
License:Apache License
public OldBackgroundImage(View view) { this.view = view; div = DOM.createDiv();/*from w ww.jav a 2 s. co m*/ div.getStyle().setProperty("visibility", "hidden"); div.getStyle().setProperty("position", "absolute"); div.getStyle().setProperty("width", "1px"); div.getStyle().setProperty("height", "1px"); div.getStyle().setProperty("overflow", "hidden"); Document.get().getBody().appendChild(div); img = DOM.createImg().cast(); div.appendChild(img); Event.sinkEvents(img, Event.ONLOAD | Event.ONERROR); Event.setEventListener(div, this); img.setSrc(view.getPage().getBackgroundImageUrls(view.getLiterals().zero())); image = new Image(); image.setVisible(false); view.getPanel().insert(image, 0, 0, 0); }