Java Code Examples for com.google.gwt.user.client.Event#ONKEYUP

The following examples show how to use com.google.gwt.user.client.Event#ONKEYUP . 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: ImageButton.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (!isEnabled()) return;

	super.onBrowserEvent(event);

    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
    	int type = DOM.eventGetType(event);
    	char keyCode = (char) event.getKeyCode();
    	switch (type) {
    	case Event.ONKEYDOWN:
    		if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
    			if (iDown != null) setResource(iDown);
    		}
    		break;
        case Event.ONKEYUP:
        	if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
        		setResource(iUp);
        		onClick();
        	}
        	break;
    	}
    }
}
 
Example 2
Source File: ClickableHint.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);

    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
    	int type = DOM.eventGetType(event);
    	char keyCode = (char) event.getKeyCode();
    	switch (type) {
        case Event.ONKEYUP:
        	if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r')
        		onClick();
        	break;
    	}
    }
}
 
Example 3
Source File: AriaToggleButton.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (event.getTypeInt() == Event.ONKEYUP && event.getKeyCode() == KeyCodes.KEY_SPACE) {
		onClick();
	}
	if (event.getTypeInt() == Event.ONCLICK) {
		setValue(!getValue());
	}
	super.onBrowserEvent(event);
}
 
Example 4
Source File: StudentSchedule.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void checkAccessKeys(NativePreviewEvent event) {
	if (event.getTypeInt() == Event.ONKEYUP && (event.getNativeEvent().getAltKey() || event.getNativeEvent().getCtrlKey())) {
		for (Map.Entry<Character, Integer> entry: iTabAccessKeys.entrySet())
			if (event.getNativeEvent().getKeyCode() == Character.toLowerCase(entry.getKey()) || event.getNativeEvent().getKeyCode()  == Character.toUpperCase(entry.getKey())) {
				iTabs.selectTab(entry.getValue());
			}
	}
}
 
Example 5
Source File: EventWrapper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static String asString(Event event) {
  // Start with the event type string
  String string = DOM.eventGetTypeString(event);
  // Next type-specific fields
  switch (event.getTypeInt()) {
  case Event.ONKEYPRESS:
  case Event.ONKEYUP:
  case Event.ONKEYDOWN:
    string += key(event) + modifiers(event);
    break;
  case Event.ONCLICK:
  case Event.ONDBLCLICK:
  case Event.ONMOUSEMOVE:
    string += mousePoint(event) + modifiers(event);
    break;
  case Event.ONMOUSEDOWN:
  case Event.ONMOUSEUP:
    string += mousePoint(event) + mouseButtons(event) + modifiers(event);
    break;
  case Event.ONMOUSEOUT:
    string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event);
    break;
  case Event.ONMOUSEOVER:
    string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event);
    break;
  case Event.ONMOUSEWHEEL:
    string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event);
    break;
  case Event.ONFOCUS:
  case Event.ONBLUR:
  case Event.ONCHANGE:
  case Event.ONERROR:
  case Event.ONLOAD:
  case Event.ONLOSECAPTURE:
  case Event.ONSCROLL:
    break;
  }
  return string;
}
 
Example 6
Source File: EventWrapper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public static String asString(Event event) {
  // Start with the event type string
  String string = DOM.eventGetTypeString(event);
  // Next type-specific fields
  switch (event.getTypeInt()) {
  case Event.ONKEYPRESS:
  case Event.ONKEYUP:
  case Event.ONKEYDOWN:
    string += key(event) + modifiers(event);
    break;
  case Event.ONCLICK:
  case Event.ONDBLCLICK:
  case Event.ONMOUSEMOVE:
    string += mousePoint(event) + modifiers(event);
    break;
  case Event.ONMOUSEDOWN:
  case Event.ONMOUSEUP:
    string += mousePoint(event) + mouseButtons(event) + modifiers(event);
    break;
  case Event.ONMOUSEOUT:
    string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event);
    break;
  case Event.ONMOUSEOVER:
    string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event);
    break;
  case Event.ONMOUSEWHEEL:
    string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event);
    break;
  case Event.ONFOCUS:
  case Event.ONBLUR:
  case Event.ONCHANGE:
  case Event.ONERROR:
  case Event.ONLOAD:
  case Event.ONLOSECAPTURE:
  case Event.ONSCROLL:
    break;
  }
  return string;
}
 
Example 7
Source File: GuidedTourHelper.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void init(BootstrapContext bootstrapContext) {
    String locale = Preferences.get(Preferences.Key.LOCALE, "en");
    String url = bootstrapContext.getProperty(ApplicationProperties.GUIDED_TOUR) + "/" +
            (bootstrapContext.isStandalone() ? "standalone" : "domain") + "/step1.html?setLng=" + locale;

    Frame tourFrame = new Frame(url);
    tourFrame.setWidth("100%");
    tourFrame.setHeight("100%");

    guidedTour = new PopupPanel(true, true) {
        {
            Window.addResizeHandler(resizeEvent -> {
                if (isShowing()) {
                    center();
                }
            });
        }

        @Override
        protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (Event.ONKEYUP == event.getTypeInt()) {
                if (event.getNativeEvent().getKeyCode() == KeyboardEvent.KeyCode.ESC) {
                    hide();
                }
            }
        }
    };
    guidedTour.setGlassEnabled(true);
    guidedTour.setAnimationEnabled(false);
    guidedTour.setWidget(tourFrame);
    guidedTour.setWidth("1120px");
    guidedTour.setHeight("800px");
    guidedTour.setStyleName("default-window");

    exportCloseMethod();
}
 
Example 8
Source File: CubaPopupButtonWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleKeyboardEvents(Event event) {
    int type = DOM.eventGetType(event);
    // Synthesize clicks based on keyboard events AFTER the normal key
    // handling.
    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
        switch (type) {
            case Event.ONKEYDOWN:
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                // Stop propagation when the user starts pressing a button that
                // we are handling to prevent actions from getting triggered
                if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                    isFocusing = true;
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
                    isFocusing = true;
                    event.stopPropagation();
                }
                break;

            // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
            case Event.ONKEYUP:
                if (isFocusing) {
                    if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    }
                } else if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                break;
            case Event.ONKEYPRESS: {
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 9
Source File: CubaButtonWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleKeyboardEvents(Event event) {
    int type = DOM.eventGetType(event);
    // Synthesize clicks based on keyboard events AFTER the normal key
    // handling.
    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
        switch (type) {
            case Event.ONKEYDOWN:
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                // Stop propagation when the user starts pressing a button that
                // we are handling to prevent actions from getting triggered
                if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                }
                break;

            // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
            case Event.ONKEYUP:
                if (isFocusing) {
                    if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    }
                } else if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                break;
            case Event.ONKEYPRESS: {
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 10
Source File: WidgetComboBox.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * See class docs
 */
@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
  NativeEvent nativeEvent = event.getNativeEvent();
  EventTarget eventTarget = nativeEvent.getEventTarget();
  if (!Element.is(eventTarget)) //chrome fix
  {
    return;
  }

  Element target = (Element)Element.as(eventTarget);

  int type = event.getTypeInt();
  if (type == Event.ONKEYDOWN) {
    setKeyPressed(true);
    if (DOM.getCaptureElement() != null) return;

    boolean eventTargetsPopup = (target != null) && DOM.isOrHasChild(getElement(), target);
    int button = nativeEvent.getKeyCode();
    boolean alt = nativeEvent.getAltKey();
    boolean ctrl = nativeEvent.getCtrlKey();
    boolean shift = nativeEvent.getShiftKey();

    boolean hasModifiers = alt || ctrl || shift;

    if (eventTargetsPopup && isListPanelOpened()) {
      if (button == KeyCodes.KEY_UP && !hasModifiers) {
        moveCursor(-1);
        cancelAndPrevent(event);
      }
      else if (button == KeyCodes.KEY_DOWN && !hasModifiers) {
        moveCursor(1);
        cancelAndPrevent(event);
      }
      else if (button == KeyCodes.KEY_ENTER && !hasModifiers) {
        select(getHighlightRow());
        getChoiceButton().setFocus(false);
        ChangeEvent changeEvent = new ComboBoxChangeEvent(getHighlightRow(), ComboBoxChangeEvent.ChangeEventInputDevice.KEYBOARD);
        fireEvent(changeEvent);
        setKeyPressed(false);
      }
      else if (button == KeyCodes.KEY_ESCAPE && !hasModifiers) {
        hideList();
        setKeyPressed(false);
      }
      else if (button == KeyCodes.KEY_TAB && (!hasModifiers || !alt && !ctrl && shift)) {
        hideList();
        setKeyPressed(false);
      }
    }
    else if (eventTargetsPopup && !hasModifiers && button == KeyCodes.KEY_ENTER && getModel().getCount() > 0) {
      showList(true);
    }
  }
  else if (type == Event.ONKEYUP) {
    setKeyPressed(false);
  }
}
 
Example 11
Source File: ComboPicker.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ComboPicker(String cssSuffix) {

        cellList = new CellList<String>(new TextCell()
        {
            @Override
            public void render(Context context, String data, SafeHtmlBuilder sb) {
                String cssName = (context.getIndex() %2 > 0) ? "combobox-item combobox-item-odd" : "combobox-item";

                if(data.equals(displayed.getActual()))
                    cssName+=" combobox-item-selected";

                sb.append(TEMPLATE.item(cssName, data));
            }

        });

        cellList.setPageSize(100);

        final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
        cellList.setSelectionModel(selectionModel);

        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
            public void onSelectionChange(SelectionChangeEvent event) {
                String selectedValue = selectionModel.getSelectedObject();

                setDisplayedValue(selectedValue);
                popup.hide();

                onSelection(selectedValue);
            }
        });

        final String panelId = "combopicker_popup";
        popup = new PopupPanel(true, true) {

            @Override
            protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
                if (Event.ONKEYUP == event.getTypeInt()) {
                    if (event.getNativeEvent().getKeyCode() == ESCAPE) {
                        // Dismiss when escape is pressed
                        popup.hide();
                    }
                }
            }

            public void onBrowserEvent(Event event) {
                super.onBrowserEvent(event);
            }
        };

        popup.getElement().setId(panelId);

        popup.setStyleName("default-popup");

        popup.addStyleName("triangle-border");
        popup.addStyleName("top-left");

        popup.setWidget(new ScrollPanel(cellList));

        displayed = new Display("");

        header = new HorizontalPanel();
        header.setStyleName("combobox"+cssSuffix);
        header.add(displayed);

        HTML icon = new HTML("<span style='font-size:12px;cursor:pointer'><i class='icon-chevron-down'></i></span>");
        header.add(icon);

        displayed.getElement().getParentElement().setAttribute("width", "100%");

        icon.getParent().getElement().setAttribute("width", "18");

        //header.getElement().setAttribute("width", "95%");
        header.getElement().setAttribute("cellspacing", "0");
        header.getElement().setAttribute("cellpadding", "0");
        header.getElement().setAttribute("border", "0");


        ClickHandler clickHandler = new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                openPanel();
            }
        };

        displayed.addClickHandler(clickHandler);
        icon.addClickHandler(clickHandler);

    }