com.vaadin.flow.component.Key Java Examples

The following examples show how to use com.vaadin.flow.component.Key. 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: EmployeeEditor.java    From tutorials with MIT License 6 votes vote down vote up
@Autowired
public EmployeeEditor(EmployeeRepository repository) {
    this.repository = repository;

    add(firstName, lastName, actions);

    binder.bindInstanceFields(this);

    setSpacing(true);

    save.getElement().getThemeList().add("primary");
    delete.getElement().getThemeList().add("error");

    addKeyPressListener(Key.ENTER, e -> save());

    save.addClickListener(e -> save());
    delete.addClickListener(e -> delete());
    cancel.addClickListener(e -> editEmployee(employee));
    setVisible(false);
}
 
Example #2
Source File: PreserveOnRefreshShortcutView.java    From flow with Apache License 2.0 5 votes vote down vote up
public PreserveOnRefreshShortcutView() {
    NativeButton button = new NativeButton(
            "Press ENTER, reload the page, and press ENTER again",
            event -> handleClick());
    button.addClickShortcut(Key.ENTER);
    button.setId("trigger");
    add(button);
}
 
Example #3
Source File: KeyboardEvent.java    From flow with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new keyboard event.
 *
 * @param source
 *            the component that fired the event
 * @param fromClient
 *            <code>true</code> if the event was originally fired on the
 *            client, <code>false</code> if the event originates from
 *            server-side logic
 * @param key
 *            the string value representing the key
 * @param code
 *            the string value representing the code (nullable)
 * @param location
 *            the integer value representing the location of the key
 * @param ctrlKey
 *            <code>true</code> if the control key was down when the event
 *            was fired, <code>false</code> otherwise
 * @param shiftKey
 *            <code>true</code> if the shift key was down when the event was
 *            fired, <code>false</code> otherwise
 * @param altKey
 *            <code>true</code> if the alt key was down when the event was
 *            fired, <code>false</code> otherwise
 * @param metaKey
 *            <code>true</code> if the meta key was down when the event was
 *            fired, <code>false</code> otherwise
 * @param repeat
 *            <code>true</code> if the key has been pressed in a sustained
 *            manner
 * @param composing
 *            <code>true</code> if the key event occurred as part of a
 *            composition session
 */
public KeyboardEvent(Component source, boolean fromClient, String key,
                     String code, int location, boolean ctrlKey,
                     boolean shiftKey, boolean altKey, boolean metaKey,
                     boolean repeat, boolean composing) {
    super(source, fromClient);
    this.key = Key.of(key);
    // code might not be present for all keys for all browsers
    // it is quite implementation dependent
    this.code = (code == null || code.isEmpty()) ?
            null : Key.of(code);
    this.location = KeyLocation.of(location);
    this.repeat = repeat;
    this.composing = composing;
    modifiers = EnumSet.noneOf(KeyModifier.class);
    if (ctrlKey) {
        modifiers.add(KeyModifier.CONTROL);
    }
    if (shiftKey) {
        modifiers.add(KeyModifier.SHIFT);
    }
    if (altKey) {
        modifiers.add(KeyModifier.ALT);
    }
    if (metaKey) {
        modifiers.add(KeyModifier.META);
    }
}
 
Example #4
Source File: KeyboardEvent.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the key of the event.
 *
 * @return the {@link Key} of the event
 */
public Key getKey() {
    return key;
}
 
Example #5
Source File: KeyboardEvent.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the code of the event. If the event did not contain a valid code, a
 * <code>null</code> value will be given instead.
 * @return the optional code of the event as a {@link Key}
 */
public Optional<Key> getCode() { return Optional.ofNullable(code); }