Java Code Examples for com.google.gwt.user.client.Event#ONKEYDOWN

The following examples show how to use com.google.gwt.user.client.Event#ONKEYDOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageButton.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (!isEnabled()) return;

	super.onBrowserEvent(event);

    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
    	int type = DOM.eventGetType(event);
    	char keyCode = (char) event.getKeyCode();
    	switch (type) {
    	case Event.ONKEYDOWN:
    		if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
    			if (iDown != null) setResource(iDown);
    		}
    		break;
        case Event.ONKEYUP:
        	if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
        		setResource(iUp);
        		onClick();
        	}
        	break;
    	}
    }
}
 
Example 2
Source File: InputSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 3
Source File: SignalKeyLogic.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Common logic between Webkit and IE for deciding whether we want the keydown
 * or the keypress
 */
private static boolean maybeNullWebkitIE(boolean ret, int typeInt,
    KeySignalType type) {
  // Use keydown as the signal for everything except input.
  // This is because the mutation always happens after the keypress for
  // input (this is especially important for chrome,
  // which interleaves deferred commands between keydown and keypress).
  //
  // For everything else, keypress is redundant with keydown, and also, the resulting default
  // dom mutation (if any) often happens after the keydown but before the keypress in webkit.
  // Also, if the 'Command' key is held for chrome/safari etc, we want to get the keydown
  // event, NOT the keypress event, for everything because of things like ctrl+c etc.
  // where sometimes it'll happen just after the keydown, or sometimes we just won't
  // get a keypress at all
  if (typeInt == (type == KeySignalType.INPUT ? Event.ONKEYDOWN : Event.ONKEYPRESS)) {
    return false;
  }

  return ret;
}
 
Example 4
Source File: SignalKeyLogic.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Common logic between Webkit and IE for deciding whether we want the keydown
 * or the keypress
 */
private static boolean maybeNullWebkitIE(boolean ret, int typeInt,
    KeySignalType type) {
  // Use keydown as the signal for everything except input.
  // This is because the mutation always happens after the keypress for
  // input (this is especially important for chrome,
  // which interleaves deferred commands between keydown and keypress).
  //
  // For everything else, keypress is redundant with keydown, and also, the resulting default
  // dom mutation (if any) often happens after the keydown but before the keypress in webkit.
  // Also, if the 'Command' key is held for chrome/safari etc, we want to get the keydown
  // event, NOT the keypress event, for everything because of things like ctrl+c etc.
  // where sometimes it'll happen just after the keydown, or sometimes we just won't
  // get a keypress at all
  if (typeInt == (type == KeySignalType.INPUT ? Event.ONKEYDOWN : Event.ONKEYPRESS)) {
    return false;
  }

  return ret;
}
 
Example 5
Source File: CubaScrollTableWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN && _delegate.shortcutHandler != null) {
        _delegate.shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 6
Source File: EventWrapper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static String asString(Event event) {
  // Start with the event type string
  String string = DOM.eventGetTypeString(event);
  // Next type-specific fields
  switch (event.getTypeInt()) {
  case Event.ONKEYPRESS:
  case Event.ONKEYUP:
  case Event.ONKEYDOWN:
    string += key(event) + modifiers(event);
    break;
  case Event.ONCLICK:
  case Event.ONDBLCLICK:
  case Event.ONMOUSEMOVE:
    string += mousePoint(event) + modifiers(event);
    break;
  case Event.ONMOUSEDOWN:
  case Event.ONMOUSEUP:
    string += mousePoint(event) + mouseButtons(event) + modifiers(event);
    break;
  case Event.ONMOUSEOUT:
    string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event);
    break;
  case Event.ONMOUSEOVER:
    string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event);
    break;
  case Event.ONMOUSEWHEEL:
    string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event);
    break;
  case Event.ONFOCUS:
  case Event.ONBLUR:
  case Event.ONCHANGE:
  case Event.ONERROR:
  case Event.ONLOAD:
  case Event.ONLOSECAPTURE:
  case Event.ONSCROLL:
    break;
  }
  return string;
}
 
Example 7
Source File: EventWrapper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * @return A string describing which modifier keys were pressed,
 *        and whether this was a repeat event,  e.g., " shift ctrl"
 */
@SuppressWarnings("deprecation")
public static String modifiers(Event event) {
  // repeat is deprecated, but useful for debugging
  return (event.getAltKey() ? " alt" : "")
  + (event.getShiftKey() ? " shift" : "")
  + (event.getCtrlKey() ? " ctrl" : "")
  + (event.getMetaKey() ? " meta" : "")
  + ((event.getTypeInt() == Event.ONKEYDOWN) && event.getRepeat() ? " repeat" : "");
}
 
Example 8
Source File: Tab.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    int type = DOM.eventGetType(event);
    switch (type) {
        case Event.ONKEYDOWN:
            if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                tabLayout.selectTab(index);
                event.stopPropagation();
            }
            break;
        default:
            break;
    }
}
 
Example 9
Source File: CubaCssActionsLayoutWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN && shortcutHandler != null) {
        shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 10
Source File: MessageCenterView.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private PopupPanel createDisplay(Message message) {
    PopupPanel displayPopup = new PopupPanel() {
        {
            this.sinkEvents(Event.ONKEYDOWN);

            getElement().setAttribute("role", "alert");
            getElement().setAttribute("aria-live", "assertive");

            if(!message.isSticky()) {
                setAutoHideEnabled(true);
                setAutoHideOnHistoryEventsEnabled(true);
            }
        }

        @Override
        protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (Event.ONKEYDOWN == event.getTypeInt()) {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
                    // Dismiss when escape is pressed
                    hide();
                }
            }
        }
    };

    displayPopup.addStyleName("back");
    return displayPopup;
}
 
Example 11
Source File: EventWrapper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public static String asString(Event event) {
  // Start with the event type string
  String string = DOM.eventGetTypeString(event);
  // Next type-specific fields
  switch (event.getTypeInt()) {
  case Event.ONKEYPRESS:
  case Event.ONKEYUP:
  case Event.ONKEYDOWN:
    string += key(event) + modifiers(event);
    break;
  case Event.ONCLICK:
  case Event.ONDBLCLICK:
  case Event.ONMOUSEMOVE:
    string += mousePoint(event) + modifiers(event);
    break;
  case Event.ONMOUSEDOWN:
  case Event.ONMOUSEUP:
    string += mousePoint(event) + mouseButtons(event) + modifiers(event);
    break;
  case Event.ONMOUSEOUT:
    string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event);
    break;
  case Event.ONMOUSEOVER:
    string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event);
    break;
  case Event.ONMOUSEWHEEL:
    string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event);
    break;
  case Event.ONFOCUS:
  case Event.ONBLUR:
  case Event.ONCHANGE:
  case Event.ONERROR:
  case Event.ONLOAD:
  case Event.ONLOSECAPTURE:
  case Event.ONSCROLL:
    break;
  }
  return string;
}
 
Example 12
Source File: CubaTextFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);

    if (type == Event.ONKEYDOWN && shortcutHandler != null) {
        shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 13
Source File: CubaTreeTableWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN && _delegate.shortcutHandler != null) {
        _delegate.shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 14
Source File: OffPageSelector.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example 15
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	int type = event.getTypeInt();
	Element target = event.getCurrentTarget();
	if (type == Event.ONCLICK) {
		String dataDate = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_DATE);
		String dataCursor = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR);
		String dataYear = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_YEAR);
		if (dataDate != null && dataDate.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.setValue(InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataDate), true);
		} else if (dataCursor != null && dataCursor.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.cursor = InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataCursor);
			this.redraw();
		} else if (dataYear != null && dataYear.length() > 0) {
			this.openMonthOfYear(Integer.valueOf(dataYear));
		} else if (target == this.monthPickerButton) {
			if (this.mode != Mode.MONTH) {
				this.mode = Mode.MONTH;
			} else {
				this.mode = Mode.CALENDAR;
			}
			this.redraw();
		}
		event.stopPropagation();
		event.preventDefault();
	} else if (type == Event.ONKEYDOWN) {
		this.handleKeyPress(event.getKeyCode());
		event.stopPropagation();
		event.preventDefault();
	} else {
		super.onBrowserEvent(event);
	}
}
 
Example 16
Source File: CubaGridLayoutWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN && shortcutHandler != null) {
        shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 17
Source File: CubaDateFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);

    if (type == Event.ONKEYDOWN && shortcutHandler != null) {
        shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example 18
Source File: SuggestionMenu.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
private void handleEventInner(Event event) {
  switch (DOM.eventGetType(event)) {
    case Event.ONCONTEXTMENU:
      event.preventDefault();
      break;
    case Event.ONKEYPRESS:
    case Event.ONKEYDOWN: {
      // NOTE(user): It is necessary to stop propagation on the key events to
      // prevent them from leaking to the blip/wave presenters.
      int keyCode = DOM.eventGetKeyCode(event);

      // Move left/right to previous/next drop down widget
      switch (keyCode) {
        case KeyCodes.KEY_LEFT:
        case KeyCodes.KEY_RIGHT:
          handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT);
          event.stopPropagation();
          return;
        case KeyCodes.KEY_ENTER:
          event.stopPropagation();
      }

      if (keyCode >= '1' && keyCode <= '9') {
        // TODO(danilatos): Is this ok? i18n etc?
        int index = keyCode - '1';

        if (index >= 0 && index < getItems().size()) {
          MenuItem item = getItems().get(index);
          if (item == null) {
            return;
          }

          item.getCommand().execute();
          DOM.eventPreventDefault(event);
        }
      }
      break;
    }
    case Event.ONMOUSEOUT: {
      // Need to check that we really seem to have left the menu, as
      // mouse-out events get triggered whenever the mouse moves between
      // selections in the menu.
      EventTarget target = event.getRelatedEventTarget();
      Element targetElement = Element.as(target);
      if (!getElement().isOrHasChild(targetElement)) {
        handler.handleMouseOut();
      }
      break;
    }
    case Event.ONMOUSEOVER: {
      handler.handleMouseOver();
      break;
    }
  }
}
 
Example 19
Source File: CubaButtonWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleKeyboardEvents(Event event) {
    int type = DOM.eventGetType(event);
    // Synthesize clicks based on keyboard events AFTER the normal key
    // handling.
    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
        switch (type) {
            case Event.ONKEYDOWN:
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                // Stop propagation when the user starts pressing a button that
                // we are handling to prevent actions from getting triggered
                if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                }
                break;

            // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
            case Event.ONKEYUP:
                if (isFocusing) {
                    if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    }
                } else if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                break;
            case Event.ONKEYPRESS: {
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 20
Source File: SuggestionsContainer.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    if (getElement() == DOM.eventGetTarget(event)) {
        return;
    }

    SuggestionItem item = findItem(DOM.eventGetTarget(event));
    switch (DOM.eventGetType(event)) {
        case Event.ONMOUSEDOWN: {
            if (BrowserInfo.get().isIE()) {
                suggestionFieldWidget.iePreventBlur = true;
            }
            break;
        }

        case Event.ONCLICK: {
            if (event.getButton() == NativeEvent.BUTTON_LEFT) {
                performItemCommand(item);
            }
            break;
        }

        case Event.ONMOUSEOVER: {
            if (item != null) {
                selectItem(item);
            }
            break;
        }

        case Event.ONKEYDOWN: {
            int keyCode = KeyCodes.maybeSwapArrowKeysForRtl(
                    event.getKeyCode(),
                    LocaleInfo.getCurrentLocale().isRTL()
            );

            switch (keyCode) {
                case KeyCodes.KEY_UP:
                    selectPrevItem();
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_DOWN:
                    selectNextItem();
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_ESCAPE:
                    selectItem(null);
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_TAB:
                    selectItem(null);
                    break;
                case KeyCodes.KEY_ENTER:
                    performItemCommand(item);
                    preventEvent(event);
                    break;
            }
            break;
        }
    }
    super.onBrowserEvent(event);
}