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

The following examples show how to use com.google.gwt.event.dom.client.KeyCodes. These examples are extracted from open source projects. 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
@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 2
Source Project: consulo   Source File: CellBrowser.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onBrowserEvent2(Event event) {
  super.onBrowserEvent2(event);

  // Handle keyboard navigation between lists.
  String eventType = event.getType();
  if (BrowserEvents.KEYDOWN.equals(eventType) && !isKeyboardNavigationSuppressed()) {
    int keyCode = event.getKeyCode();
    boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
    keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
    switch (keyCode) {
      case KeyCodes.KEY_LEFT:
        keyboardNavigateShallow();
        return;
      case KeyCodes.KEY_RIGHT:
        keyboardNavigateDeep();
        return;
    }
  }
}
 
Example 3
Source Project: cuba   Source File: CubaNotification.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onEventPreview(Event event) {
    int type = DOM.eventGetType(event);

    if ((type == Event.ONCLICK || type == Event.ONTOUCHEND)
            && event.getEventTarget() != null) {
        Element target = Element.as(event.getEventTarget());
        if (containsSubstring(target.getClassName(), CUBA_NOTIFICATION_MODALITY_CURTAIN)) {
            hide();
            return false;
        }
    }

    if (type == Event.ONKEYDOWN && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
        if (!getElement().getClassName().contains(TRAY_STYLE)) {
            hide();
            return false;
        }
    }

    return super.onEventPreview(event);
}
 
Example 4
Source Project: gwt-traction   Source File: AutoSizingBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void onKeyCodeEvent(KeyCodeEvent event, String newShadowText) {
// ignore arrow keys
switch (event.getNativeKeyCode()) {
case KeyCodes.KEY_UP:
case KeyCodes.KEY_DOWN:
case KeyCodes.KEY_LEFT:
case KeyCodes.KEY_RIGHT:
    break;
default:
    // don't do this if there's a selection because it will get smaller
    if (box.getSelectionLength() == 0) {
	setShadowText(newShadowText);
	adjustSize();	    
	break;
    }
}	
   }
 
Example 5
Source Project: geowe-core   Source File: ToggleTool.java    License: GNU General Public License v3.0 6 votes vote down vote up
private KeyUpHandler setRedoHandler() {
	final KeyUpHandler handler = new KeyUpHandler() {
		@Override
		public void onKeyUp(final KeyUpEvent event) {
			if (KeyCodes.KEY_R == event.getNativeEvent().getKeyCode()) {
				for (final Control control : controls) {
					try {
						((DrawFeature) control).redo();
					} catch (Exception e) {
						LOGGER.error("ACTION REDO: "
								+ control.getControlId());
					}
				}
			}
		}
	};
	return handler;
}
 
Example 6
public void testDeleteWithRangeSelectedDeletesRange() {
  FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.DELETE, KeyCodes.KEY_LEFT);

  //Event event = Document.get().createKeyPressEvent(
  //    false, false, false, false, KeyCodes.KEY_BACKSPACE, 0).cast();

  Text input = Document.get().createTextNode("ABCDE");
  ContentNode node = new ContentTextNode(input, null);

  final Point<ContentNode> start = Point.inText(node, 1);
  final Point<ContentNode> end = Point.inText(node, 4);
  FakeEditorInteractor interactor = setupFakeEditorInteractor(
      new FocusedContentRange(start, end));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  interactor.call(FakeEditorInteractor.DELETE_RANGE).nOf(1).withArgs(
      start, end, false).returns(start);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example 7
Source Project: context-menu   Source File: VContextMenu.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleNavigation(int keycode, boolean ctrl, boolean shift) {
    if (keycode == KeyCodes.KEY_TAB) {
        return true;
    }
    if (keycode == getNavigationLeftKey() && (getParentMenu() == null
            || getParentMenu().getParentMenu() == null)) {
        // do not close parent menu by left key
        return true;
    }
    if (keycode == getNavigationRightKey() && getSelected() != null
            && getSelected().getSubMenu() == null) {
        // do not close menu by right key if there is no submenu
        return true;
    }
    return super.handleNavigation(keycode, ctrl, shift);
}
 
Example 8
Source Project: incubator-retired-wave   Source File: EditorEventHandler.java    License: Apache License 2.0 6 votes vote down vote up
private boolean handleNavigationKeyEvents(EditorEvent event) {
  editorInteractor.checkpoint(null);
  editorInteractor.clearCaretAnnotations();
  ContentNode node = cachedSelection.getFocus().getContainer();
  logger.trace().log("Navigation event");

  // Not using key combo, because we want to handle left key with
  // any modifiers also applying.
  // TODO(danilatos): MoveUnit, and holding down shift for selection.
  if (event.getKeyCode() == KeyCodes.KEY_LEFT) {
    router.handleLeft(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
    return !event.shouldAllowBrowserDefault();
  } else if (event.getKeyCode() == KeyCodes.KEY_RIGHT) {
    router.handleRight(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
    return !event.shouldAllowBrowserDefault();
  } else {
    editorInteractor.rebiasSelection(CursorDirection.NEUTRAL);
  }
  return false;
}
 
Example 9
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_ENTER:
				if (this.getDropdown().isOpen()) {
					((MultiSelectionHandler) this.getSelectionHandler()).onEnterKeyDown();
					mustKillEvent = true;
				}
				break;
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 10
Source Project: djvu-html5   Source File: SinglePageLayout.java    License: 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 11
Source Project: swellrt   Source File: EditorImpl.java    License: Apache License 2.0 6 votes vote down vote up
private boolean shouldTrackCursor(SignalEvent event) {
  if (event.isMouseButtonEvent()) {
    return true;
  }
  if (event.isKeyEvent()) {
    KeySignalType keySignalType = event.getKeySignalType();
    // The cursor location should move if the user either has modified the
    // content (typed or delete), or move the cursor deliberately.  However, page up/down
    // doesn't actually move the cursor, so we don't want to move the view port
    int keyCode = event.getKeyCode();
    return keySignalType == KeySignalType.INPUT ||
          keySignalType == KeySignalType.DELETE ||
          keySignalType == KeySignalType.NAVIGATION && (
             keyCode != KeyCodes.KEY_PAGEDOWN &&
             keyCode != KeyCodes.KEY_PAGEUP);
  }
  return false;
}
 
Example 12
Source Project: swellrt   Source File: EditorEventHandler.java    License: Apache License 2.0 6 votes vote down vote up
private boolean handleNavigationKeyEvents(EditorEvent event) {
  editorInteractor.checkpoint(null);
  editorInteractor.clearCaretAnnotations();
  ContentNode node = cachedSelection.getFocus().getContainer();
  logger.trace().log("Navigation event");

  // Not using key combo, because we want to handle left key with
  // any modifiers also applying.
  // TODO(danilatos): MoveUnit, and holding down shift for selection.
  if (event.getKeyCode() == KeyCodes.KEY_LEFT) {
    router.handleLeft(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);
    return !event.shouldAllowBrowserDefault();
  } else if (event.getKeyCode() == KeyCodes.KEY_RIGHT) {
    router.handleRight(node, event);
    editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT);
    return !event.shouldAllowBrowserDefault();
  } else {
    editorInteractor.rebiasSelection(CursorDirection.NEUTRAL);
  }
  return false;
}
 
Example 13
Source Project: calendar-component   Source File: MonthGrid.java    License: 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 14
private void handleKeyPress(char keyCode) {
  if (keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_TAB) {
    // Pressing <tab>, <enter> or <return> will surrender focus.
    textEdit.cancelKey();
    textEdit.setFocus(false);
  } else if (!validateKeyCode(keyCode)) {
    textEdit.cancelKey();
  }
}
 
Example 15
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 16
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 17
@Override
public void onKeyDown(KeyDownEvent event) {
  if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
    searchResults.clear();
    searchText.setText("");
  }
}
 
Example 18
@Override
public void onKeyPress(KeyPressEvent event) {
  switch (event.getCharCode()) {
    case KeyCodes.KEY_END:
    case KeyCodes.KEY_DELETE:
    case KeyCodes.KEY_BACKSPACE:
      doSearch();
      break;
  }
}
 
Example 19
private void handleKeyPress(char keyCode) {
  if (keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_TAB) {
    // Pressing <tab>, <enter> or <return> will surrender focus.
    urlField.cancelKey();
    urlField.setFocus(false);
  } else if (!validateKeyCode(keyCode)) {
    urlField.cancelKey();
  }
}
 
Example 20
Source Project: appinventor-extensions   Source File: MockComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
  super.onPreviewNativeEvent(event);
  switch (event.getTypeInt()) {
    case Event.ONKEYDOWN:
      if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
        hide();
      } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
        hide();
        MockComponent.this.delete();
      }
      break;
  }
}
 
Example 21
@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 22
/**
 * 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 23
private void testBackspaceDeleteHelper(boolean isBackspace, boolean handled,
    boolean isShiftDown) {
  EditorEvent signal = FakeSignalEvent.createKeyPress(FakeEditorEvent.ED_FACTORY,
      KeySignalType.DELETE, isBackspace ? KeyCodes.KEY_BACKSPACE : KeyCodes.KEY_DELETE,
      isShiftDown ? EnumSet.of(KeyModifier.SHIFT) : null);

  FakeRouter router = new FakeRouter();
  ContentElement fakeContentElement = newElement();
  final Point<ContentNode> caret = Point.<ContentNode> end(fakeContentElement);

  FakeEditorInteractor interactor = setupFakeEditorInteractor(new FocusedContentRange(caret));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(router, interactor, subHandler);

  // Because we cannot override handleBackspace in ContentElement, we test at
  // handleBackspaceAtBeginning instead. We have to be sure that the caret is
  // at beginning or it wouldn't work, so this is a bit fragile.
  assertTrue(ContentPoint.fromPoint(caret).isAtBeginning());
  if (isBackspace) {
    router.ctx.call(FakeRouter.HANDLE_BACKSPACE_AT_BEGINNING).nOf(1)
        .withArgs(signal).returns(handled);
  } else {
    router.ctx.call(FakeRouter.HANDLE_DELETE).nOf(1).withArgs(signal)
        .returns(handled);
  }
  boolean cancel = handler.handleEvent(signal);
  router.ctx.checkExpectations();
  assertEquals("Backspace should be cancelled if handled", handled, cancel);
}
 
Example 24
public static boolean isArrowKey(int keyCode) {
	if (KeyCodes.KEY_LEFT == keyCode || KeyCodes.KEY_RIGHT == keyCode || KeyCodes.KEY_UP == keyCode
			|| KeyCodes.KEY_DOWN == keyCode) {
		return true;
	} else {
		return false;
	}
}
 
Example 25
public static boolean isNavigationKey(int keyCode) {
	if (isArrowKey(keyCode) || KeyCodes.KEY_HOME == keyCode || KeyCodes.KEY_END == keyCode ||
			KeyCodes.KEY_PAGEUP == keyCode || KeyCodes.KEY_PAGEDOWN == keyCode) {
		return true;
	} else {
		return false;
	}
}
 
Example 26
public static boolean isModifierKey(int keyCode) {
	if (KeyCodes.KEY_SHIFT == keyCode || KeyCodes.KEY_ALT == keyCode || KeyCodes.KEY_CTRL == keyCode
			|| KeyCodes.KEY_DOWN == keyCode) {
		return true;
	} else {
		return false;
	}
}
 
Example 27
/**
 * File textBox
 */
public FileTextBox() {
	textBox = new TextBox();
	textBox.addKeyUpHandler(new KeyUpHandler() {
		@Override
		public void onKeyUp(KeyUpEvent event) {
			switch (event.getNativeKeyCode()) {
				case (char) KeyCodes.KEY_ENTER:
					switch (action) {
						case ACTION_RENAME:
							if (textBox.getText().length() > 0) {
								Main.get().mainPanel.desktop.browser.fileBrowser.rename(textBox.getText());
							} else {
								Main.get().mainPanel.desktop.browser.fileBrowser.hideRename();
							}
							break;
					}
					Main.get().mainPanel.enableKeyShorcuts(); // Enables general keys applications
					break;

				case (char) KeyCodes.KEY_ESCAPE:
					switch (action) {
						case ACTION_RENAME:
							Main.get().mainPanel.desktop.browser.fileBrowser.hideRename();
							break;
					}
					Main.get().mainPanel.enableKeyShorcuts(); // Enables general keys applications
					break;
			}
		}
	});
	textBox.setVisibleLength(20);
	textBox.setStyleName("okm-FileBrowser-TextBox");
	initWidget(textBox);
}
 
Example 28
Source Project: cuba   Source File: CubaSearchSelectWidget.java    License: 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 29
Source Project: dashbuilder   Source File: NavItemDefaultEditorView.java    License: Apache License 2.0 5 votes vote down vote up
@EventHandler("itemNameInput")
public void onItemNameChanged(KeyPressEvent keyEvent) {
    if (keyEvent.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
        presenter.onChangesOk();
    } else {
        presenter.onItemNameChanged();
    }
}
 
Example 30
Source Project: cuba   Source File: CubaSearchSelectWidget.java    License: 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();
    }
}