/** * Adds a {@link KeyPressHandler} to the specified widget which calls {@link Button#click()} on <code>targetButton</code> * when the Enter key is pressed. * @param widget widget to add the key handler to * @param targetButton target button to activate when the enter key is pressed */ public static void addEnterTarget( final HasKeyPressHandlers widget, final Button targetButton ) { widget.addKeyPressHandler( new KeyPressHandler() { @Override public void onKeyPress( final KeyPressEvent event ) { if ( event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER ) targetButton.click(); } } ); }
@Override public EntitiesExplorerView configure(final String entityType, final EntitiesList.View entitiesListView) { this.entitiesListView = entitiesListView; this.entityType = entityType; initWidget(uiBinder.createAndBindUi(this)); searchBox.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { doSearch(searchBox.getText()); } } }); searchButton.addClickHandler(e -> doSearch(searchBox.getText())); clearSearchButton.addDomHandler(new ClickHandler() { @Override public void onClick(final ClickEvent clickEvent) { doSearch(""); } }, ClickEvent.getType()); clearSearch(); return this; }
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; }
private KeyUpHandler setUndoHandler() { final KeyUpHandler handler = new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { if (KeyCodes.KEY_U == event.getNativeEvent().getKeyCode()) { for (final Control control : controls) { try { ((DrawFeature) control).undo(); } catch (Exception e) { LOGGER.error( "ACTION UNDO: " + control.getControlId(), e); } } } } }; return handler; }
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; }
@Override public void onKeyDown(KeyDownEvent keyDownEvent) { if (keyDownEvent.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { SimplePanel panel = WidgetUtil.findWidget(WidgetUtil.getFocusedElement(), SimplePanel.class); if (panel != null) { WidgetUtil.focus(panel.getParent().getElement()); // prevent further bubbling of the event as it has only // navigational purpose if thrown at this depth. A subsequent // press of ESC is not stopped, so ESC abort actions of the // application should work as soon as the focus is in // "navigational mode" on a grid-cell keyDownEvent.preventDefault(); keyDownEvent.stopPropagation(); } } }
@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 (target.getClassName() != null && target.getClassName().contains(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); }
@Override public boolean shouldTrackCursor() { if (isMouseButtonEvent()) { return true; } if (isKeyEvent()) { KeySignalType keySignalType = 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 = getKeyCode(); return keySignalType == KeySignalType.INPUT || keySignalType == KeySignalType.DELETE || keySignalType == KeySignalType.NAVIGATION && ( keyCode != KeyCodes.KEY_PAGEDOWN && keyCode != KeyCodes.KEY_PAGEUP); } return false; }
private boolean handleEventsManuallyOnNode(EditorEvent event, Point<ContentNode> caret) throws SelectionLostException { // Note that caret may be null if this is called during typing extraction // Always handle enter specially, and always cancel the default action. // TODO(danilatos): This is still a slight anomaly, to call a // node.handleXYZ method here. if (event.isOnly(KeyCodes.KEY_ENTER)) { refreshEditorWithCaret(event); caret = event.getCaret().asPoint(); editorInteractor.checkpoint(new FocusedContentRange(caret)); router.handleEnter(caret.getContainer(), event); editorInteractor.rebiasSelection(CursorDirection.FROM_LEFT); return true; } else if (event.isCombo(KeyCodes.KEY_ENTER, KeyModifier.SHIFT)) { // shift+enter inserts a "newline" (such as a <br/>) by default // TODO(danilatos): Form elements want to handle this. return true; } return false; }
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; }
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(); }
@Override protected void onPreviewNativeEvent(NativePreviewEvent preview) { super.onPreviewNativeEvent(preview); NativeEvent evt = preview.getNativeEvent(); if (evt.getType().equals("keydown")) { // Use the popup's key preview hooks to close the dialog when either // enter or escape is pressed. switch (evt.getKeyCode()) { case KeyCodes.KEY_ENTER: case KeyCodes.KEY_ESCAPE: hide(); break; default: break; } } }
/** * Handles TAB key and Shift-TAB key presses. */ protected boolean handleTabKey(Event event, ChartState chartInfo, int keyCode, boolean isShiftKeyDown) { if (DOM.eventGetType(event) != chartInfo.getTabKeyEventCode()) { return false; } if (keyCode == KeyCodes.KEY_TAB) { if (isShiftKeyDown) { chartInfo.chart.prevFocus(); } else { chartInfo.chart.nextFocus(); } return true; } return false; }
@Test public void enterKeyEditsCells() { when(layer.getGridWidgets()).thenReturn(gridWidgets); when(gridWidget1.isSelected()).thenReturn(true); when(event.getNativeKeyCode()).thenReturn(KeyCodes.KEY_ENTER); gridWidget1Data.selectCell(0, 0); handler.onKeyDown(event); verify(gridWidget1, times(1)).startEditingCell(eq(0), eq(0)); verify(layer, never()).draw(); verify(keyboardOperationEditCell, times(1)).perform(eq(gridWidget1), eq(false), eq(false)); }
public void onKeyPress(KeyPressEvent event) { ChartState chartInfo = getChartState(event); Chart chart = chartInfo.chart; int keyCode = event.getCharCode(); boolean handled = true; if (keyCode == KeyCodes.KEY_TAB) { handled = handleTabKey((Event)event.getNativeEvent(), chartInfo, keyCode, event.isShiftKeyDown()); } else if (keyCode == KEY_Z) { chart.nextZoom(); } else if (keyCode == KEY_X) { chart.prevZoom(); } else if (keyCode == KeyCodes.KEY_ENTER) { chart.maxZoomToFocus(); } else { handled = false; } chartInfo.setHandled(handled); if (handled) { event.stopPropagation(); event.preventDefault(); } }
@Override protected void extend(final ServerConnector target) { textFieldWidget = (VTextField) ((ComponentConnector) target).getWidget(); textFieldWidget.setImmediate(true); textFieldWidget.textChangeEventMode = "EAGER"; panel.setWidget(select); panel.setStyleName("suggestion-popup"); panel.setOwner(textFieldWidget); textFieldWidget.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { if (panel.isAttached()) { handlePanelEventDelegation(event); } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { rpc.executeQuery(textFieldWidget.getValue(), textFieldWidget.getCursorPos()); } else { doAskForSuggestion(); } } }); }
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(); } }
@UiHandler("projectName") void onProjectNameChanged(KeyUpEvent event) { if (projectName.getValue() != null && projectName.getValue().contains(" ")) { String tmp = projectName.getValue(); while (tmp.contains(" ")) { tmp = tmp.replaceAll(" ", "-"); } projectName.setValue(tmp); } if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { return; } delegate.projectNameChanged(projectName.getText()); }
@Override protected void onPreviewNativeEvent(NativePreviewEvent preview) { super.onPreviewNativeEvent(preview); NativeEvent evt = preview.getNativeEvent(); if (evt.getType() .equals("keydown")) { // Use the popup's key preview hooks to close the dialog when either // enter or escape is pressed. switch (evt.getKeyCode()) { case KeyCodes.KEY_ENTER: case KeyCodes.KEY_ESCAPE: hide(); break; } } }
@UiHandler("projectDescription") void onProjectDescriptionChanged(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { return; } delegate.onProjectDescriptionChanged(projectDescription.getValue()); }
@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(); } }
public void onKeyPress(KeyPressEvent arg0) { if (arg0.getCharCode() == KeyCodes.KEY_ENTER) { Long candidateID = null; try{ candidateID = Long.parseLong(addCandidateIdTB.getText()); } catch(NumberFormatException e) { BallotServer.popError("The Candidate ID must be a number."); return; } Communicator.getInstance().getService().addCandidate(electionId, addCandidateNameTB.getText(), candidateID, new UpdateCallback()); } }
@Override public void onKeyDown(KeyDownEvent p_event) { switch( p_event.getNativeKeyCode() ) { case KeyCodes.KEY_ESCAPE: hide(); p_event.stopPropagation(); break; case KeyCodes.KEY_ENTER: sendMessage(); p_event.stopPropagation(); p_event.getNativeEvent().stopPropagation(); break; default: break; } }
public Hashtags() { initWidget(uiBinder.createAndBindUi(this)); hashtagTextBox.setVisibleLength(VISIBLE_LENGTH); hashtagTextBox.addKeyDownHandler( new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent e) { if (e.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { onCancel(null); } else if (e.getNativeKeyCode() == KeyCodes.KEY_ENTER) { onAdd(null); } } }); addHashtagIcon.addDomHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { onOpenForm(); } }, ClickEvent.getType()); }
/** * Create a box that holds the current page. */ private void createCurPageBox() { // Setup the widget curPageBox.setWidth("3em"); curPageBox.setText("1"); curPageBox.setTextAlignment(TextBoxBase.ALIGN_RIGHT); // Disallow non-numeric pages KeyPressHandler handler = new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { int keyCode = event.getNativeEvent().getKeyCode(); char charCode = event.getCharCode(); if (keyCode == KeyCodes.KEY_ENTER) { PagingPanel.this.table.gotoPage(getPagingBoxValue(), false); } else if (charCode != 0 && !Character.isDigit(charCode)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }
@Test public void homeKeyMovesToTopLeft() { when(layer.getGridWidgets()).thenReturn(gridWidgets); when(gridWidget1.isSelected()).thenReturn(true); when(gridWidget1.selectCell(eq(0), eq(0), any(Boolean.class), any(Boolean.class))).thenReturn(true); when(event.getNativeKeyCode()).thenReturn(KeyCodes.KEY_HOME); handler.onKeyDown(event); verify(gridWidget1, times(1)).selectCell(eq(0), eq(0), eq(false), eq(false)); verify(layer, times(1)).draw(); verify(keyboardOperationSelectTopLeftCell, times(1)).perform(eq(gridWidget1), eq(false), eq(false)); }
@Override public void registerKeys() { super.registerKeys(); getKeysNavigation() .add( new NoOpKeyCommand(KeyCommand.M_SHIFT, KeyCodes.KEY_LEFT, PatchUtil.C.focusSideA()), new NoOpKeyCommand(KeyCommand.M_SHIFT, KeyCodes.KEY_RIGHT, PatchUtil.C.focusSideB())); getKeysAction() .add( new KeyCommand(KeyCommand.M_SHIFT, 'a', PatchUtil.C.toggleSideA()) { @Override public void onKeyPress(KeyPressEvent event) { diffTable.toggleA().run(); } }); registerHandlers(); }
private void onKey(int key) { if (key == KeyCodes.KEY_ESCAPE) { setText(prevText); Widget p = getParent(); if (p instanceof SuggestBox) { // Since the text was changed, ensure that the SuggestBox is // aware of this change so that it will refresh properly on // the next keystroke. Without this, if the first keystroke // recreates the same string as before ESC was pressed, the // SuggestBox will think that the string has not changed, and // it will not yet provide any Suggestions. ((SuggestBox) p).showSuggestionList(); // The suggestion list lingers if we don't hide it. ((DefaultSuggestionDisplay) ((SuggestBox) p).getSuggestionDisplay()).hideSuggestions(); } setFocus(false); } }
@Override public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { event.preventDefault(); closeFullScreen(); } }
@UiHandler("titleTextBox") public void titleKeyDownHandler(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { presenter.applyBookmark(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { presenter.discardChanges(); } }
@Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONKEYUP && event.getKeyCode() == KeyCodes.KEY_SPACE) { onClick(); } if (event.getTypeInt() == Event.ONCLICK) { setValue(!getValue()); } super.onBrowserEvent(event); }
@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(); } }
@Override public void onKeyUp(KeyUpEvent event) { if (iCourses.getRowCount() < 2 || iCourses.getData(1) == null) return; int row = iCourses.getSelectedRow(); if (event.getNativeKeyCode() == KeyCodes.KEY_DOWN) { if (row < 0 || iCourses.getSelectedRow() + 1 >= iCourses.getRowCount()) iCourses.setSelected(1, true); else iCourses.setSelected(row + 1, true); scrollToSelectedRow(); updateCourseDetails(); } else if (event.getNativeKeyCode()==KeyCodes.KEY_UP) { if (row - 1 < 1) iCourses.setSelected(iCourses.getRowCount() - 1, true); else iCourses.setSelected(row - 1, true); scrollToSelectedRow(); updateCourseDetails(); } else if (event.isControlKeyDown() || event.isAltKeyDown()) { for (Map.Entry<Character, Integer> entry: iTabAccessKeys.entrySet()) if (event.getNativeKeyCode() == Character.toLowerCase(entry.getKey()) || event.getNativeKeyCode() == Character.toUpperCase(entry.getKey())) { iCourseDetailsTabBar.selectTab(entry.getValue(), true); event.preventDefault(); event.stopPropagation(); } } }
public NumberBox() { setStyleName("gwt-SuggestBox"); setWidth("100px"); getElement().getStyle().setTextAlign(TextAlign.RIGHT); addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (!isEnabled() || isReadOnly()) return; int keyCode = event.getNativeEvent().getKeyCode(); switch (keyCode) { case KeyCodes.KEY_BACKSPACE: case KeyCodes.KEY_DELETE: case KeyCodes.KEY_ESCAPE: case KeyCodes.KEY_RIGHT: case KeyCodes.KEY_LEFT: case KeyCodes.KEY_TAB: return; } if (isDecimal() && event.getCharCode() == '.' && !getValue().contains(".")) return; if (isNegative() && event.getCharCode() == '-' && !getValue().contains("-") && (getCursorPos() == 0 || getSelectionLength() == getValue().length())) return; if (Character.isDigit(event.getCharCode())) return; cancelKey( ); } } ); }
private void fixHandlers(final FilterBox box, Widget w) { if (w instanceof HasBlurHandlers) ((HasBlurHandlers)w).addBlurHandler(box.iBlurHandler); if (w instanceof HasFocusHandlers) ((HasFocusHandlers)w).addFocusHandler(box.iFocusHandler); if (w instanceof HasKeyDownHandlers) ((HasKeyDownHandlers)w).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) if (box.isFilterPopupShowing()) box.hideFilterPopup(); } }); }
private void addKeyShortcuts() { final KeyShortcutHandler keyShortcut = new KeyShortcutHandler( getButton(PredefinedButton.OK), KeyCodes.KEY_ENTER); latitudTextField.addKeyDownHandler(keyShortcut); longitudTextField.addKeyDownHandler(keyShortcut); }
private void addKeyShortcuts() { KeyShortcutHandler keyShortcut = new KeyShortcutHandler(searchButton, KeyCodes.KEY_ENTER); layerNameField.addKeyDownHandler(keyShortcut); valueAttributeField.addKeyDownHandler(keyShortcut); attributeCombo.addKeyDownHandler(keyShortcut); }
private KeyUpHandler createKeyHandler() { return new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { if (KeyCodes.KEY_PAGEUP == event.getNativeEvent().getKeyCode()) { onRelease(); } } }; }
private KeyUpHandler createKeyHandler() { KeyUpHandler handler= new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { if (KeyCodes.KEY_PAGEDOWN == event.getNativeEvent().getKeyCode()) { onRelease(); } } }; return handler; }