Example usage for com.google.gwt.event.dom.client KeyPressEvent getUnicodeCharCode

List of usage examples for com.google.gwt.event.dom.client KeyPressEvent getUnicodeCharCode

Introduction

In this page you can find the example usage for com.google.gwt.event.dom.client KeyPressEvent getUnicodeCharCode.

Prototype

public int getUnicodeCharCode() 

Source Link

Document

Gets the Unicode char code (code point) for this event.

Usage

From source file:com.ephesoft.gxt.rv.client.controller.ReviewValidateSelectionController.java

License:Open Source License

private KeyPressHandler getKeyPressHandler() {
    return new KeyPressHandler() {

        @Override/*w ww  . j a  v  a 2  s .  c  o m*/
        public void onKeyPress(KeyPressEvent event) {
            if (event.isControlKeyDown()) {
                if (event.getUnicodeCharCode() == KeyCodes.KEY_P
                        || event.getNativeEvent().getKeyCode() == KeyCodes.KEY_P) {
                    event.preventDefault();
                    event.stopPropagation();
                }
            }
        }
    };
}

From source file:com.isotrol.impe3.pms.gui.client.widget.LoginPanel.java

License:Open Source License

/**
 * Inits this container inner components.<br/>
 *///from  w  w w.  j  a  va2 s .  com
private void initComponent() {

    LayoutContainer lc = new LayoutContainer(formSupport.getStandardLayout(false));
    lc.addStyleName(pmsStyles.loginPanel());
    lc.setAutoWidth(true);

    tfErrorMessage = new LabelField();
    tfErrorMessage.addStyleName(styles.labelInfoMessage());
    tfErrorMessage.addStyleName(styles.redMessage());
    tfErrorMessage.setVisible(false);
    lc.add(tfErrorMessage);

    add(lc);

    lcAuthenticating = new LayoutContainer(new ColumnLayout());
    lcAuthenticating.setVisible(false);
    lcAuthenticating.setStyleName(styles.marginBottom10px());
    // add "loading" icon:
    lcAuthenticating.add(new Html("<div class='loading-icon' style='float: right; margin-right: 5px;'></div>"),
            new ColumnData(165));
    // add "authenticating" label:
    Label tfAuthenticating = new Label(pmsMessages.msgAuthenticating());
    tfAuthenticating.addStyleName(styles.labelInfoMessage());
    lcAuthenticating.add(tfAuthenticating);

    add(lcAuthenticating);

    KeyPressHandler keyEnterPressHandler = new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (event.getUnicodeCharCode() == KeyCodes.KEY_ENTER) {
                pmsLoginForm.submit();
            }
        }
    };

    tfUsername = (InputElement) Document.get().getElementById(USER_FIELD_ID);
    // wrap the input element in a gwt textbox to listen 'enter' key press
    TextBox tbUserName = TextBox.wrap(tfUsername);
    if (tbUserName != null) {
        tbUserName.addKeyPressHandler(keyEnterPressHandler);
    }

    tfPassword = (InputElement) Document.get().getElementById(PASSWORD_FIELD_ID);
    PasswordTextBox tbPassword = PasswordTextBox.wrap(tfPassword);
    if (tbPassword != null) {
        tbPassword.addKeyPressHandler(keyEnterPressHandler);
    }

    LabelElement userLabel = (LabelElement) Document.get().getElementById(USER_LABEL_ID);
    userLabel.setInnerText(pmsMessages.labelUsername());
    LabelElement pwdLabel = (LabelElement) Document.get().getElementById(PASSWORD_LABEL_ID);
    pwdLabel.setInnerText(pmsMessages.labelPassword());

    // Get a handle to the form and set its action. The Wraping for form must be after the input wrapings
    pmsLoginForm = FormPanel.wrap(Document.get().getElementById(FORM_ID), false);
    // form.setAction("javascript:__gwt_login()");
    // form.setAction("javascript:''");
    pmsLoginForm.addSubmitHandler(new SubmitHandler() {
        /**
         * Add login form validations (user and password are required fields)
         * @see com.google.gwt.user.client.ui.FormPanel.SubmitHandler#onSubmit(com.google.gwt.user.client.ui.FormPanel.SubmitEvent)
         */
        public void onSubmit(SubmitEvent event) {
            if (tfUsername.getValue() == null || tfUsername.getValue().equals("")) {
                tfErrorMessage.setValue(pmsMessages.msgErrorUserRequired());
                tfErrorMessage.show();
                event.cancel();
            } else if (tfPassword.getValue() == null || tfPassword.getValue().equals("")) {
                tfErrorMessage.setValue(pmsMessages.msgErrorPasswordRequired());
                tfErrorMessage.show();
                event.cancel();
            } else {
                initAuthentication();
            }
        }
    });

    // Get the submit button for text localization
    final ButtonElement submit = (ButtonElement) Document.get().getElementById(SUBMIT_BUTTON_ID);
    submit.setInnerText(messages.labelAccept());

    SelectionListener<ButtonEvent> listener = new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            submit.click();
        }
    };
    Button bAccept = buttonsSupport.createAcceptButton(listener);
    addButton(bAccept);
    // Add the form to the panel
    lc.add(pmsLoginForm);
}

From source file:com.tasktop.c2c.server.tasks.client.widgets.AbstractEditTaskDialog.java

License:Open Source License

protected void attachEnterForSubmit(HasKeyPressHandlers widget) {
    widget.addKeyPressHandler(new KeyPressHandler() {

        @Override/*w  w  w .  ja va 2  s .c  o  m*/
        public void onKeyPress(KeyPressEvent event) {
            if (KeyCodes.KEY_ENTER == event.getUnicodeCharCode()) {
                onSave(null);
            }
        }
    });
}

From source file:org.clevermore.monitor.client.servers.GcHistoryPopup.java

License:Apache License

@Override
public void onKeyPress(KeyPressEvent event) {
    Log.debug("key" + event.getUnicodeCharCode());
}

From source file:org.opencms.gwt.client.ui.input.colorpicker.CmsColorSelector.java

License:Open Source License

/**
 * Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed.<p>
 * It should be noted that many browsers do not generate keypress events for non-printing keyCode values.<p>
 * Such as KEY_ENTER or arrow keys.//from  ww w.  j  a v a 2  s.  c  o m
 *
 * @param event the widget that was focused when the event occurred.
 */
public void onKeyPress(KeyPressEvent event) {

    Widget widget = (Widget) event.getSource();
    int unicodeCharCode = event.getUnicodeCharCode();
    char keyCode = event.getCharCode();

    if (widget == m_tbHexColor) {
        // Disallow non-hex in hexadecimal boxes
        if ((!Character.isDigit(keyCode)) && (unicodeCharCode != 'A') && (unicodeCharCode != 'a')
                && (unicodeCharCode != 'B') && (unicodeCharCode != 'b') && (unicodeCharCode != 'C')
                && (unicodeCharCode != 'c') && (unicodeCharCode != 'D') && (unicodeCharCode != 'd')
                && (unicodeCharCode != 'E') && (unicodeCharCode != 'e') && (unicodeCharCode != 'F')
                && (unicodeCharCode != 'f') && (unicodeCharCode != KeyCodes.KEY_TAB)
                && (unicodeCharCode != (char) KeyCodes.KEY_BACKSPACE)
                && (unicodeCharCode != (char) KeyCodes.KEY_DELETE)
                && (unicodeCharCode != (char) KeyCodes.KEY_ENTER)
                && (unicodeCharCode != (char) KeyCodes.KEY_HOME) && (unicodeCharCode != (char) KeyCodes.KEY_END)
                && (unicodeCharCode != (char) KeyCodes.KEY_LEFT) && (unicodeCharCode != (char) KeyCodes.KEY_UP)
                && (unicodeCharCode != (char) KeyCodes.KEY_RIGHT)
                && (unicodeCharCode != (char) KeyCodes.KEY_DOWN)) {
            ((TextBox) widget).cancelKey();
        }
    } else {
        // Disallow non-numerics in numeric boxes
        if ((!Character.isDigit(keyCode)) && (keyCode != (char) KeyCodes.KEY_TAB)
                && (keyCode != (char) KeyCodes.KEY_BACKSPACE) && (keyCode != (char) KeyCodes.KEY_DELETE)
                && (keyCode != (char) KeyCodes.KEY_ENTER) && (keyCode != (char) KeyCodes.KEY_HOME)
                && (keyCode != (char) KeyCodes.KEY_END) && (keyCode != (char) KeyCodes.KEY_LEFT)
                && (keyCode != (char) KeyCodes.KEY_UP) && (keyCode != (char) KeyCodes.KEY_RIGHT)
                && (keyCode != (char) KeyCodes.KEY_DOWN)) {
            ((TextBox) widget).cancelKey();
        }
    }
}

From source file:org.primaresearch.web.layouteditor.client.WebLayoutEditor.java

License:Apache License

@Override
public void onKeyPress(KeyPressEvent event) {
    try {//from w w w  . ja va  2  s  .com
        int code = event.getUnicodeCharCode();
        if (code == '\u002B')
            pageView.zoomIn();
        else if (code == '\u2212' || code == '\u2010' || code == '\u002D')
            pageView.zoomOut();
        else if (code == '\u2212' || code == '\u2010' || code == '\u002D')
            pageView.zoomOut();
        //else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEDOWN)
        //   selectNextObject();
        //else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEUP)
        //   selectPreviousObject();
        //else
        //   Window.alert(""+code);
    } catch (Exception exc) {
        logManager.logError(ERROR_UNSPECIFIED, "Error in onKeyPress()");
        exc.printStackTrace();
    }
}

From source file:org.xwiki.gwt.user.client.TextBoxNumberFilter.java

License:Open Source License

@Override
public void onKeyPress(KeyPressEvent event) {
    int keyCode = event.getNativeEvent().getKeyCode();
    int codePoint = event.getUnicodeCharCode();
    if (codePoint > 0 && !Character.isDigit((char) codePoint) && !SPECIAL_KEY_CODES.contains(keyCode)) {
        // Suppress the current keyboard event.
        ((TextBox) event.getSource()).cancelKey();
    }//from   w  w w .java  2  s .  c  om
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.rt.RealTimePlugin.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww w. j  a v  a2s.  c  o m*/
 *
 * @see KeyPressHandler#onKeyPress(KeyPressEvent)
 */
public void onKeyPress(KeyPressEvent event) {
    log.fine("onKeyPress: " + getTextArea().getHTML());
    boolean isAltControlOrMetaDown = event.isAltKeyDown() || event.isControlKeyDown() || event.isMetaKeyDown();
    boolean isNoteworthyKeyPressed = event.getCharCode() != '\u0000';

    if (getTextArea().isAttached() && getTextArea().isEnabled() && !isAltControlOrMetaDown
            && isNoteworthyKeyPressed) {
        Selection selection = getTextArea().getDocument().getSelection();
        if (selection.getRangeCount() > 0) {
            Range range = selection.getRangeAt(0);
            range = EditorUtils.normalizeCaretPosition(range);

            logRange("New range", range);

            char character = new String(new int[] { event.getUnicodeCharCode() }, 0, 1).charAt(0);
            clientJupiter.generate(
                    treeOperationFactory.createTreeInsertText(clientJupiter.getSiteId(), range, character));

            event.preventDefault();
        }
    }
}

From source file:viewer.EventsHandler.java

License:Open Source License

private static int getKeyCode(final KeyPressEvent event) {
    final int code = event.getUnicodeCharCode();
    if (code != 0) {
        return code;
    }//from w ww . java2s . c o m
    // According to bug #5558, this might confuse '(' and 'down arrow'.
    return event.getNativeEvent().getKeyCode();
}