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

The following examples show how to use com.google.gwt.event.dom.client.KeyPressEvent. 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: AddressBookPage.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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));
			}
		}
	});
}
 
Example #2
Source File: MaskValueBoxHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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();
		}
	}
}
 
Example #3
Source File: FocusManager.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: AddressBookView.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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));
			}
		}
	});
}
 
Example #5
Source File: YoungAndroidPalettePanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  switch (event.getCharCode()) {
    case KeyCodes.KEY_END:
    case KeyCodes.KEY_DELETE:
    case KeyCodes.KEY_BACKSPACE:
      doSearch();
      break;
  }
}
 
Example #6
Source File: FocusManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #7
Source File: StaticStringTokenHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected boolean handleKeyPress(KeyPressEvent event) {
	boolean b = handleKeyPress(event.getCharCode());
	if (b) {
		event.preventDefault();
		event.stopPropagation();
	}
	return b;
}
 
Example #8
Source File: InputEmail.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
	boolean valid = false;
	char pressed = event.getCharCode();
	for (char c : ALLOWED_CHARS) {
		if (c == pressed) {
			valid = true;
			break;
		}
	}
	if (!valid) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #9
Source File: AbstractDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
	if (event.getCharCode() == KeyCodes.KEY_ENTER) {
		this.toggleOpen();
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #10
Source File: NavItemDefaultEditorView.java    From dashbuilder with 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 #11
Source File: NavRootNodeEditorView.java    From dashbuilder with 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 #12
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 #13
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 #14
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 #15
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 #16
Source File: FocusManager.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  dispatch(event);
}
 
Example #17
Source File: MaskValueBoxHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected boolean handleKeyPress(KeyPressEvent event) {
	return handleKeyPress(event.getCharCode());
}
 
Example #18
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());
}
 
Example #19
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 #20
Source File: FocusManager.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  dispatch(event);
}