List of usage examples for com.google.gwt.user.client Event sinkEvents
public static void sinkEvents(Element elem, int eventBits)
From source file:com.dianaui.universal.core.client.ui.CheckBox.java
License:Apache License
@Override public void sinkEvents(final int eventBitsToAdd) { if (isOrWasAttached()) { Event.sinkEvents(inputElem, eventBitsToAdd | Event.getEventsSunk(inputElem)); } else {//from w w w . jav a 2 s . c om super.sinkEvents(eventBitsToAdd); } }
From source file:com.dianaui.universal.core.client.ui.CheckBoxButton.java
License:Apache License
@Override public void sinkEvents(int eventBitsToAdd) { // Sink on the actual element because that's what gets clicked if (isOrWasAttached()) { Event.sinkEvents(getElement(), eventBitsToAdd | Event.getEventsSunk(getElement())); } else {/*w w w .ja v a2 s . c o m*/ super.sinkEvents(eventBitsToAdd); } }
From source file:com.dianaui.universal.core.client.ui.Radio.java
License:Apache License
@Override public void sinkEvents(int eventBitsToAdd) { // Like CheckBox, we want to hear about inputElem. We // also want to know what's going on with the label, to // make sure onBrowserEvent is able to record value changes // initiated by label events if (isOrWasAttached()) { Event.sinkEvents(inputElem, eventBitsToAdd | Event.getEventsSunk(inputElem)); if (labelElem != null) Event.sinkEvents(labelElem, eventBitsToAdd | Event.getEventsSunk(labelElem)); } else {/*from www . j a v a 2 s .c o m*/ super.sinkEvents(eventBitsToAdd); } }
From source file:com.extjs.gxt.ui.client.widget.form.Radio.java
License:sencha.com license
private void replaceInputElement(Element elem) { InputElement newInputElem = InputElement.as(elem); int tabIndex = getTabIndex(); boolean checked = getValue(); boolean enabled = isEnabled(); String uid = input.getId();/* w ww . j a va2s. com*/ String accessKey = InputElement.as(input.dom).getAccessKey(); int sunkEvents = Event.getEventsSunk(input.dom); String styleName = input.getStyleName(); String valueAttribute = getValueAttribute(); getElement().replaceChild(newInputElem, input.dom); Event.sinkEvents(elem, 0); input = new El((Element) Element.as(newInputElem)); input.makePositionable(); Event.sinkEvents(input.dom, sunkEvents); input.setId(uid); if (!"".equals(accessKey)) { InputElement.as(input.dom).setAccessKey(accessKey); } setTabIndex(tabIndex); setValueAttribute(valueAttribute); setValue(checked); setEnabled(enabled); input.setStyleName(styleName); }
From source file:com.github.gwtbootstrap.client.ui.CheckBox.java
License:Apache License
@Override public void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { Event.sinkEvents(inputElem, eventBitsToAdd | Event.getEventsSunk(inputElem)); } else {//from w w w . ja v a2s .co m super.sinkEvents(eventBitsToAdd); } }
From source file:com.github.gwtbootstrap.client.ui.CheckBox.java
License:Apache License
/** * Replace the current input element with a new one. Preserves all state * except for the name property, for nasty reasons related to radio button * grouping. (See implementation of {@link RadioButton#setName}.) * /*w w w .java2 s . co m*/ * @param elem * the new input element */ protected void replaceInputElement(Element elem) { InputElement newInputElem = InputElement.as(elem); // Collect information we need to set int tabIndex = getTabIndex(); boolean checked = getValue(); boolean enabled = isEnabled(); String formValue = getFormValue(); String uid = inputElem.getId(); String accessKey = inputElem.getAccessKey(); int sunkEvents = Event.getEventsSunk(inputElem); // Clear out the old input element setEventListener(asOld(inputElem), null); getElement().replaceChild(newInputElem, inputElem); // Sink events on the new element Event.sinkEvents(elem, Event.getEventsSunk(inputElem)); Event.sinkEvents(inputElem, 0); inputElem = newInputElem; // Setup the new element Event.sinkEvents(inputElem, sunkEvents); inputElem.setId(uid); if (!"".equals(accessKey)) { inputElem.setAccessKey(accessKey); } setTabIndex(tabIndex); setValue(checked); setEnabled(enabled); setFormValue(formValue); // Set the event listener if (isAttached()) { setEventListener(asOld(inputElem), this); } }
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/* w ww . j a v a2s.c o m*/ 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 www. j a v a 2 s. co 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.google.gwt.sample.contacts.client.view.ContactsViewImpl.java
public void setRowData(List<T> rowData) { this.rowData = rowData; TableElement table = Document.get().createTableElement(); TableSectionElement tbody;// w w w . j a va 2 s . co m table.appendChild(tbody = Document.get().createTBodyElement()); for (int i = 0; i < rowData.size(); ++i) { TableRowElement row = tbody.insertRow(-1); T t = rowData.get(i); for (int j = 0; j < columnDefinitions.size(); ++j) { TableCellElement cell = row.insertCell(-1); StringBuilder sb = new StringBuilder(); columnDefinitions.get(j).render(t, sb); cell.setInnerHTML(sb.toString()); // TODO: Really total hack! There's gotta be a better way... Element child = cell.getFirstChildElement(); if (child != null) { Event.sinkEvents(child, Event.ONFOCUS | Event.ONBLUR); } } } contactsTable.setHTML(table.getInnerHTML()); }
From source file:com.googlecode.mgwt.ui.client.widget.input.radio.MRadioButton.java
License:Apache License
private void replaceInputElement(Element elem) { InputElement newInputElem = InputElement.as(elem); // Collect information we need to set boolean checked = getValue(); boolean enabled = isEnabled(); String formValue = getFormValue(); String uid = inputRadio.getId(); String accessKey = inputRadio.getAccessKey(); int sunkEvents = Event.getEventsSunk(inputRadio); // Clear out the old input element DOM.setEventListener(inputRadio, null); getElement().replaceChild(newInputElem, inputRadio); // Sink events on the new element Event.sinkEvents(elem, Event.getEventsSunk(inputRadio)); Event.sinkEvents(inputRadio, 0); inputRadio = newInputElem;//from w ww. j a v a 2s .c om // Setup the new element Event.sinkEvents(inputRadio, sunkEvents); inputRadio.setId(uid); if (!"".equals(accessKey)) { inputRadio.setAccessKey(accessKey); } setValue(checked); setEnabled(enabled); setFormValue(formValue); // Set the event listener if (isAttached()) { DOM.setEventListener(inputRadio, this); } }