Example usage for com.google.gwt.user.client EventListener EventListener

List of usage examples for com.google.gwt.user.client EventListener EventListener

Introduction

In this page you can find the example usage for com.google.gwt.user.client EventListener EventListener.

Prototype

EventListener

Source Link

Usage

From source file:bz.davide.dmweb.shared.view.DMWidgetEventAttachHandler.java

License:Open Source License

@Override
public void onAttachOrDetach(AttachEvent event) {
    if (event.isAttached()) {
        DOM.sinkEvents(this.widget.getElement(), this.widget.eventBits);
        DOM.setEventListener(this.widget.getElement(), new EventListener() {
            @Override/*from w w w .  ja v  a  2s. co m*/
            public void onBrowserEvent(Event event) {
                DMWidgetEventAttachHandler.this.widget.onBrowserEvent(event);
            }
        });
    } else {
        DOM.setEventListener(this.widget.getElement(), null);
    }
}

From source file:ca.concordia.ivocab.client.PageTransitionPanel.java

License:Apache License

/**
 * Attaches an EventListener to the resize event on the Window.
 *//*w w  w .  ja va  2 s . c o m*/
private void hookResizeListener() {
    DomUtils.getWindow().addResizeListener(new EventListener() {
        public void onBrowserEvent(Event event) {
            doResize();
        }
    });
}

From source file:client.net.sf.saxon.ce.Xslt20ProcessorImpl.java

License:Mozilla Public License

private void registerEventHandlers(Controller controller) throws XPathException {
    // add an event listener to capture registered event modes
    if (registeredEventModes != null) {
        return;/*from w  w w  . j a va2 s  .co  m*/
    }
    Element docElement = (com.google.gwt.user.client.Element) (Object) Document.get();
    registeredEventModes = controller.getRuleManager().getModesInNamespace(NamespaceConstant.IXSL);
    // Restriction: only one event listener per element
    if (registeredEventModes.size() > 0 && !registeredForEvents) {
        registeredForEvents = true;
        registerNonDOMevents(controller);
        if (DOM.getEventListener((com.google.gwt.user.client.Element) docElement) == null) {
            principleEventListener = true;
            DOM.setEventListener((com.google.gwt.user.client.Element) docElement, new EventListener() {
                public void onBrowserEvent(Event event) {

                    EventTarget eTarget = event.getEventTarget();
                    Node eventNode;
                    if (Node.is(eTarget)) {
                        eventNode = Node.as(eTarget);
                    } else {
                        eventNode = Node.as(getCorrespondingSVGElement(eTarget));
                        if (eventNode == null) {
                            return;
                        }
                    }
                    bubbleApplyTemplates(eventNode, event);
                }
            });
        } else {
            // can't register for event so register for relayEvent
            Controller.addEventProcessor(this);
        }
    }
    // Events for all processor instances may register 1 or more event types
    for (Mode eventMode : registeredEventModes) {
        String eventName = eventMode.getModeName().getLocalName();
        if (!eventName.startsWith("on")) {
            logger.warning("Event name: '" + eventName + "' is invalid - names should begin with 'on'");
        } else {
            eventName = eventName.substring(2);
        }
        int eventNo = Event.getTypeInt(eventName);
        DOM.sinkEvents((com.google.gwt.user.client.Element) docElement,
                eventNo | DOM.getEventsSunk((com.google.gwt.user.client.Element) docElement));

    }

}

From source file:com.dianaui.universal.core.client.ui.DateTimePicker.java

License:Apache License

@Override
protected void onShow() {
    container.clear();//from   w  ww. j  a  v  a  2  s  . com

    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();//from   w  ww . j a  va2  s .  co  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.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** @Returns if it worked */
public static boolean attachHandler(String elementName, final int eventTypes, final EventCallback callback) {
    boolean result = false;
    Element e = (Element) Document.get().getElementById(elementName);
    if (e != null) {
        DOM.sinkEvents(e, eventTypes);/*  w w w.  j av a 2  s . co  m*/
        DOM.setEventListener(e, new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
                if (callback != null)
                    callback.onEvent(event);
            }
        });
        result = true;
    }
    return result;
}

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** @Returns if it worked */
public static boolean attachHandler(Element e, final int eventTypes, final EventCallback callback) {
    boolean result = false;
    if (e != null) {
        DOM.sinkEvents(e, eventTypes);/* w  ww  .j ava 2s.  co  m*/
        DOM.setEventListener(e, new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
                if (callback != null)
                    callback.onEvent(event);
            }
        });
        result = true;
    }
    return result;
}

From source file:com.extjs.gxt.ui.client.util.ClickRepeater.java

License:sencha.com license

public void doAttach() {
    DOM.setEventListener(el.dom, new EventListener() {
        public void onBrowserEvent(Event event) {
            switch (event.getTypeInt()) {
            case Event.ONMOUSEDOWN:
                event.stopPropagation();
                event.preventDefault();//from  ww  w.  ja  v a2 s  .c  o m
                handleMouseDown();
                break;
            case Event.ONMOUSEOUT:
                handleMouseOut();
                break;
            case Event.ONMOUSEOVER:
                handleMouseReturn();
                break;
            }
        }
    });

    el.disableTextSelection(true);
    preview.add();
}

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 w w  w  .ja  va 2 s  .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  w w w.  j a  v  a 2s  . 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();
}