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

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

Introduction

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

Prototype

@Override
public void sinkEvents(int eventBitsToAdd) 

Source Link

Document

Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.

Usage

From source file:com.ui.gwt.mobile.client.utils.EventUtils.java

License:Apache License

public static void sinkClickEvent(Widget widget) {
    if (BrowserUtils.isMobile) {
        widget.sinkEvents(Event.ONTOUCHEND);
    } else {/*from w  ww  . j  av a2  s.c o m*/
        widget.sinkEvents(Event.ONCLICK);
    }
}

From source file:gwt.material.design.client.base.helper.UiHelper.java

License:Apache License

/**
 * Adds a mouse pressed handler to a widget. Adds a CSS style to the widget
 * as long as the mouse is pressed (or the user touches the widget on mobile browser).
 *
 * @param widget The widget to which the style must be applied for mouse/touch event
 * @param cssStyleName CSS style name to be applied
 */// w  ww.  jav  a2  s . c  o  m
public static void addMousePressedHandlers(final Widget widget, final String cssStyleName) {
    widget.sinkEvents(Event.ONMOUSEDOWN);
    widget.sinkEvents(Event.ONMOUSEUP);
    widget.sinkEvents(Event.ONMOUSEOUT);
    widget.sinkEvents(Event.TOUCHEVENTS);

    widget.addHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent event) {
            widget.addStyleName(cssStyleName);
        }
    }, MouseDownEvent.getType());

    widget.addHandler(new MouseUpHandler() {
        @Override
        public void onMouseUp(MouseUpEvent event) {
            widget.removeStyleName(cssStyleName);
        }
    }, MouseUpEvent.getType());

    widget.addHandler(new MouseOutHandler() {
        @Override
        public void onMouseOut(MouseOutEvent event) {
            widget.removeStyleName(cssStyleName);
        }
    }, MouseOutEvent.getType());

    // Touch Events
    widget.addHandler(new TouchStartHandler() {
        @Override
        public void onTouchStart(TouchStartEvent event) {
            widget.addStyleName(cssStyleName);
        }
    }, TouchStartEvent.getType());

    widget.addHandler(new TouchEndHandler() {
        @Override
        public void onTouchEnd(TouchEndEvent event) {
            widget.removeStyleName(cssStyleName);

        }
    }, TouchEndEvent.getType());

    widget.addHandler(new TouchCancelHandler() {
        @Override
        public void onTouchCancel(TouchCancelEvent event) {
            widget.removeStyleName(cssStyleName);
        }
    }, TouchCancelEvent.getType());
}

From source file:gwt.material.design.client.ui.table.CellBasedWidgetImpl.java

License:Apache License

/**
 * Sink events on the widget./*  w ww  .  j a v a2 s. c o  m*/
 *
 * @param widget the {@link Widget} that will handle the events
 * @param typeNames the names of the events to sink
 */
public final void sinkEvents(Widget widget, Set<String> typeNames) {
    if (typeNames == null) {
        return;
    }

    int eventsToSink = 0;
    for (String typeName : typeNames) {
        int typeInt = Event.getTypeInt(typeName);
        if (typeInt < 0) {
            widget.sinkBitlessEvent(typeName);
        } else {
            typeInt = sinkEvent(widget, typeName);
            if (typeInt > 0) {
                eventsToSink |= typeInt;
            }
        }
    }
    if (eventsToSink > 0) {
        widget.sinkEvents(eventsToSink);
    }
}

From source file:gwt.material.design.components.client.utils.helper.UiHelper.java

License:Apache License

/**
 * Adds a mouse pressed handler to a widget. Adds a CSS style to the widget as
 * long as the mouse is pressed (or the user touches the widget on mobile
 * browser).//from   w ww .  j a va2  s  .  c o m
 *
 * @param widget       The widget to which the style must be applied for
 *                     mouse/touch event
 * @param cssStyleName CSS style name to be applied
 */
public static void addMousePressedHandlers(final Widget widget, final String cssStyleName) {
    widget.sinkEvents(Event.ONMOUSEDOWN);
    widget.sinkEvents(Event.ONMOUSEUP);
    widget.sinkEvents(Event.ONMOUSEOUT);
    widget.sinkEvents(Event.TOUCHEVENTS);

    widget.addHandler(event -> {
        widget.addStyleName(cssStyleName);
    }, MouseDownEvent.getType());

    widget.addHandler(event -> {
        widget.removeStyleName(cssStyleName);
    }, MouseUpEvent.getType());

    widget.addHandler(event -> {
        widget.removeStyleName(cssStyleName);
    }, MouseOutEvent.getType());

    // Touch Events
    widget.addHandler(event -> {
        widget.addStyleName(cssStyleName);
    }, TouchStartEvent.getType());

    widget.addHandler(event -> {
        widget.removeStyleName(cssStyleName);
    }, TouchEndEvent.getType());

    widget.addHandler(event -> {
        widget.removeStyleName(cssStyleName);
    }, TouchCancelEvent.getType());
}

From source file:net.sf.mmm.client.ui.gwt.widgets.handler.AbstractMouseDragHandler.java

License:Apache License

/**
 * {@inheritDoc}//from www  . j a  v  a  2s.  com
 */
@Override
public void register(Widget widget, HandlerRegistrationCollector collector) {

    widget.sinkEvents(Event.ONMOUSEDOWN);
    HandlerRegistration handlerRegistration = widget.addDomHandler(this, MouseDownEvent.getType());
    if (collector != null) {
        collector.addHandlerRegistration(handlerRegistration);
    }
}

From source file:org.jbpm.form.builder.ng.model.common.handler.EventHelper.java

License:Apache License

public static HandlerRegistration addBlurHandler(Widget widget, final BlurHandler handler) {
    widget.sinkEvents(Event.ONBLUR);
    List<BlurHandler> handlers = BLUR_HANDLERS.get(widget);
    if (handlers == null) {
        handlers = new ArrayList<BlurHandler>();
        BLUR_HANDLERS.put(widget, handlers);
    }/*from w w  w .  ja  va2  s.  c om*/
    handlers.add(handler);
    final List<BlurHandler> _handlers = handlers;
    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            _handlers.remove(handler);
        }
    };
}

From source file:org.jbpm.form.builder.ng.model.common.handler.EventHelper.java

License:Apache License

public static HandlerRegistration addFocusHandler(Widget widget, final FocusHandler handler) {
    widget.sinkEvents(Event.ONFOCUS);
    List<FocusHandler> handlers = FOCUS_HANDLERS.get(widget);
    if (handlers == null) {
        handlers = new ArrayList<FocusHandler>();
        FOCUS_HANDLERS.put(widget, handlers);
    }/*  w  w  w  .  j a va2s. c om*/
    handlers.add(handler);
    final List<FocusHandler> _handlers = handlers;
    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            _handlers.remove(handler);
        }
    };
}

From source file:org.jbpm.form.builder.ng.model.common.handler.EventHelper.java

License:Apache License

public static HandlerRegistration addRightClickHandler(Widget widget, final RightClickHandler handler) {
    widget.sinkEvents(Event.ONMOUSEUP | Event.ONDBLCLICK | Event.ONCONTEXTMENU);
    List<RightClickHandler> handlers = RCLICK_HANDLERS.get(widget);
    if (handlers == null) {
        handlers = new ArrayList<RightClickHandler>();
        RCLICK_HANDLERS.put(widget, handlers);
    }/*from  w  w  w  .j a  v a  2 s  .  com*/
    handlers.add(handler);
    final List<RightClickHandler> _handlers = handlers;
    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            _handlers.remove(handler);
        }
    };
}

From source file:org.jbpm.form.builder.ng.model.common.handler.EventHelper.java

License:Apache License

public static HandlerRegistration addKeyboardPasteHandler(Widget widget, final ControlKeyHandler handler) {
    widget.sinkEvents(Event.ONKEYPRESS);
    List<ControlKeyHandler> handlers = KPASTE_HANDLERS.get(widget);
    if (handlers == null) {
        handlers = new ArrayList<ControlKeyHandler>();
        KPASTE_HANDLERS.put(widget, handlers);
    }//w  w  w .j a v  a2  s .co m
    handlers.add(handler);
    final List<ControlKeyHandler> _handlers = handlers;
    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            _handlers.remove(handler);
        }
    };
}

From source file:org.jbpm.form.builder.ng.model.common.handler.EventHelper.java

License:Apache License

public static HandlerRegistration addKeyboardCutHandler(Widget widget, final ControlKeyHandler handler) {
    widget.sinkEvents(Event.ONKEYPRESS);
    List<ControlKeyHandler> handlers = KCUT_HANDLERS.get(widget);
    if (handlers == null) {
        handlers = new ArrayList<ControlKeyHandler>();
        KCUT_HANDLERS.put(widget, handlers);
    }//from w w w  .  j  a va  2  s.com
    handlers.add(handler);
    final List<ControlKeyHandler> _handlers = handlers;
    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            _handlers.remove(handler);
        }
    };
}