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

The following examples show how to use com.google.gwt.event.dom.client.KeyPressEvent. 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
Source Project: swellrt   Source File: FocusManager.java    License: 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 2
@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 3
@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 4
@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 5
Source Project: incubator-retired-wave   Source File: FocusManager.java    License: 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 6
@Override
public void onKeyPress(KeyPressEvent event) {
  switch (event.getCharCode()) {
    case KeyCodes.KEY_END:
    case KeyCodes.KEY_DELETE:
    case KeyCodes.KEY_BACKSPACE:
      doSearch();
      break;
  }
}
 
Example 7
Source Project: sc2gears   Source File: ClientUtils.java    License: 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 8
Source Project: unitime   Source File: NumberBox.java    License: 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 9
Source Project: dashbuilder   Source File: NavRootNodeEditorView.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 10
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 11
@Override
public void onKeyPress(KeyPressEvent event) {
	if (event.getCharCode() == KeyCodes.KEY_ENTER) {
		this.toggleOpen();
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 12
@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 13
@Override
protected boolean handleKeyPress(KeyPressEvent event) {
	boolean b = handleKeyPress(event.getCharCode());
	if (b) {
		event.preventDefault();
		event.stopPropagation();
	}
	return b;
}
 
Example 14
Source Project: appinventor-extensions   Source File: HandlerPanel.java    License: Apache License 2.0 4 votes vote down vote up
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
  return addDomHandler(handler, KeyPressEvent.getType());
}
 
Example 15
Source Project: swellrt   Source File: FocusManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  dispatch(event);
}
 
Example 16
@Override
public com.google.gwt.event.shared.HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}
 
Example 17
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}
 
Example 18
protected boolean handleKeyPress(KeyPressEvent event) {
	return handleKeyPress(event.getCharCode());
}
 
Example 19
@Override
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
	return this.addDomHandler(handler, KeyPressEvent.getType());
}
 
Example 20
Source Project: incubator-retired-wave   Source File: FocusManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onKeyPress(KeyPressEvent event) {
  dispatch(event);
}