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

The following examples show how to use com.google.gwt.event.dom.client.KeyDownEvent. 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: KeyShortcutHandler.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onKeyDown(final KeyDownEvent event) {

	if (event.getNativeKeyCode() == keyCode) {				
		actionButton.fireEvent( new GwtEvent<ClickHandler>() {
	        @Override
	        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
	        	return ClickEvent.getType();
	        }
	        @Override
	        protected void dispatch(final ClickHandler handler) {
	            handler.onClick(null);
	        }
	   });
	}
}
 
Example #2
Source File: SinglePageLayout.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
@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();
	}
}
 
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: WordCloudApp.java    From swcv with MIT License 6 votes vote down vote up
private TextArea createTextArea()
{
    TextArea textArea = TextArea.wrap(Document.get().getElementById("input_text"));
    textArea.addKeyDownHandler(new KeyDownHandler()
    {
        public void onKeyDown(KeyDownEvent event)
        {
            event.preventDefault();
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
            {
                createWordCloud();
            }
        }
    });

    return textArea;
}
 
Example #5
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key is pressed in the text box
 *
 * @param event
 *            The KeyDownEvent
 */
private void inputFieldKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");

	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
	case KeyCodes.KEY_UP:
	case KeyCodes.KEY_PAGEDOWN:
	case KeyCodes.KEY_PAGEUP:
		// open popup as from gadget
		filterOptions(-1, "");
		this.tb.selectAll();
		this.dataReceivedHandler.popupOpenerClicked();
		break;
	case KeyCodes.KEY_ENTER:
		/*
		 * This only handles the case when new items is allowed, a text is
		 * entered, the popup opener button is clicked to close the popup
		 * and enter is then pressed (see #7560).
		 */
		if (!this.allowNewItems) {
			return;
		}

		if (this.currentSuggestion != null && this.tb.getText()
			.equals(this.currentSuggestion.getReplacementString())) {
			// Retain behavior from #6686 by returning without stopping
			// propagation if there's nothing to do
			return;
		}
		this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());

		event.stopPropagation();
		break;
	}

}
 
Example #6
Source File: FilterBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
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();
			}
		});
}
 
Example #7
Source File: DateCell.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    int keycode = event.getNativeEvent().getKeyCode();
    if (keycode == KeyCodes.KEY_ESCAPE && eventRangeStart > -1) {
        cancelRangeSelect();
    }
}
 
Example #8
Source File: SinglePageLayout.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
public PanController(Widget widget) {
	super(widget);
	widget.addDomHandler(this, MouseWheelEvent.getType());
	widget.addDomHandler(this, KeyDownEvent.getType());
	
	app.getHorizontalScrollbar().addScrollPanListener(this);
	app.getVerticalScrollbar().addScrollPanListener(this);
}
 
Example #9
Source File: UIHider.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
public UIHider(int uiHideDelay, Widget textLayer) {
	this.uiHideDelay = uiHideDelay;
	textLayer.addDomHandler(this, MouseMoveEvent.getType());
	textLayer.addDomHandler(this, KeyDownEvent.getType());
	textLayer.addDomHandler(this, ScrollEvent.getType());
	textLayer.addDomHandler(this, TouchStartEvent.getType());
}
 
Example #10
Source File: FocusManager.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private boolean checkStatDialogCondition(KeyEvent<?> event) {
  boolean down = event instanceof KeyDownEvent;
  if (checkStatDialogCondition(statDialogCondition, event.getNativeEvent().getKeyCode(), down)) {
    if (statDialogCondition/2 == statDialogKeyCodeSequence.length-1) {
      statDialogCondition = 0;
      return true;
    }
    statDialogCondition++;
  } else if (statDialogCondition != 0) {
    statDialogCondition = checkStatDialogCondition(0, event.getNativeEvent().getKeyCode(), down) ? 1 : 0;
  }
  return false;
}
 
Example #11
Source File: UTCTimeBoxImplHtml4.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    switch (event.getNativeKeyCode()) {
    case KeyCodes.KEY_UP:
        menu.adjustHighlight(-1);
        break;
    case KeyCodes.KEY_DOWN:
        menu.adjustHighlight(1);
        break;
    case KeyCodes.KEY_ENTER:
    case KeyCodes.KEY_TAB:
        // accept current value
        if (menu.isShowing()) {
            menu.acceptHighlighted();
            hideMenu();
            clearInvalidStyle();
        } 
        else {
            
            // added a sync here because this is when we
            // accept the value we've typed if we're typing in
            // a new value.
            syncValueToText();
            
            validate();
        }
        break;
    case KeyCodes.KEY_ESCAPE:
        validate();
        hideMenu();
        break;
    default:
        hideMenu();
        clearInvalidStyle();
        break;
    }
}
 
Example #12
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (!InputSlider.this.isStateValid()) {
		return;
	}
	int paddingValue = 1;
	if (event.isControlKeyDown()) {
		paddingValue = InputSlider.this.items.size() / 5;
	}
	switch (event.getNativeKeyCode()) {
		case KeyCodes.KEY_HOME:
			InputSlider.this.handleWidget.moveStart();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_END:
			InputSlider.this.handleWidget.moveEnd();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_SPACE:
			InputSlider.this.handleWidget.moveMiddle();
			this.killEvent(event);
			break;
		case KeyCodes.KEY_LEFT:
			InputSlider.this.handleWidget.moveLeft(paddingValue);
			this.killEvent(event);
			break;
		case KeyCodes.KEY_RIGHT:
			InputSlider.this.handleWidget.moveRight(paddingValue);
			this.killEvent(event);
			break;
		default:
			break;
	}
}
 
Example #13
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				Element activeElement = FocusUtils.getActiveElement();
				if (activeElement != null && !CompositeFocusHelper.this.isOrHasChildOfContainerOrPartner(activeElement)) {
					CompositeFocusHelper.this.blur();
				}
			}
		});
	}
}
 
Example #14
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private CompositeFocusHelper(Widget containerWidget, HasFocusHandlers... hasFocusContents) {
	this.containerWidget = containerWidget;
	containerWidget.addDomHandler(this.keyDownHandler, KeyDownEvent.getType());
	if (hasFocusContents != null) {
		for (HasFocusHandlers hasFocus : hasFocusContents) {
			this.addHasFocusContent(hasFocus);
		}
	}

	this.handlerManager = new HandlerManager(containerWidget);
}
 
Example #15
Source File: MaskValueBoxHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (this.cursorToReset) {
		this.focusOnCursor();
		this.cursorToReset = false;
	}
	if (this.currentHelper != null) {
		this.currentHelper.onKeyDown(event);
	}
}
 
Example #16
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 #17
Source File: FocusManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private boolean checkStatDialogCondition(KeyEvent<?> event) {
  boolean down = event instanceof KeyDownEvent;
  if (checkStatDialogCondition(statDialogCondition, event.getNativeEvent().getKeyCode(), down)) {
    if (statDialogCondition/2 == statDialogKeyCodeSequence.length-1) {
      statDialogCondition = 0;
      return true;
    }
    statDialogCondition++;
  } else if (statDialogCondition != 0) {
    statDialogCondition = checkStatDialogCondition(0, event.getNativeEvent().getKeyCode(), down) ? 1 : 0;
  }
  return false;
}
 
Example #18
Source File: CubaRadioButtonGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example #19
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (this.enabled && !this.readonly) {
		int keyCode = event.getNativeKeyCode();

		debug("VComboBoxMultiselect: key down: " + keyCode);

		if (this.dataReceivedHandler.isWaitingForFilteringResponse() && navigationKeyCodes.contains(keyCode)
				&& (!this.allowNewItems || keyCode != KeyCodes.KEY_ENTER)) {
			/*
			 * Keyboard navigation events should not be handled while we are
			 * waiting for a response. This avoids flickering, disappearing
			 * items, wrongly interpreted responses and more.
			 */
			debug("Ignoring " + keyCode + " because we are waiting for a filtering response");

			DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
			event.stopPropagation();
			return;
		}

		if (this.suggestionPopup.isAttached()) {
			debug("Keycode " + keyCode + " target is popup");
			popupKeyDown(event);
		} else {
			debug("Keycode " + keyCode + " target is text field");
			inputFieldKeyDown(event);
		}
	}
}
 
Example #20
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Triggered when a key is pressed in the text box
 *
 * @param event
 *            The KeyDownEvent
 */
private void inputFieldKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");

	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
	case KeyCodes.KEY_UP:
	case KeyCodes.KEY_PAGEDOWN:
	case KeyCodes.KEY_PAGEUP:
		// open popup as from gadget
		filterOptions(-1, "");
		this.tb.selectAll();
		this.dataReceivedHandler.popupOpenerClicked();
		break;
	case KeyCodes.KEY_ENTER:
		/*
		 * This only handles the case when new items is allowed, a text is
		 * entered, the popup opener button is clicked to close the popup
		 * and enter is then pressed (see #7560).
		 */
		if (!this.allowNewItems) {
			return;
		}

		if (this.currentSuggestion != null && this.tb.getText()
			.equals(this.currentSuggestion.getReplacementString())) {
			// Retain behavior from #6686 by returning without stopping
			// propagation if there's nothing to do
			return;
		}
		this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());

		event.stopPropagation();
		break;
	}

}
 
Example #21
Source File: YoungAndroidPalettePanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
  if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
    searchResults.clear();
    searchText.setText("");
  }
}
 
Example #22
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (this.enabled && !this.readonly) {
		int keyCode = event.getNativeKeyCode();

		debug("VComboBoxMultiselect: key down: " + keyCode);

		if (this.dataReceivedHandler.isWaitingForFilteringResponse() && navigationKeyCodes.contains(keyCode)
				&& (!this.allowNewItems || keyCode != KeyCodes.KEY_ENTER)) {
			/*
			 * Keyboard navigation events should not be handled while we are
			 * waiting for a response. This avoids flickering, disappearing
			 * items, wrongly interpreted responses and more.
			 */
			debug("Ignoring " + keyCode + " because we are waiting for a filtering response");

			DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
			event.stopPropagation();
			return;
		}

		if (this.suggestionPopup.isAttached()) {
			debug("Keycode " + keyCode + " target is popup");
			popupKeyDown(event);
		} else {
			debug("Keycode " + keyCode + " target is text field");
			inputFieldKeyDown(event);
		}
	}
}
 
Example #23
Source File: CubaSearchSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void inputFieldKeyDown(KeyDownEvent event) {
    if (KeyCodes.KEY_ENTER == event.getNativeKeyCode()
            && !event.isAnyModifierKeyDown()) {
        event.stopPropagation();
    }
}
 
Example #24
Source File: CubaCheckBoxWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadOnly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example #25
Source File: CubaCheckBoxGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example #26
Source File: CubaOptionGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    if ((!isEnabled() || isReadonly())
            && event.getNativeKeyCode() != KeyCodes.KEY_TAB) {
        event.preventDefault();
    }
}
 
Example #27
Source File: SuggestPopup.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	int keyCode = event.getNativeKeyCode();
	if (keyCode == KeyCodes.KEY_ENTER
			&& choiceList.getSelectedIndex() != -1) {
		event.preventDefault();
		event.stopPropagation();
		select();
	} else if (keyCode == KeyCodes.KEY_ESCAPE) {
		event.preventDefault();
		close();
	}
}
 
Example #28
Source File: MonthGrid.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
    int keycode = event.getNativeKeyCode();
    if (KeyCodes.KEY_ESCAPE == keycode && selectionStart != null) {
        cancelRangeSelection();
    }
}
 
Example #29
Source File: RemixedYoungAndroidProjectWizard.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new YoungAndroid project wizard.
 */
public RemixedYoungAndroidProjectWizard(final GalleryApp app, final Button actionButton) {
  super(MESSAGES.remixedYoungAndroidProjectWizardCaption());

  this.actionButton = actionButton;
  gallery = GalleryClient.getInstance();
  // Initialize the UI
  setStylePrimaryName("ode-DialogBox");

  projectNameTextBox = new LabeledTextBox(MESSAGES.projectNameLabel());
  projectNameTextBox.setText(replaceNonTextChar(app.getTitle()));
  projectNameTextBox.getTextBox().addKeyDownHandler(new KeyDownHandler() {
    @Override
    public void onKeyDown(KeyDownEvent event) {
      int keyCode = event.getNativeKeyCode();
      if (keyCode == KeyCodes.KEY_ENTER) {
        handleOkClick();
      } else if (keyCode == KeyCodes.KEY_ESCAPE) {
        handleCancelClick();
      }
    }
  });

  VerticalPanel page = new VerticalPanel();
  page.add(projectNameTextBox);
  addPage(page);
  // Create finish command (create a new Young Android project)
  initFinishCommand(new Command() {
    @Override
    public void execute() {
      String projectName = projectNameTextBox.getText();
      final PopupPanel popup = new PopupPanel(true);
      final FlowPanel content = new FlowPanel();
      popup.setWidget(content);
      Label loading = new Label();
      loading.setText(MESSAGES.loadingAppIndicatorText());
      // loading indicator will be hided or forced to be hided in gallery.loadSourceFile
      content.add(loading);
      popup.center();
      boolean success = gallery.loadSourceFile(app, projectNameTextBox.getText(), popup);
      if(success){
        gallery.appWasDownloaded(app.getGalleryAppId(), app.getDeveloperId());
      }
      else {
        show();
        center();
        return;
      }
    }
  });
}
 
Example #30
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
/**
 * Triggered when a key was pressed in the suggestion popup.
 *
 * @param event
 *            The KeyDownEvent of the key
 */
private void popupKeyDown(KeyDownEvent event) {
	debug("VComboBoxMultiselect: popupKeyDown(" + event.getNativeKeyCode() + ")");

	// Propagation of handled events is stopped so other handlers such as
	// shortcut key handlers do not also handle the same events.
	switch (event.getNativeKeyCode()) {
	case KeyCodes.KEY_DOWN:
		this.suggestionPopup.selectNextItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_UP:
		this.suggestionPopup.selectPrevItem();

		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEDOWN:
		selectNextPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_PAGEUP:
		selectPrevPage();
		event.stopPropagation();
		break;
	case KeyCodes.KEY_ESCAPE:
		reset();
		DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
		event.stopPropagation();
		break;
	case KeyCodes.KEY_TAB:
	case KeyCodes.KEY_ENTER:

		// queue this, may be cancelled by selection
		int selectedIndex = this.suggestionPopup.menu.getSelectedIndex();
		if (!this.allowNewItems && selectedIndex != -1) {

			debug("index before: " + selectedIndex);
			if (this.showClearButton) {
				selectedIndex = selectedIndex - 1;
			}
			if (this.showSelectAllButton) {
				selectedIndex = selectedIndex - 1;
			}

			debug("index after: " + selectedIndex);
			if (selectedIndex == -2) {
				this.clearCmd.execute();
			} else if (selectedIndex == -1) {
				if (this.showSelectAllButton) {
					this.selectAllCmd.execute();
				} else {
					this.clearCmd.execute();
				}
			}

			debug("entered suggestion: " + this.currentSuggestions.get(selectedIndex).caption);
			onSuggestionSelected(this.currentSuggestions.get(selectedIndex));
		} else {
			this.dataReceivedHandler.reactOnInputWhenReady(this.tb.getText());
		}

		event.stopPropagation();
		break;
	}
}