Example usage for com.google.gwt.user.client.ui Widget addBitlessDomHandler

List of usage examples for com.google.gwt.user.client.ui Widget addBitlessDomHandler

Introduction

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

Prototype

public final <H extends EventHandler> HandlerRegistration addBitlessDomHandler(final H handler,
        DomEvent.Type<H> type) 

Source Link

Document

For <a href= "http://code.google.com/p/google-web-toolkit/wiki/UnderstandingMemoryLeaks" >browsers which do not leak</a>, adds a native event handler to the widget.

Usage

From source file:com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetPointerImpl.java

License:Apache License

@Override
public HandlerRegistration addTouchStartHandler(Widget w, TouchStartHandler handler) {
    return w.addBitlessDomHandler(new TouchStartToMsPointerDownHandler(handler), MsPointerDownEvent.getType());
}

From source file:com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetPointerImpl.java

License:Apache License

@Override
public HandlerRegistration addTouchMoveHandler(Widget w, TouchMoveHandler handler) {
    return w.addBitlessDomHandler(new TouchMoveToMsPointerMoveHandler(handler), MsPointerMoveEvent.getType());
}

From source file:com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetPointerImpl.java

License:Apache License

@Override
public HandlerRegistration addTouchCancelHandler(Widget w, TouchCancelHandler handler) {
    return w.addBitlessDomHandler(new TouchCancelToMsPointerCancelHandler(handler),
            MsPointerCancelEvent.getType());
}

From source file:com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetPointerImpl.java

License:Apache License

@Override
public HandlerRegistration addTouchEndHandler(Widget w, TouchEndHandler handler) {
    return w.addBitlessDomHandler(new TouchEndToMsPointerUpHandler(handler), MsPointerUpEvent.getType());
}

From source file:com.ponysdk.ui.terminal.ui.PTWidget.java

License:Apache License

private void addDomHandler(final PTInstruction addHandler, final Widget widget, final int domHandlerType,
        final UIService uiService) {

    final DomHandlerType h = DomHandlerType.values()[domHandlerType];
    switch (h) {//  ww  w.j av  a 2  s .  com
    case CLICK:
        widget.addDomHandler(new ClickHandler() {

            @Override
            public void onClick(final ClickEvent event) {
                triggerOnClick(addHandler, widget, domHandlerType, uiService, event);
            }

        }, ClickEvent.getType());
        break;
    case MOUSE_OVER:
        widget.addDomHandler(new MouseOverHandler() {

            @Override
            public void onMouseOver(final MouseOverEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, MouseOverEvent.getType());
        break;
    case BLUR:
        widget.addDomHandler(new BlurHandler() {

            @Override
            public void onBlur(final BlurEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, BlurEvent.getType());
        break;
    case FOCUS:
        widget.addDomHandler(new FocusHandler() {

            @Override
            public void onFocus(final FocusEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, FocusEvent.getType());
        break;
    case MOUSE_OUT:
        widget.addDomHandler(new MouseOutHandler() {

            @Override
            public void onMouseOut(final MouseOutEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, MouseOutEvent.getType());
        break;
    case MOUSE_DOWN:
        widget.addDomHandler(new MouseDownHandler() {

            @Override
            public void onMouseDown(final MouseDownEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, MouseDownEvent.getType());
        break;
    case MOUSE_UP:
        widget.addDomHandler(new MouseUpHandler() {

            @Override
            public void onMouseUp(final MouseUpEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }

        }, MouseUpEvent.getType());
        break;
    case KEY_PRESS:
        widget.addDomHandler(new KeyPressHandler() {

            @Override
            public void onKeyPress(final KeyPressEvent event) {
                triggerOnKeyPress(addHandler, domHandlerType, uiService, event);
            }

        }, KeyPressEvent.getType());
        break;
    case KEY_UP:

        if (widget instanceof TextBoxBase) {
            final TextBoxBase textBox = (TextBoxBase) widget;
            textBox.addKeyUpHandler(new KeyUpHandler() {

                @Override
                public void onKeyUp(final KeyUpEvent event) {
                    final PTInstruction changeHandlerInstruction = new PTInstruction();
                    changeHandlerInstruction.setObjectID(addHandler.getObjectID());
                    changeHandlerInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT);
                    changeHandlerInstruction.put(HANDLER.KEY, HANDLER.KEY_.STRING_VALUE_CHANGE_HANDLER);
                    changeHandlerInstruction.put(PROPERTY.VALUE, textBox.getText());

                    final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType);
                    eventInstruction.put(PROPERTY.VALUE, event.getNativeEvent().getKeyCode());

                    if (addHandler.containsKey(PROPERTY.KEY_FILTER)) {
                        final JSONArray jsonArray = addHandler.get(PROPERTY.KEY_FILTER).isArray();
                        for (int i = 0; i < jsonArray.size(); i++) {
                            final JSONNumber keyCode = jsonArray.get(i).isNumber();
                            if (keyCode.doubleValue() == event.getNativeEvent().getKeyCode()) {
                                uiService.stackEvent(changeHandlerInstruction);
                                uiService.stackEvent(eventInstruction);
                                uiService.flushEvents();
                                break;
                            }
                        }
                    } else {
                        uiService.stackEvent(changeHandlerInstruction);
                        uiService.stackEvent(eventInstruction);
                        uiService.flushEvents();
                    }
                }
            });
        } else {
            widget.addDomHandler(new KeyUpHandler() {

                @Override
                public void onKeyUp(final KeyUpEvent event) {
                    final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType);
                    eventInstruction.put(PROPERTY.VALUE, event.getNativeEvent().getKeyCode());
                    if (eventInstruction.containsKey(PROPERTY.KEY_FILTER)) {
                        final JSONArray jsonArray = addHandler.get(PROPERTY.KEY_FILTER).isArray();
                        for (int i = 0; i < jsonArray.size(); i++) {
                            final JSONNumber keyCode = jsonArray.get(i).isNumber();
                            if (keyCode.doubleValue() == event.getNativeEvent().getKeyCode()) {
                                uiService.triggerEvent(eventInstruction);
                                break;
                            }
                        }
                    } else {
                        uiService.triggerEvent(eventInstruction);
                    }
                }
            }, KeyUpEvent.getType());
        }
        break;
    case DRAG_START:
        widget.getElement().setDraggable(Element.DRAGGABLE_TRUE);
        widget.addBitlessDomHandler(new DragStartHandler() {

            @Override
            public void onDragStart(final DragStartEvent event) {
                event.setData("text", Long.toString(addHandler.getObjectID()));
                event.getDataTransfer().setDragImage(uiObject.getElement(), 10, 10);
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }
        }, DragStartEvent.getType());
        break;
    case DRAG_END:
        widget.addBitlessDomHandler(new DragEndHandler() {

            @Override
            public void onDragEnd(final DragEndEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }
        }, DragEndEvent.getType());
        break;
    case DRAG_ENTER:
        widget.addBitlessDomHandler(new DragEnterHandler() {

            @Override
            public void onDragEnter(final DragEnterEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }
        }, DragEnterEvent.getType());
        break;
    case DRAG_LEAVE:
        widget.addBitlessDomHandler(new DragLeaveHandler() {

            @Override
            public void onDragLeave(final DragLeaveEvent event) {
                triggerDomEvent(addHandler, domHandlerType, uiService);
            }
        }, DragLeaveEvent.getType());
        break;
    case DROP:
        widget.addBitlessDomHandler(new DragOverHandler() {

            @Override
            public void onDragOver(final DragOverEvent event) {
                // required by GWT api
                // triggerDomEvent(addHandler, domHandlerType, uiService);
            }
        }, DragOverEvent.getType());

        widget.addBitlessDomHandler(new DropHandler() {

            @Override
            public void onDrop(final DropEvent event) {
                event.preventDefault();
                final String dragWidgetID = event.getData("text");
                final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType);
                if (dragWidgetID != null)
                    eventInstruction.put(PROPERTY.DRAG_SRC, Long.parseLong(dragWidgetID));
                uiService.triggerEvent(eventInstruction);
            }
        }, DropEvent.getType());
        break;
    default:
        log.info("Handler not supported #" + h);
        break;
    }
}