com.google.gwt.event.dom.client.KeyPressHandler Java Examples

The following examples show how to use com.google.gwt.event.dom.client.KeyPressHandler. 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: ClientUtils.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
		}
	} );
}
 
Example #2
Source File: NumberBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
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( );
        }
    } );
}
 
Example #3
Source File: HandlerPanel.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
  return addDomHandler(handler, KeyPressEvent.getType());
}
 
Example #4
Source File: TimeSelector.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return iText.addKeyPressHandler(handler);
}
 
Example #5
Source File: FilterBox.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return iFilter.addKeyPressHandler(handler);
}
 
Example #6
Source File: UniTimeFilterBox.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return iFilter.getWidget().addKeyPressHandler(handler);
}
 
Example #7
Source File: AbstractInput.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public com.google.gwt.event.shared.HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}
 
Example #8
Source File: ListItem.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}
 
Example #9
Source File: Anchor.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}