Exemple #1
0
    @Override
    public void onKeyPress(KeyPressEvent event) {
      if (isReadOnly()
          || !isEnabled()
          || event.getNativeEvent().getCtrlKey()
          || event.getNativeEvent().getAltKey()) {
        return;
      }

      switch (event.getNativeEvent().getKeyCode()) {
        case KeyCodes.KEY_LEFT:
        case KeyCodes.KEY_RIGHT:
        case KeyCodes.KEY_BACKSPACE:
        case KeyCodes.KEY_DELETE:
        case KeyCodes.KEY_UP:
        case KeyCodes.KEY_PAGEUP:
        case KeyCodes.KEY_DOWN:
        case KeyCodes.KEY_PAGEDOWN:
        case KeyCodes.KEY_TAB:
          return;
      }

      String newText = getNewText(event.getCharCode());
      if ("-".equals(newText)
          || numberType == NumberType.DECIMAL
              && newText.endsWith(".")
              && newText.length() > 1
              && !newText.substring(0, newText.length() - 1).contains(".")) {
        return;
      }

      cancelKey();
      setValue(newText, true);
    }
 @Override
 public void onKeyPress(KeyPressEvent event) {
   // for default text
   if (moreInfoText.equals(textbox.getText())
       && !(event.getNativeEvent().getKeyCode() == KeyCodes.KEY_TAB)) {
     hidePrompt();
   }
   if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
     enterKeyPressed(event);
   }
 }
Exemple #3
0
        @Override
        public void onKeyPress(KeyPressEvent event) {

          if (isReadOnly() || !isEnabled()) {
            return;
          }

          int keyCode = event.getNativeEvent().getKeyCode();

          switch (keyCode) {
            case KeyCodes.KEY_LEFT:
            case KeyCodes.KEY_RIGHT:
            case KeyCodes.KEY_BACKSPACE:
              // case KeyCodes.KEY_DELETE:
            case KeyCodes.KEY_TAB:
            case KeyCodes.KEY_UP:
            case KeyCodes.KEY_DOWN:
              return;
          }

          char charCode = event.getCharCode();

          // check for decimal ','
          if (('.' == charCode || ',' == charCode)
              && (getValue() == null || (!getText().contains(",") && !getText().contains(".")))) {
            return;
          }

          // filter out non-digits
          if (Character.isDigit(charCode)) {
            return;
          }

          cancelKey();
        }
Exemple #4
0
  /**
   * The date box on key down action.
   *
   * <p>
   *
   * <ul>
   *   <li>If enter or tab is pressed in the date box the date time picker should be updated with
   *       the value from the date box.
   *   <li>If the escape key is pressed the picker should be hided.
   *   <li>If the up key is pressed the value should be taken from the date box.
   *   <li>If the down key is pressed the picker should be hided.
   * </ul>
   *
   * @param event the key down event
   */
  protected void onDateBoxKeyPress(KeyPressEvent event) {

    switch (event.getNativeEvent().getKeyCode()) {
      case KeyCodes.KEY_ENTER:
      case KeyCodes.KEY_TAB:
      case KeyCodes.KEY_ESCAPE:
      case KeyCodes.KEY_UP:
        updateFromTextBox();
        hidePopup();
        break;
      case KeyCodes.KEY_DOWN:
        showPopup();
        break;
      default:
        hidePopup();
        Scheduler.get()
            .scheduleDeferred(
                new ScheduledCommand() {

                  public void execute() {

                    updateCloseBehavior();
                    if (isValideDateBox()) {
                      setErrorMessage(null);
                    }
                  }
                });
        break;
    }
  }
Exemple #5
0
 /**
  * The onKeyPress method handles all keys that were held down and then lifted up, after the
  * KeyDown and KeyUp events are triggered
  */
 @Override
 public void onKeyPress(KeyPressEvent event) {
   code = new Code(event);
   if (code.getCharCode() > 31 && code.getCharCode() < 127) {
     processCode(code);
     event.getNativeEvent().stopPropagation();
     event.getNativeEvent().preventDefault();
   }
 }
 @Override
 public void onKeyPress(KeyPressEvent event) {
   // if the key is enter in the search box, search
   if (event.getSource() == searchBox
       && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER
       && !event.isAnyModifierKeyDown()) {
     // should send the correct sender
     onClick(null);
   }
 }
 @Override
 public void onKeyPress(KeyPressEvent event) {
   Event nativeEvent = (Event) event.getNativeEvent();
   if (!ignoreNextKeyPress) {
     if (!nativeEvent.isCancelled()) {
       handleRepeatableKey(nativeEvent);
     }
   } else if (cancelNextKeyPress) {
     nativeEvent.xPreventDefault();
   }
   ignoreNextKeyPress = false;
   cancelNextKeyPress = false;
 }
 protected void allowDigitsOnly(KeyPressEvent event) {
   event.getNativeEvent().getKeyCode();
   // This is for support for firefox for special characters like enter,tab,etc...
   if (event.getUnicodeCharCode() == 0) {
     return;
   }
   if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE
       || event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER
       || event.getNativeEvent().getKeyCode() == KeyCodes.KEY_TAB
       || event.getNativeEvent().getKeyCode() == 46 /*dot symbol*/
       || event.getUnicodeCharCode() == 46 /*firefox dot symbol*/
       || event.getNativeEvent().getKeyCode() == 45 /*minus symbol*/
       || event.getUnicodeCharCode() == 45 /*firefox minus symbol*/) {
     return;
   }
   if (!Character.isDigit(event.getCharCode())) {
     setMessage("invalid value");
     textbox.cancelKey();
   } else {
     clearMessage();
   }
 }
    @Override
    public void onKeyPress(KeyPressEvent event) {

      if (!scoreTextBox.isReadOnly()) {
        if (!Character.isDigit(event.getCharCode())
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_TAB
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_BACKSPACE
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_SHIFT
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_ENTER
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_LEFT
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_RIGHT
            && event.getNativeEvent().getKeyCode() != KeyCodes.KEY_DELETE) {
          ((TextBox) event.getSource()).cancelKey();

        } else if (event.getNativeEvent().getKeyCode() == 46) {
          ((TextBox) event.getSource()).cancelKey();
        } else {
          saveEnabled(true);
          saveBtn.removeStyleName(CssTokens.DISABLED);
          errorLabel.setVisible(false);
        }
      }
    }
Exemple #10
0
    /**
     * @see
     *     com.google.gwt.event.dom.client.KeyPressHandler#onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent)
     */
    public void onKeyPress(KeyPressEvent event) {

      int keyCode = event.getNativeEvent().getKeyCode();
      if (!isNavigationKey(keyCode)) {
        setGhostMode(false);
      }
      if (isTriggerChangeOnKeyPress()) {
        Scheduler.get()
            .scheduleDeferred(
                new ScheduledCommand() {

                  public void execute() {

                    checkForChange();
                  }
                });
      }
    }