Java Code Examples for com.google.gwt.event.dom.client.KeyDownEvent#getNativeKeyCode()

The following examples show how to use com.google.gwt.event.dom.client.KeyDownEvent#getNativeKeyCode() . 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: SinglePageLayout.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	int key = event.getNativeKeyCode();
	if (event.isControlKeyDown()) {
		if (key == KEY_PLUS || key == KEY_MINUS) {
			app.getToolbar().zoomChangeClicked(key == KEY_PLUS ? 1 : -1);
			event.preventDefault();
		}
	} else if (!event.isShiftKeyDown()) {
		boolean handled = true;
		switch (key) {
		case KeyCodes.KEY_HOME:
			changePage(0, -1, -1);
			break;
		case KeyCodes.KEY_END:
			changePage(dataStore.getPageCount() - 1, 1, 1);
			break;
		default:
			handled = false;
		}
		if (handled)
			event.preventDefault();
	}
}
 
Example 2
Source File: KeyShortcutHandler.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onKeyDown(final KeyDownEvent event) {

	if (event.getNativeKeyCode() == keyCode) {				
		actionButton.fireEvent( new GwtEvent<ClickHandler>() {
	        @Override
	        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
	        	return ClickEvent.getType();
	        }
	        @Override
	        protected void dispatch(final ClickHandler handler) {
	            handler.onClick(null);
	        }
	   });
	}
}
 
Example 3
Source File: CubaOptionGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example 4
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				Element activeElement = FocusUtils.getActiveElement();
				if (activeElement != null && !CompositeFocusHelper.this.isOrHasChildOfContainerOrPartner(activeElement)) {
					CompositeFocusHelper.this.blur();
				}
			}
		});
	}
}
 
Example 5
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (!InputSlider.this.isStateValid()) {
		return;
	}
	int paddingValue = 1;
	if (event.isControlKeyDown()) {
		paddingValue = InputSlider.this.items.size() / 5;
	}
	switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_HOME:
			InputSlider.this.handleWidget.moveStart();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_END:
			InputSlider.this.handleWidget.moveEnd();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_SPACE:
			InputSlider.this.handleWidget.moveMiddle();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_LEFT:
			InputSlider.this.handleWidget.moveLeft(paddingValue);
			this.killEvent(event);
			break;
		case KeyCodes.KEY_RIGHT:
			InputSlider.this.handleWidget.moveRight(paddingValue);
			this.killEvent(event);
			break;
		default:
			break;
	}
}
 
Example 6
Source File: UTCTimeBoxImplHtml4.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    switch (event.getNativeKeyCode()) {
    case KeyCodes.KEY_UP:
        menu.adjustHighlight(-1);
        break;
    case KeyCodes.KEY_DOWN:
        menu.adjustHighlight(1);
        break;
    case KeyCodes.KEY_ENTER:
    case KeyCodes.KEY_TAB:
        // accept current value
        if (menu.isShowing()) {
            menu.acceptHighlighted();
            hideMenu();
            clearInvalidStyle();
        } 
        else {
            
            // added a sync here because this is when we
            // accept the value we've typed if we're typing in
            // a new value.
            syncValueToText();
            
            validate();
        }
        break;
    case KeyCodes.KEY_ESCAPE:
        validate();
        hideMenu();
        break;
    default:
        hideMenu();
        clearInvalidStyle();
        break;
    }
}
 
Example 7
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key is pressed in the text box
 *
 * @param event
 *            The KeyDownEvent
 */
private void inputFieldKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");

	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
	case KeyCodes.KEY_UP:
	case KeyCodes.KEY_PAGEDOWN:
	case KeyCodes.KEY_PAGEUP:
		// open popup as from gadget
		filterOptions(-1, "");
		this.tb.selectAll();
		this.dataReceivedHandler.popupOpenerClicked();
		break;
	case KeyCodes.KEY_ENTER:
		/*
		 * This only handles the case when new items is allowed, a text is
		 * entered, the popup opener button is clicked to close the popup
		 * and enter is then pressed (see #7560).
		 */
		if (!this.allowNewItems) {
			return;
		}

		if (this.currentSuggestion != null && this.tb.getText()
			.equals(this.currentSuggestion.getReplacementString())) {
			// Retain behavior from #6686 by returning without stopping
			// propagation if there's nothing to do
			return;
		}
		this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());

		event.stopPropagation();
		break;
	}

}
 
Example 8
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (this.enabled && !this.readonly) {
		int keyCode = event.getNativeKeyCode();

		debug("VComboBoxMultiselect: key down: " + keyCode);

		if (this.dataReceivedHandler.isWaitingForFilteringResponse() && navigationKeyCodes.contains(keyCode)
				&& (!this.allowNewItems || keyCode != KeyCodes.KEY_ENTER)) {
			/*
			 * Keyboard navigation events should not be handled while we are
			 * waiting for a response. This avoids flickering, disappearing
			 * items, wrongly interpreted responses and more.
			 */
			debug("Ignoring " + keyCode + " because we are waiting for a filtering response");

			DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
			event.stopPropagation();
			return;
		}

		if (this.suggestionPopup.isAttached()) {
			debug("Keycode " + keyCode + " target is popup");
			popupKeyDown(event);
		} else {
			debug("Keycode " + keyCode + " target is text field");
			inputFieldKeyDown(event);
		}
	}
}
 
Example 9
Source File: SuggestPopup.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	int keyCode = event.getNativeKeyCode();
	if (keyCode == KeyCodes.KEY_ENTER
			&& choiceList.getSelectedIndex() != -1) {
		event.preventDefault();
		event.stopPropagation();
		select();
	} else if (keyCode == KeyCodes.KEY_ESCAPE) {
		event.preventDefault();
		close();
	}
}
 
Example 10
Source File: MonthGrid.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    int keycode = event.getNativeKeyCode();
    if (KeyCodes.KEY_ESCAPE == keycode && selectionStart != null) {
        cancelRangeSelection();
    }
}
 
Example 11
Source File: CubaCheckBoxGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example 12
Source File: CubaCheckBoxWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadOnly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example 13
Source File: CubaRadioButtonGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example 14
Source File: CubaSearchSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void inputFieldKeyDown(KeyDownEvent event) {
    if (KeyCodes.KEY_ENTER == event.getNativeKeyCode()
            && !event.isAnyModifierKeyDown()) {
        event.stopPropagation();
    }
}
 
Example 15
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key is pressed in the text box
 *
 * @param event
 *            The KeyDownEvent
 */
private void inputFieldKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");

	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
	case KeyCodes.KEY_UP:
	case KeyCodes.KEY_PAGEDOWN:
	case KeyCodes.KEY_PAGEUP:
		// open popup as from gadget
		filterOptions(-1, "");
		this.tb.selectAll();
		this.dataReceivedHandler.popupOpenerClicked();
		break;
	case KeyCodes.KEY_ENTER:
		/*
		 * This only handles the case when new items is allowed, a text is
		 * entered, the popup opener button is clicked to close the popup
		 * and enter is then pressed (see #7560).
		 */
		if (!this.allowNewItems) {
			return;
		}

		if (this.currentSuggestion != null && this.tb.getText()
			.equals(this.currentSuggestion.getReplacementString())) {
			// Retain behavior from #6686 by returning without stopping
			// propagation if there's nothing to do
			return;
		}
		this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());

		event.stopPropagation();
		break;
	}

}
 
Example 16
Source File: YoungAndroidPalettePanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
  if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
    searchResults.clear();
    searchText.setText("");
  }
}
 
Example 17
Source File: CubaSearchSelectWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void popupKeyDown(KeyDownEvent event) {
    // Propagation of handled events is stopped so other handlers such as
    // shortcut key handlers do not also handle the same events.
    switch (event.getNativeKeyCode()) {
        case KeyCodes.KEY_DOWN:
            keyboardNavigation = true;
            suggestionPopup.selectNextItem();
            suggestionPopup.menu.selectItem(suggestionPopup.menu
                    .getSelectedItem());
            DOM.eventGetCurrentEvent().preventDefault();
            event.stopPropagation();
            break;
        case KeyCodes.KEY_UP:
            keyboardNavigation = true;
            suggestionPopup.selectPrevItem();
            suggestionPopup.menu.selectItem(suggestionPopup.menu
                    .getSelectedItem());
            DOM.eventGetCurrentEvent().preventDefault();
            event.stopPropagation();
            break;
        case KeyCodes.KEY_PAGEDOWN:
            keyboardNavigation = false;
            if (hasNextPage()) {
                filterOptions(currentPage + 1, lastFilter);
            }
            event.stopPropagation();
            break;
        case KeyCodes.KEY_PAGEUP:
            keyboardNavigation = false;
            if (currentPage > 0) {
                filterOptions(currentPage - 1, lastFilter);
            }
            event.stopPropagation();
            break;
        case KeyCodes.KEY_ESCAPE:
            keyboardNavigation = false;
            reset();
            event.stopPropagation();
            break;
        case KeyCodes.KEY_TAB:
        case KeyCodes.KEY_ENTER:
            int selectedIndex = suggestionPopup.menu.getSelectedIndex();
            currentSuggestion = currentSuggestions.get(selectedIndex);
            if (currentSuggestion != null &&
                    currentSuggestion.getReplacementString().equals(tb.getText())) {
                this.preventFilterAfterSelect = true;
                onSuggestionSelected(currentSuggestion);
            }

            keyboardNavigation = false;

            event.stopPropagation();
            break;
    }
}
 
Example 18
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
/**
 * Triggered when a key was pressed in the suggestion popup.
 *
 * @param event
 *            The KeyDownEvent of the key
 */
private void popupKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: popupKeyDown(" + event.getNativeKeyCode() + ")");

	// Propagation of handled events is stopped so other handlers such as
	// shortcut key handlers do not also handle the same events.
	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
		this.suggestionPopup.selectNextItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_UP:
		this.suggestionPopup.selectPrevItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEDOWN:
		selectNextPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEUP:
		selectPrevPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_ESCAPE:
		reset();
		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_TAB:
	case KeyCodes.KEY_ENTER:

		// queue this, may be cancelled by selection
		int selectedIndex = this.suggestionPopup.menu.getSelectedIndex();
		if (!this.allowNewItems && selectedIndex != -1) {

			debug("index before: " + selectedIndex);
			if (this.showClearButton) {
				selectedIndex = selectedIndex - 1;
			}
			if (this.showSelectAllButton) {
				selectedIndex = selectedIndex - 1;
			}

			debug("index after: " + selectedIndex);
			if (selectedIndex == -2) {
				this.clearCmd.execute();
			} else if (selectedIndex == -1) {
				if (this.showSelectAllButton) {
					this.selectAllCmd.execute();
				} else {
					this.clearCmd.execute();
				}
			}

			debug("entered suggestion: " + this.currentSuggestions.get(selectedIndex).caption);
			onSuggestionSelected(this.currentSuggestions.get(selectedIndex));
		} else {
			this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());
		}

		event.stopPropagation();
		break;
	}
}
 
Example 19
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
/**
 * Triggered when a key was pressed in the suggestion popup.
 *
 * @param event
 *            The KeyDownEvent of the key
 */
private void popupKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: popupKeyDown(" + event.getNativeKeyCode() + ")");

	// Propagation of handled events is stopped so other handlers such as
	// shortcut key handlers do not also handle the same events.
	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
		this.suggestionPopup.selectNextItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_UP:
		this.suggestionPopup.selectPrevItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEDOWN:
		selectNextPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEUP:
		selectPrevPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_ESCAPE:
		reset();
		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_TAB:
	case KeyCodes.KEY_ENTER:

		// queue this, may be cancelled by selection
		int selectedIndex = this.suggestionPopup.menu.getSelectedIndex();
		if (!this.allowNewItems && selectedIndex != -1) {

			debug("index before: " + selectedIndex);
			if (this.showClearButton) {
				selectedIndex = selectedIndex - 1;
			}
			if (this.showSelectAllButton) {
				selectedIndex = selectedIndex - 1;
			}

			debug("index after: " + selectedIndex);
			if (selectedIndex == -2) {
				this.clearCmd.execute();
			} else if (selectedIndex == -1) {
				if (this.showSelectAllButton) {
					this.selectAllCmd.execute();
				} else {
					this.clearCmd.execute();
				}
			}

			debug("entered suggestion: " + this.currentSuggestions.get(selectedIndex).caption);
			onSuggestionSelected(this.currentSuggestions.get(selectedIndex));
		} else {
			this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());
		}

		event.stopPropagation();
		break;
	}
}
 
Example 20
Source File: MaskValueBoxHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void onKeyDown(KeyDownEvent event) {
	this.keyDown = event.getNativeKeyCode();
	boolean preventDefault = false;
	switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_DELETE:
		case KeyCodes.KEY_BACKSPACE:
			if (this.token != null) {
				this.reset();
				this.maskHelper.refreshValueBox();
				event.preventDefault();
			}
			break;
		case KeyCodes.KEY_DOWN:
		case KeyCodes.KEY_UP:
			event.preventDefault();
			break;
		case KeyCodes.KEY_LEFT:
			preventDefault = this.maskHelper.focusPrevious();
			break;
		case KeyCodes.KEY_RIGHT:
			preventDefault = this.maskHelper.focusNext();

			break;
		case KeyCodes.KEY_TAB:
			if (event.isShiftKeyDown()) {
				preventDefault = this.maskHelper.focusPrevious();
			} else {
				preventDefault = this.maskHelper.focusNext();
			}
			break;
		default:
			break;
	}

	if (preventDefault) {
		event.preventDefault();
	}
	if (this.handleKeyDown(this.keyDown)) {
		this.maskHelper.refreshValueBox();
		this.schedule(this.maskHelper.initialDelayMilis);
	}
}