/** * 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(); } } ); }
@Test public void replace_foundElement() { // given TextBoxMock hasValue = mock(TextBoxMock.class); when(hasValue.getValue()).thenReturn("a"); ExpressionReplacer replacer = new ExpressionReplacer(); replacer.useReplacements(ImmutableMap.of("a", "b", "c", "d")); KeyPressEvent event = mock(KeyPressEvent.class); when(event.getCharCode()).thenReturn("a".charAt(0)); ArgumentCaptor<InputEventListener> listenerCaptor = ArgumentCaptor.forClass(InputEventListener.class); handler.init(Wrapper.of(hasValue), replacer); verify(eventRegistrar).registerInputHandler(eq(hasValue), listenerCaptor.capture()); // when listenerCaptor.getValue().onInput(); // then verify(hasValue).setValue("b", true); }
/** * Installs a key handler for key events on this window. * * @param handler handler to receive key events. */ static void install(KeySignalHandler handler) { // // NOTE: There are three potential candidate elements for sinking keyboard // events: the window, the document, and the document body. IE7 does not // fire events on the window element, and GWT's RootPanel is already a // listener on the body, leaving the document as the only cross-browser // whole-window event-sinking 'element'. // DocumentPanel panel = new DocumentPanel(handler); panel.setElement(Document.get().<Element>cast()); panel.addDomHandler(panel, KeyDownEvent.getType()); panel.addDomHandler(panel, KeyPressEvent.getType()); panel.addDomHandler(panel, KeyUpEvent.getType()); RootPanel.detachOnWindowClose(panel); panel.onAttach(); }
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(); } }
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()); } }
/** * 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); }
@Override protected void onLoad() { super.onLoad(); if (regFocus == null) { regFocus = GlobalKey.addApplication( this, new KeyCommand(0, '/', Gerrit.C.keySearch()) { @Override public void onKeyPress(KeyPressEvent event) { event.preventDefault(); searchBox.setFocus(true); searchBox.selectAll(); } }); } }
@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 KeyCommand setupNav(InlineHyperlink link, char key, String help, FileInfo info) { if (info != null) { final String url = url(info); link.setTargetHistoryToken(url); link.setTitle( PatchUtil.M.fileNameWithShortcutKey( FileInfo.getFileName(info.path()), Character.toString(key))); KeyCommand k = new KeyCommand(0, key, help) { @Override public void onKeyPress(KeyPressEvent event) { Gerrit.display(url); } }; keys.add(k); if (link == prev) { hasPrev = true; } else { hasNext = true; } return k; } link.getElement().getStyle().setVisibility(Visibility.HIDDEN); keys.add(new UpToChangeCommand(projectKey, patchSetId, 0, key)); return null; }
public void setKeyTyped(JavaScriptObject aValue) { if (keyTyped != aValue) { if (keyTypedReg != null) { keyTypedReg.removeHandler(); keyTypedReg = null; } keyTyped = aValue; if (keyTyped != null && component instanceof HasKeyPressHandlers) { keyTypedReg = ((HasKeyPressHandlers) component).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (keyTyped != null) { event.stopPropagation(); executeEvent(keyTyped, EventsPublisher.publish(event)); } } }); } } }
public void bind() { RootPanel.get("container").add(getView().asWidget()); getView().asWidget().setVisible(false); view.getLoginButton().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { login(); } }); KeyPressHandler handler = new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { // Si on appuie sur "Entrée" if (KeyCodes.KEY_ENTER == event.getNativeEvent().getKeyCode()) login(); } }; getView().getLoginKeyPress().addKeyPressHandler(handler); getView().getPasswdKeyPress().addKeyPressHandler(handler); getView().asWidget().setVisible(true); }
public static KeyPressHandler createOnKeyPressListener(final EventListenerGVO ev, final List<InputVariableGVO> input) { return new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if (ev.getParameterList() != null) { Iterator<ParameterGVO> itr = ev.getParameterList().iterator(); while (itr.hasNext()) { ParameterGVO parameter = itr.next(); if (parameter != null) { if (KeyBoardHelper.isKeyInput(parameter.getName(), parameter.getValue(), Character.toString(event.getCharCode()))) { CallbackHandler.createCallBack(event.getSource(), QAMLConstants.EVENT_ONKEYPRESS, ev, input); } } } } } }; }
/** * 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) { char charCode = event.getCharCode(); if (charCode == KeyCodes.KEY_ENTER) { QPagingOptions.this.table.gotoPage(getPagingBoxValue(), false); } else if (!Character.isDigit(charCode) && (charCode != KeyCodes.KEY_TAB) && (charCode != KeyCodes.KEY_BACKSPACE) && (charCode != KeyCodes.KEY_DELETE) && (charCode != KeyCodes.KEY_ENTER) && (charCode != KeyCodes.KEY_HOME) && (charCode != KeyCodes.KEY_END) && (charCode != KeyCodes.KEY_LEFT) && (charCode != KeyCodes.KEY_UP) && (charCode != KeyCodes.KEY_RIGHT) && (charCode != KeyCodes.KEY_DOWN)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }
private static KeyPressHandler createKeyPressHandler(final ComponentGVO componentGVO, final EventListenerGVO eventGVO, final NotifyHandler notifyHandler, final String windowId, final String context, final AbstractActivity activity) { return new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (eventGVO.getParameterList() == null) { return; } Iterator<ParameterGVO> itrParameter = eventGVO.getParameterList().iterator(); while (itrParameter.hasNext()) { ParameterGVO parameterGVO = itrParameter.next(); if (parameterGVO == null) { continue; } if (KeyBoardHelper.isKeyInput(parameterGVO.getName(), parameterGVO.getValue(), Character.toString(event.getCharCode()))) { UIObject widget = (UIObject)event.getSource(); List<InputVariableGVO> inputVariables = eventGVO.getInputvariablesList(); handleEvent(componentGVO, widget, eventGVO, event, QAMLConstants.EVENT_ONKEYPRESS, inputVariables, notifyHandler, windowId, context, activity); break; } } } }; }
@UiHandler("searchBox") void onSearchBox(KeyPressEvent event) { final InputText source = (InputText) event.getSource(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { String query = source.flush(); if (query == null || query.length() == 0) { displayList(displayedList); } else { final String queryToCompare = query.toLowerCase().trim(); Iterable<Contact> filteredIteable = Iterables.filter(displayedList, new Predicate<Contact>() { @Override public boolean apply(Contact contact) { return contact.getName() != null && contact.getName().toLowerCase().contains(queryToCompare); } }); displayList(Lists.newArrayList(filteredIteable)); } } }); }
@Override public void onKeyPress(KeyPressEvent event) { int i = helpers.indexOf(currentHelper); if (currentHelper != null) { if (currentHelper.handleKeyPress(event)) { refreshValueBox(); event.preventDefault(); } else if (1 + i < helpers.size()) { if (!helpers.get(1 + i).handleKeyPress(event) && 2 + i < helpers.size()) { focus(i + 1); helpers.get(2 + i).handleKeyPress(event); } else { focus(i + 1); } } else { event.preventDefault(); } } }
@UiHandler("searchBox") void onSearchBox(KeyPressEvent event) { final InputText source = (InputText) event.getSource(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { String query = source.flush(); if (query == null || query.length() == 0) { AddressBookPage.this.displayList(AddressBookPage.this.displayedList); } else { final String queryToCompare = query.toLowerCase().trim(); Iterable<Contact> filteredIteable = Iterables.filter(AddressBookPage.this.displayedList, new Predicate<Contact>() { @Override public boolean apply(Contact contact) { return contact.getName() != null && contact.getName().toLowerCase().contains(queryToCompare); } }); AddressBookPage.this.displayList(Lists.newArrayList(filteredIteable)); } } }); }
@Override public void onKeyPress(KeyPressEvent event) { try { int code = event.getUnicodeCharCode(); if (code == '\u002B') pageView.zoomIn(); else if (code == '\u2212' || code == '\u2010' || code == '\u002D') pageView.zoomOut(); else if (code == '\u2212' || code == '\u2010' || code == '\u002D') pageView.zoomOut(); //else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEDOWN) // selectNextObject(); //else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_PAGEUP) // selectPreviousObject(); //else // Window.alert(""+code); } catch (Exception exc) { logManager.logError(ERROR_UNSPECIFIED, "Error in onKeyPress()"); exc.printStackTrace(); } }
/** * Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed. * * It should be noted that many browsers do not generate keypress events for non-printing keyCode values, such as KEY_ENTER or arrow keys. These keyCodes can be reliably captured either with onKeyDown(Widget, char, int) or onKeyUp(Widget, char, int). * * Subclasses that override this method must call <tt>super.onKeyPress(sender, keyCode, modifiers)</tt> to ensure that the Widget recieves its events. * @param sender the widget that was focused when the event occurred. * @see com.google.gwt.user.client.ui.KeyboardListener */ public void onKeyPress(KeyPressEvent event) { Widget sender = (Widget) event.getSource(); char keyCode = event.getCharCode(); // Disallow non-numerics in numeric boxes if ((!Character.isDigit(keyCode)) && (keyCode != (char) KeyCodes.KEY_TAB) && (keyCode != (char) KeyCodes.KEY_BACKSPACE) && (keyCode != (char) KeyCodes.KEY_DELETE) && (keyCode != (char) KeyCodes.KEY_ENTER) && (keyCode != (char) KeyCodes.KEY_HOME) && (keyCode != (char) KeyCodes.KEY_END) && (keyCode != (char) KeyCodes.KEY_LEFT) && (keyCode != (char) KeyCodes.KEY_UP) && (keyCode != (char) KeyCodes.KEY_RIGHT) && (keyCode != (char) KeyCodes.KEY_DOWN)) { ((TextBox)sender).cancelKey(); } }
private void limitArea() { reportTextArea.getElement().setAttribute("maxlength", String.valueOf(MAX_REPORT_LENGTH)); reportTextArea.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { int size = reportTextArea.getText().length(); textLength.setText(String.valueOf(MAX_REPORT_LENGTH-size)); if(size == MAX_REPORT_LENGTH) { Animation a = new Animation() { @Override protected void onUpdate(double progress) { String rgbvalue = "rgb(" + ((int)((1-progress)*255)) + ",0,0)"; textLengthPanel.getElement().getStyle().setProperty("color", rgbvalue); } }; a.run(1000); } } }); }
@SuppressWarnings("rawtypes") public Code(KeyEvent event){ if (event != null){ if (event instanceof KeyPressEvent){ kP_Event = (KeyPressEvent)event; } else if (event instanceof KeyDownEvent){ kD_Event = (KeyDownEvent)event; } isCtrlDown = event.isControlKeyDown(); isAltDown = event.isAltKeyDown(); isShiftDown = event.isShiftKeyDown(); } int temp = 0; if (kP_Event != null){ charCode = kP_Event.getUnicodeCharCode(); } else if (kD_Event != null){ temp = keyCode = kD_Event.getNativeKeyCode(); } isFunctionKey = false; for (int k : keyCodes){ if (temp == k) { isFunctionKey = true; break; } } }
public void setSubmitOnEnter(boolean submitOnEnter) { if (submitOnEnter) { if (submitOnEnterRegistration == null) submitOnEnterRegistration = addDomHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { if (validate()) { fireSubmitEvent(); } } } }, KeyPressEvent.getType()); } else if (submitOnEnterRegistration != null) { submitOnEnterRegistration.removeHandler(); submitOnEnterRegistration = null; } }
@Override public void onKeyPress(KeyPressEvent event) { char c = event.getCharCode(); switch (c) { case '[':case 'q': scale /= KEY_ZOOM_STEP; updateZoom(); break; case ']':case 'w': scale *= KEY_ZOOM_STEP; updateZoom(); break; case '\\': case '1': scale = 1; updateZoom(); OMSVGRect viewBox = svg.getViewBox().getBaseVal(); viewBox.setX(0); viewBox.setY(0); break; } }
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( ); } } ); }
@Override public void onKeyPress(KeyPressEvent event) { if (listener != null) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { listener.onSelect(getInput()); } else { listener.onInput(getInput()); } } }
@Override public void onKeyPress(KeyPressEvent event) { //Window.alert("Char code: '" + (int) getCharCode( event.getNativeEvent() ) + "', key code: " + event.getNativeEvent().getKeyCode()); //Substitute characters if the transliteration is on and the text input is enabled if( textObject.isEnabled() ) { final Character charCode = getCharCode( event.getNativeEvent() ); if( processNewCharacter( charCode ) ) { event.stopPropagation(); event.preventDefault(); } } }
protected InfoPopupPanel(boolean autoHide, boolean modal){ super(autoHide, modal); //Register the popup in the list of popups eligible for closing on user-logout SiteManagerUI.getInstance().registerPopup( this ); //Set Animation ON this.setAnimationEnabled( true ); //Add the close by escape handler this.addDomHandler( new KeyPressHandler(){ public void onKeyPress( KeyPressEvent event ){ NativeEvent nativeEvent = event.getNativeEvent(); if( ( nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE ) ) { hide(); } } }, KeyPressEvent.getType() ); //Set the width of the panel //this.setWidth("25%"); //Adding decorator panel inside the pop-up because //we want the panel to have rounded borders. decoratedPanel.setSize( "100%", "100%"); decoratedPanel.setStyleName( CommonResourcesContainer.INFO_POPUP_STYLE_NAME ); this.add( decoratedPanel ); }
@Override public void onKeyPress(KeyPressEvent event) { int keyCode = event.getCharCode(); if(keyCode == KEY_ENTER) { submit(); } }
@Override public void onKeyPress(KeyPressEvent event) { if (promptText.equals(this.getText()) && !(event.getNativeEvent().getKeyCode() == KeyCodes.KEY_TAB)) { hidePrompt(); } }
public void bind(Widget target) { if (component != null) { registration.removeHandler(); } if (target != null) { if (keyEvent == Event.ONKEYDOWN) { registration = target.addDomHandler(handler, KeyDownEvent.getType()); } else { registration = target.addDomHandler(handler, KeyPressEvent.getType()); } } component = target; }
@Override public HandlerRegistration addKeyPressHandler(final KeyPressHandler handler) { return this.addDomHandler(handler, KeyPressEvent.getType()); }
@Override public void onKeyPress(KeyPressEvent event) { if (isReadOnly() || !isEnabled()) { return; } int keyCode = event.getNativeEvent().getKeyCode(); switch (keyCode) { case KeyCodes.KEY_LEFT: case KeyCodes.KEY_RIGHT: case KeyCodes.KEY_BACKSPACE: case KeyCodes.KEY_DELETE: case KeyCodes.KEY_TAB: case KeyCodes.KEY_UP: case KeyCodes.KEY_DOWN: return; } int index = getCursorPos(); String previousText = getText(); String newText; if (getSelectionLength() > 0) { newText = previousText.substring(0, getCursorPos()) + event.getCharCode() + previousText.substring( getCursorPos() + getSelectionLength(), previousText.length()); } else { newText = previousText.substring(0, index) + event.getCharCode() + previousText.substring(index, previousText.length()); } cancelKey(); setValue(newText, true); }
public void onKeyPress(KeyPressEvent ev) { if (submitButton == null) return; final int keyCode = ev.getNativeEvent().getKeyCode(); char charCode = ev.getCharCode(); if ((keyCode == KeyCodes.KEY_ENTER || charCode == KeyCodes.KEY_ENTER) && ev.getRelativeElement() != null) { DeferredCommand.addCommand(new SubmitCommand()); } }
/** * 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) { char charCode = event.getCharCode(); if (charCode == KeyCodes.KEY_ENTER) { PagingOptions.this.imageGridPanel.getImageGrid().gotoPage(getPagingBoxValue(), false); } else if (!Character.isDigit(charCode) && (charCode != KeyCodes.KEY_TAB) && (charCode != KeyCodes.KEY_BACKSPACE) && (charCode != KeyCodes.KEY_DELETE) && (charCode != KeyCodes.KEY_ENTER) && (charCode != KeyCodes.KEY_HOME) && (charCode != KeyCodes.KEY_END) && (charCode != KeyCodes.KEY_LEFT) && (charCode != KeyCodes.KEY_UP) && (charCode != KeyCodes.KEY_RIGHT) && (charCode != KeyCodes.KEY_DOWN)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }