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

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

Introduction

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

Prototype

int ONPASTE

To view the source code for com.google.gwt.user.client Event ONPASTE.

Click Source Link

Document

Fired when the user pastes text into an input element.

Usage

From source file:ar.com.kyol.jet.client.wrappers.FloatBox.java

License:Open Source License

/**
 * Instantiates a new float box./*from w  w  w .  ja v  a 2s . c  o m*/
 * 
 * @param maximumFractionDigits - 1 or more digits
 * @param acceptNegatives - true if you want to allow the minus sign
 */
public FloatBox(final int maximumFractionDigits, final boolean acceptNegatives) {
    sinkEvents(Event.ONPASTE);
    //addKeyPressHandler(new KeyPressHandler() {
    addKeyDownHandler(new KeyDownHandler() {

        @Override
        //public void onKeyPress(KeyPressEvent event) { //GWT bug: Issue 5558:    KeyPressEvent.getCharCode returns zero for special keys like enter, escape, tab
        public void onKeyDown(KeyDownEvent event) {

            switch (event.getNativeKeyCode()) {
            case KeyCodes.KEY_LEFT:
            case KeyCodes.KEY_DOWN:
            case KeyCodes.KEY_RIGHT:
            case KeyCodes.KEY_UP:
            case KeyCodes.KEY_BACKSPACE:
            case KeyCodes.KEY_DELETE:
            case KeyCodes.KEY_TAB:
            case KeyCodes.KEY_HOME:
            case KeyCodes.KEY_END:
                return;
            }

            if (event.getNativeKeyCode() == 109 || event.getNativeKeyCode() == 189) { //minus sign or dash
                if ((getCursorPos() != 0) || getValue().contains("-") || !acceptNegatives) {
                    ((TextBoxBase) event.getSource()).cancelKey();
                } else {
                    return;
                }
            }

            if (event.getNativeKeyCode() == 188 || event.getNativeKeyCode() == 190
                    || event.getNativeKeyCode() == 110) { //comma, point and decimal separator
                //TODO internationalization!!! use com.google.gwt.i18n.client.LocaleInfo.getNumberConstants().decimalSeparator()
                if (getValue().contains(".")) {
                    ((TextBoxBase) event.getSource()).cancelKey();
                } else {
                    if (getCursorPos() < getValue().length() - maximumFractionDigits) {
                        ((TextBoxBase) event.getSource()).cancelKey();
                    } else {
                        return;
                    }
                }
            }

            if (((event.getNativeKeyCode() < 48 || event.getNativeKeyCode() > 57) && //numeric keys
            (event.getNativeKeyCode() < 96 || event.getNativeKeyCode() > 105)) //numeric pad
                    || event.isAnyModifierKeyDown() || event.isAltKeyDown()) {
                ((TextBoxBase) event.getSource()).cancelKey();
            } else {
                if (getValue().contains(".")) {
                    int cursorPos = getCursorPos();
                    int posicionPunto = getValue().indexOf(".");
                    int longitudTexto = getValue().length();
                    if (cursorPos > posicionPunto
                            && longitudTexto >= posicionPunto + 1 + maximumFractionDigits) {
                        ((TextBoxBase) event.getSource()).cancelKey();
                    }
                }
            }

        }
    });
}

From source file:ar.com.kyol.jet.client.wrappers.FloatBox.java

License:Open Source License

@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);
    switch (event.getTypeInt()) {
    case Event.ONPASTE: {
        event.stopPropagation();// ww w.  j  a v a 2s.c om
        event.preventDefault();
        break;
    }
    }
}

From source file:ar.com.kyol.jet.client.wrappers.NumericBox.java

License:Open Source License

/**
 * Instantiates a new numeric box.//from  w  w  w . ja va2s .  co m
 * <i>allowNegative</i> allows the minus sign.
 */
public NumericBox(final boolean allowNegative) {
    sinkEvents(Event.ONPASTE);
    //addKeyPressHandler(new KeyPressHandler() {
    addKeyDownHandler(new KeyDownHandler() {

        @Override
        //public void onKeyPress(KeyPressEvent event) { //GWT bug: Issue 5558:    KeyPressEvent.getCharCode returns zero for special keys like enter, escape, tab
        public void onKeyDown(KeyDownEvent event) {

            switch (event.getNativeKeyCode()) {
            case KeyCodes.KEY_LEFT:
            case KeyCodes.KEY_DOWN:
            case KeyCodes.KEY_RIGHT:
            case KeyCodes.KEY_UP:
            case KeyCodes.KEY_BACKSPACE:
            case KeyCodes.KEY_DELETE:
            case KeyCodes.KEY_TAB:
            case KeyCodes.KEY_HOME:
            case KeyCodes.KEY_END:
                return;
            }

            if (event.getNativeKeyCode() == 109 || event.getNativeKeyCode() == 189) { //minus sign or dash
                if ((getCursorPos() != 0) || getValue().contains("-") || !allowNegative) {
                    ((TextBoxBase) event.getSource()).cancelKey();
                } else {
                    return;
                }
            }

            if ((event.getNativeKeyCode() >= 96 && event.getNativeKeyCode() <= 105)) { //numeric pad!
                return;
            }

            //FIXME shift!!!   
            if (event.getNativeKeyCode() < 48 || event.getNativeKeyCode() > 57 || event.isAnyModifierKeyDown()
                    || event.isAltKeyDown()) { //numeric keys
                ((TextBoxBase) event.getSource()).cancelKey();
            }

        }
    });
}

From source file:com.alkacon.geranium.client.ui.input.TextBox.java

License:Open Source License

/**
 * Constructs a new instance of this widget.
 *///from   www .java 2 s  .  c o m
public TextBox() {

    setEnabled(true);
    m_textbox.setStyleName(CSS.textBox());
    m_textbox.getElement().setId("CmsTextBox_" + (idCounter++));

    TextBoxHandler handler = new TextBoxHandler("");
    m_textbox.addMouseOverHandler(handler);
    m_textbox.addMouseOutHandler(handler);
    m_textbox.addFocusHandler(handler);
    m_textbox.addBlurHandler(handler);
    m_textbox.addValueChangeHandler(handler);
    m_textbox.addKeyPressHandler(handler);

    m_handler = handler;

    m_textboxContainer.setStyleName(CSS.textBoxPanel());
    m_textboxContainer.addStyleName(I_LayoutBundle.INSTANCE.generalCss().cornerAll());
    m_textboxContainer.addStyleName(I_LayoutBundle.INSTANCE.generalCss().textMedium());
    m_panel.add(m_textboxContainer);
    m_panel.add(m_error);
    m_textboxContainer.add(m_textbox);
    m_textboxContainer.setPaddingX(4);
    sinkEvents(Event.ONPASTE);
    initWidget(m_panel);
}

From source file:com.alkacon.geranium.client.ui.input.TextBox.java

License:Open Source License

/**
 * @see com.google.gwt.user.client.ui.Composite#onBrowserEvent(com.google.gwt.user.client.Event)
 *///  ww w  .  j ava2 s  . co  m
@Override
public void onBrowserEvent(Event event) {

    super.onBrowserEvent(event);
    /* 
     * In IE8, the change event is not fired if we switch to another application window after having 
     * pasted some text into the text box, so we need to turn off ghost mode manually 
     */
    if (event.getTypeInt() == Event.ONPASTE) {
        setGhostMode(false);
    }
}

From source file:com.codenvy.plugin.contribution.client.dialogs.paste.PasteAwareTextBox.java

License:Open Source License

public PasteAwareTextBox() {
    sinkEvents(Event.ONPASTE);
}

From source file:com.codenvy.plugin.contribution.client.dialogs.paste.PasteAwareTextBox.java

License:Open Source License

public PasteAwareTextBox(final Element element) {
    super(element);
    sinkEvents(Event.ONPASTE);
}

From source file:com.codenvy.plugin.contribution.client.dialogs.paste.PasteAwareTextBox.java

License:Open Source License

@Override
public void onBrowserEvent(final Event event) {
    super.onBrowserEvent(event);
    switch (event.getTypeInt()) {
    case Event.ONPASTE:
        event.stopPropagation();/*from ww  w  . ja v  a2  s  . c  o m*/
        delayedFireEvent();
        break;
    default:
        break;
    }
}

From source file:com.google.gerrit.client.admin.CreateGroupScreen.java

License:Apache License

private void addCreateGroupPanel() {
    VerticalPanel addPanel = new VerticalPanel();
    addPanel.setStyleName(Gerrit.RESOURCES.css().addSshKeyPanel());
    addPanel.add(new SmallHeading(Util.C.headingCreateGroup()));

    addTxt = new NpTextBox() {
        @Override/*from  w w w . ja va2 s .  c om*/
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (event.getTypeInt() == Event.ONPASTE) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        if (addTxt.getValue().trim().length() != 0) {
                            addNew.setEnabled(true);
                        }
                    }
                });
            }
        }
    };
    addTxt.sinkEvents(Event.ONPASTE);

    addTxt.setVisibleLength(60);
    addTxt.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doCreateGroup();
            }
        }
    });
    addPanel.add(addTxt);

    addNew = new Button(Util.C.buttonCreateGroup());
    addNew.setEnabled(false);
    addNew.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            doCreateGroup();
        }
    });
    addPanel.add(addNew);
    add(addPanel);

    new OnEditEnabler(addNew, addTxt);
}

From source file:com.google.gerrit.client.admin.CreateProjectScreen.java

License:Apache License

private void initCreateTxt() {
    project = new NpTextBox() {
        @Override// w w w.j a  v  a 2  s. com
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (event.getTypeInt() == Event.ONPASTE) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        if (project.getValue().trim().length() != 0) {
                            create.setEnabled(true);
                        }
                    }
                });
            }
        }
    };
    project.sinkEvents(Event.ONPASTE);
    project.setVisibleLength(50);
    project.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doCreateProject();
            }
        }
    });
    new OnEditEnabler(create, project);
}