Example usage for com.google.gwt.user.client Event addNativePreviewHandler

List of usage examples for com.google.gwt.user.client Event addNativePreviewHandler

Introduction

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

Prototype

public static HandlerRegistration addNativePreviewHandler(final NativePreviewHandler handler) 

Source Link

Document

Adds a NativePreviewHandler that will receive all events before they are fired to their handlers.

Usage

From source file:asquare.gwt.tests.clientcoords.client.Demo.java

License:Apache License

public void onModuleLoad() {
    RootPanel.get("outer").add(new Label("Event client position"));
    final TextArea output = new TextArea();
    RootPanel.get("outer").add(output);
    Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONMOUSEDOWN) {
                NativeEvent nativeEvent = event.getNativeEvent();
                output.setText("clientX=" + nativeEvent.getClientX() + ", clientY=" + nativeEvent.getClientY());
            }//from  ww w  .j  a va 2 s.  co m
        }
    });
}

From source file:asquare.gwt.tk.client.ui.behavior.EventPreviewControllerTemporary.java

License:Apache License

public void start(Widget widget) {
    if (widget == null)
        throw new NullPointerException();

    plugIn(widget);/*w  ww  . ja  v a 2s .  c  o m*/
    m_registration = Event.addNativePreviewHandler(this);
}

From source file:at.ait.dme.yuma.client.map.tagcloud.TagCloud.java

License:EUPL

public TagCloud(int width, int height, Element parentNode, TagSelectionListener listener) {
    this.domNode = DOM.createDiv();
    parentNode.appendChild(domNode);/*  ww  w  . j  a v  a  2  s  .  c o m*/
    _init(domNode);
    paper = Raphael.create(domNode, width, height);

    this.halfWidth = width / 2;
    this.halfHeight = height / 2;

    quadrants = new TagCloudQuadrant[] {
            new TagCloudQuadrant(halfWidth - TAG_BUFFER_X / 2, halfHeight - TAG_BUFFER_Y / 2 - 1,
                    halfWidth - TAG_BUFFER_X / 2, "end", "bottom", paper, listener), // top left
            new TagCloudQuadrant(halfWidth + TAG_BUFFER_X / 2, halfHeight - TAG_BUFFER_Y / 2 - 1,
                    halfWidth - TAG_BUFFER_X / 2, "start", "bottom", paper, listener), // top right
            new TagCloudQuadrant(halfWidth - TAG_BUFFER_X / 2, halfHeight + TAG_BUFFER_Y / 2,
                    halfWidth - TAG_BUFFER_X / 2, "end", "top", paper, listener), // bottom left
            new TagCloudQuadrant(halfWidth + TAG_BUFFER_X / 2, halfHeight + TAG_BUFFER_Y / 2,
                    halfWidth - TAG_BUFFER_X / 2, "start", "top", paper, listener) // bottom right
    };

    Event.addNativePreviewHandler(new NativePreviewHandler() {

        private boolean keyIsUp = true;

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONKEYDOWN) {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ALT) {
                    if (keyIsUp) { // Prevent re-firing of event on pressed keys
                        keyIsUp = false;
                        InfoPanel.show("Tag Cloud Hidden", "Release ALT key to show the tag cloud again.");
                        _hide(domNode);
                    }
                }
            } else if (event.getTypeInt() == Event.ONKEYUP) {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ALT) {
                    _show(domNode);
                    keyIsUp = true;
                }
            }
        }
    });
}

From source file:burrito.client.Burrito.java

License:Apache License

public void onModuleLoad() {
    RootPanel adminPanel = RootPanel.get("burrito-admin");

    if (adminPanel != null) {
        String siteletContainerId = Window.Location.getParameter("container");
        if (siteletContainerId != null && !siteletContainerId.isEmpty()) {
            SiteletAdminPanel siteletAdminPanel = new SiteletAdminPanel(siteletContainerId);
            adminPanel.add(siteletAdminPanel);
        } else {//w  ww . j ava2s. c  o  m
            CrudPanel crud = new CrudPanel();
            adminPanel.add(crud);
        }
        Window.addWindowScrollHandler(new ScrollHandler() {

            @Override
            public void onWindowScroll(ScrollEvent event) {
                updateEditFormButtons();
            }
        });
        Window.addResizeHandler(new ResizeHandler() {

            @Override
            public void onResize(ResizeEvent event) {
                updateEditFormButtons();
            }
        });

        Event.addNativePreviewHandler(new Event.NativePreviewHandler() {

            @Override
            public void onPreviewNativeEvent(NativePreviewEvent event) {
                if (currentCtrlSaveHandler == null) {
                    return;
                }
                if (event.getTypeInt() == Event.ONKEYDOWN) {
                    int sCharacterCode = 83;
                    if (event.getNativeEvent().getCtrlKey()
                            && event.getNativeEvent().getKeyCode() == sCharacterCode) {
                        currentCtrlSaveHandler.onCtrlSave();
                        event.cancel();
                    }
                }
            }
        });
    }
}

From source file:cc.alcina.framework.gwt.client.widget.dialog.OkCancelDialogBox.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();
    checkReCenterTimer = new Timer() {
        private int lastCenterHeight;

        @Override//from  ww w.j  av  a  2 s.c  om
        public void run() {
            if (lastCenterHeight != 0 && lastCenterHeight != getOffsetHeight()) {
                center();
            }
            lastCenterHeight = getOffsetHeight();
        }
    };
    checkReCenterTimer.scheduleRepeating(200);
    nativePreviewHandlerRegistration = Event.addNativePreviewHandler(e -> {
        int evtCode = e.getTypeInt();
        if (evtCode == Event.ONKEYDOWN && e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            cancel();
        }
        if (evtCode == Event.ONKEYDOWN && e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER
                && e.getNativeEvent().getCtrlKey()) {
            e.cancel();
            okButton.setFocus(true);
            onOkButtonClicked();
        }
    });
}

From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java

License:Apache License

/**
 * Set the showing state of the popup. If maybeAnimate is true, the
 * animation will be used to set the state. If it is false, the animation
 * will be cancelled.//  www .  j  av  a2  s .  c  om
 * 
 * @param showing
 *            the new state
 * @param maybeAnimate
 *            true to possibly run the animation
 */
private void setState(boolean showing, boolean maybeAnimate) {
    if (maybeAnimate) {
        resizeAnimation.setState(showing);
    } else {
        resizeAnimation.cancel();
    }
    this.showing = showing;
    // Create or remove the native preview handler
    if (showing) {
        nativePreviewHandlerRegistration = Event.addNativePreviewHandler(new NativePreviewHandler() {
            public void onPreviewNativeEvent(NativePreviewEvent event) {
                previewNativeEvent(event);
            }
        });
        historyHandlerRegistration = History.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                if (autoHideOnHistoryEvents) {
                    hide();
                }
            }
        });
    } else {
        if (nativePreviewHandlerRegistration != null) {
            nativePreviewHandlerRegistration.removeHandler();
            nativePreviewHandlerRegistration = null;
        }
        if (historyHandlerRegistration != null) {
            historyHandlerRegistration.removeHandler();
            historyHandlerRegistration = null;
        }
    }
}

From source file:cc.kune.common.client.shortcuts.GlobalShortcutRegisterDefault.java

License:GNU Affero Public License

/**
 * Enable impl.
 */
private void enableImpl() {
    handlerReg = Event.addNativePreviewHandler(eventHandler);
}

From source file:cc.kune.core.client.state.LinkInterceptor.java

License:GNU Affero Public License

@Inject
public LinkInterceptor(final HistoryWrapper history) {
    this.history = history;
    Event.addNativePreviewHandler(this);
}

From source file:cc.kune.events.client.viewer.CalendarViewerPanel.java

License:GNU Affero Public License

/**
 * Instantiates a new calendar viewer panel.
 *
 * @param gsArmor//from  w ww .  ja  v  a 2s .co m
 *          the gs armor
 * @param eventBus
 *          the event bus
 * @param i18n
 *          the i18n
 * @param guiProvider
 *          the gui provider
 * @param res
 *          the res
 * @param capabilitiesRegistry
 *          the capabilities registry
 * @param dragController
 *          the drag controller
 * @param contentDropControllerProv
 *          the content drop controller prov
 * @param containerDropControllerProv
 *          the container drop controller prov
 */
@Inject
public CalendarViewerPanel(final GSpaceArmor gsArmor, final EventBus eventBus,
        final I18nTranslationService i18n, final GuiProvider guiProvider, final CoreResources res,
        final ContentCapabilitiesRegistry capabilitiesRegistry, final KuneDragController dragController,
        final Provider<FolderContentDropController> contentDropControllerProv,
        final Provider<FolderContainerDropController> containerDropControllerProv,
        final InboxToContainerDropController inbDropController) {
    super(gsArmor, eventBus, i18n, capabilitiesRegistry, dragController, contentDropControllerProv,
            containerDropControllerProv, inbDropController);
    calendar = new Calendar();
    calendar.setSettings(setCalendarSettings());
    widget = calendar;
    calendar.sinkEvents(
            Event.ONMOUSEDOWN | Event.ONDBLCLICK | Event.KEYEVENTS | Event.ONMOUSEOVER | Event.ONCLICK);
    Event.addNativePreviewHandler(new NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(final NativePreviewEvent eventPrev) {
            // We store click position in onder to show the menu
            final NativeEvent natEvent = eventPrev.getNativeEvent();
            if (Event.getTypeInt(natEvent.getType()) != Event.ONCLICK) {
                clientX = natEvent.getClientX();
                clientY = natEvent.getClientY();
                return;
            }
        }
    });
    contentTitle = new ContentTitleWidget(i18n, gsArmor, capabilitiesRegistry.getIconsRegistry());
    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(final ResizeEvent event) {
            resizeCalendar();
        }
    });
    tooltipPanel = new PopupPanel();
    Tooltip.to(tooltipPanel, "FIXME");
    addMouseOverHandler(new MouseOverHandler<Appointment>() {
        @Override
        public void onMouseOver(final MouseOverEvent<Appointment> event) {
            final Element element = (Element) event.getElement();
            tooltipPanel.setPopupPosition(DOM.getAbsoluteLeft(element),
                    DOM.getAbsoluteTop(element) + element.getOffsetHeight());
            tooltipPanel.show();
            if (Tooltip.getTip().isShowing()) {
                tooltipPanel.hide();
                Tooltip.getTip().hide();
            } else {
                Tooltip.getTip().showTemporally(tooltipPanel, tooltipText);
            }
            // NotifyUser.info("On mouse");
        }
    });
}

From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java

License:Apache License

/**
 * Adds the event preview listening for mouse events.
 *//*from  w  w  w .j  a va2  s .  c o  m*/
protected void addEventPreview() {
    handlerReg = Event.addNativePreviewHandler(nativePreviewHandler);
    GWT.log("ADD EVENT PREVIEW");
}