Java Code Examples for com.google.gwt.event.dom.client.KeyCodes#KEY_ESCAPE

The following examples show how to use com.google.gwt.event.dom.client.KeyCodes#KEY_ESCAPE . 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: AutoCompleteTextFieldConnector.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void handlePanelEventDelegation(final KeyUpEvent event) {
    switch (event.getNativeKeyCode()) {
    case KeyCodes.KEY_DOWN:
        arrowKeyDown(event);
        break;
    case KeyCodes.KEY_UP:
        arrorKeyUp(event);
        break;
    case KeyCodes.KEY_ESCAPE:
        escapeKey();
        break;
    case KeyCodes.KEY_ENTER:
        enterKey();
        break;
    default:
        doAskForSuggestion();
    }
}
 
Example 2
Source File: ToggleTool.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
private KeyUpHandler setEscapeHandler() {
	KeyUpHandler handler = new KeyUpHandler() {
		@Override
		public void onKeyUp(final KeyUpEvent event) {
			if (KeyCodes.KEY_ESCAPE == event.getNativeEvent().getKeyCode()) {
				for (Control control : controls) {
					try {
						((DrawFeature) control).cancel();
					} catch (Exception e) {
						LOGGER.error("ACTION CANCELED: "
								+ control.getControlId());
					}
				}
			}
		}
	};
	return handler;
}
 
Example 3
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 4
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 5
Source File: MessageCenterView.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 6
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key was depressed.
 *
 * @param event
 *            The KeyUpEvent of the key depressed
 */
@Override
public void onKeyUp(KeyUpEvent event) {
	debug("VComboBoxMultiselect: onKeyUp(" + event.getNativeKeyCode() + ")");

	if (this.enabled && !this.readonly) {
		switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_ENTER:
		case KeyCodes.KEY_TAB:
		case KeyCodes.KEY_SHIFT:
		case KeyCodes.KEY_CTRL:
		case KeyCodes.KEY_ALT:
		case KeyCodes.KEY_DOWN:
		case KeyCodes.KEY_UP:
		case KeyCodes.KEY_PAGEDOWN:
		case KeyCodes.KEY_PAGEUP:
		case KeyCodes.KEY_ESCAPE:
			// NOP
			break;
		default:
			if (this.textInputEnabled) {
				// when filtering, we always want to see the results on the
				// first page first.
				filterOptions(0);
			}
			break;
		}
	}
}
 
Example 7
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 8
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 9
Source File: CubaSearchSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyUp(KeyUpEvent event) {
    if (enabled && !readonly) {
        switch (event.getNativeKeyCode()) {
            case KeyCodes.KEY_ENTER:
                String tbText = tb.getText() == null ? ""
                        : tb.getText();
                String currentText = currentSuggestion == null ? ""
                        : currentSuggestion.getReplacementString();
                if (!this.preventFilterAfterSelect && !tbText.equals(currentText)) {
                    filterOptions(currentPage);
                } else {
                    if (!event.isAnyModifierKeyDown()) {
                        event.stopPropagation();
                    }
                }
                this.preventFilterAfterSelect = false;
                break;
            case KeyCodes.KEY_TAB:
            case KeyCodes.KEY_SHIFT:
            case KeyCodes.KEY_CTRL:
            case KeyCodes.KEY_ALT:
            case KeyCodes.KEY_DOWN:
            case KeyCodes.KEY_UP:
            case KeyCodes.KEY_PAGEDOWN:
            case KeyCodes.KEY_PAGEUP:
                // NOP
                break;
            case KeyCodes.KEY_ESCAPE:
                reset();
                break;
        }
        updateEditState();
    }
}
 
Example 10
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key was depressed.
 *
 * @param event
 *            The KeyUpEvent of the key depressed
 */
@Override
public void onKeyUp(KeyUpEvent event) {
	debug("VComboBoxMultiselect: onKeyUp(" + event.getNativeKeyCode() + ")");

	if (this.enabled && !this.readonly) {
		switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_ENTER:
		case KeyCodes.KEY_TAB:
		case KeyCodes.KEY_SHIFT:
		case KeyCodes.KEY_CTRL:
		case KeyCodes.KEY_ALT:
		case KeyCodes.KEY_DOWN:
		case KeyCodes.KEY_UP:
		case KeyCodes.KEY_PAGEDOWN:
		case KeyCodes.KEY_PAGEUP:
		case KeyCodes.KEY_ESCAPE:
			// NOP
			break;
		default:
			if (this.textInputEnabled) {
				// when filtering, we always want to see the results on the
				// first page first.
				filterOptions(0);
			}
			break;
		}
	}
}
 
Example 11
Source File: DefaultPopup.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 12
Source File: YoungAndroidDefaultURLPropertyEditor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void handleKeyUp(int keyCode) {
  if (keyCode == KeyCodes.KEY_ESCAPE) {
    // Pressing <esc> will reset the content of the editor to the previous property value as well
    // as surrender focus.
    updateValue();  // Restore previous property value.
    urlField.cancelKey();
    urlField.setFocus(false);
  }
}
 
Example 13
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 14
Source File: TextPropertyEditorBase.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void handleKeyUp(int keyCode) {
  if (keyCode == KeyCodes.KEY_ESCAPE) {
    // Pressing <esc> will reset the content of the editor to the previous property value as well
    // as surrender focus.
    updateValue();  // Restore previous property value.
    textEdit.cancelKey();
    textEdit.setFocus(false);
  }
}
 
Example 15
Source File: UniTimeDialogBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
	super.onPreviewNativeEvent(event);
	if (isEscapeToHide() && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
		AriaStatus.getInstance().setText(ARIA.dialogClosed(getText()));
		hide();
	} if (isEnterToSubmit() && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
		event.getNativeEvent().stopPropagation();
		event.getNativeEvent().preventDefault();
    	iSubmitHandler.execute();
	}
}
 
Example 16
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);
}
 
Example 17
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean handleKeyPress(int keyCode) {
	if (KeyEventUtils.isModifierKeyDown(Event.getCurrentEvent())) {
		return false;
	}
	boolean handleKey = false;
	switch (keyCode) {
		case KeyCodes.KEY_LEFT:
			CalendarUtil.addDaysToDate(this.cursor, -1);
			handleKey = true;
			break;
		case KeyCodes.KEY_RIGHT:
			CalendarUtil.addDaysToDate(this.cursor, 1);
			handleKey = true;
			break;
		case KeyCodes.KEY_UP:
			CalendarUtil.addDaysToDate(this.cursor, -7);
			handleKey = true;
			break;
		case KeyCodes.KEY_DOWN:
			CalendarUtil.addDaysToDate(this.cursor, 7);
			handleKey = true;
			break;
		case KeyCodes.KEY_PAGEUP:
			CalendarUtil.addMonthsToDate(this.cursor, -1);
			handleKey = true;
			break;
		case KeyCodes.KEY_PAGEDOWN:
			CalendarUtil.addMonthsToDate(this.cursor, 1);
			handleKey = true;
			break;
		case KeyCodes.KEY_ENTER:
			this.setValue(this.cursor, true);
			handleKey = true;
			break;
		case KeyCodes.KEY_ESCAPE:
			this.setValue(this.value);
			this.setFocus(false);
			handleKey = true;
			break;
		default:
			break;
	}
	if (handleKey) {
		this.redraw();
	}

	return handleKey;
}
 
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: EventPreviewAutoHiderRegistrar.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
  if (autoHiders.isEmpty()) {
    return;
  }

  // TODO(danilatos,user,user): Push signal down a layer - clean this up.
  Event event = Event.as(previewEvent.getNativeEvent());
  int lowLevelType = event.getTypeInt();

  // TODO(danilatos): Insert this logic deeply rather than
  // sprinkling it in event handlers. Also the return value
  // of onEventPreview is the reverse of signal handlers.
  SignalEvent signal = SignalEventImpl.create(event, false);
  if (signal == null) {
    return;
  }

  // Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
  if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
    if (hideTopmostAutoHiderForKeyEvent(false)) {
      // TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
      // menu we want, for example, space-bar to still shift focus to the next blip.
      // The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
      // it's not needed, eliminate it).
      return;
    }
  }

  // Pressing escape at any time causes us to close and discard the event.
  if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
      event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
    if (hideTopmostAutoHiderForKeyEvent(true)) {
      previewEvent.cancel();
      return;
    }
  }

  // Click events and mouse-wheel events that fall through use hideAllAfter.
  if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
    hideAllAfter(signal.getTarget());
  }

  // Otherwise we don't do anything and the event continues as usual.
}