aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/FocusShortcuts.java
blob: 089f95a5d946fb01cec708b4c0550a5adc35ccf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.vaadin.tests.components;

import com.vaadin.event.FocusShortcut;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.TextField;

public class FocusShortcuts extends AbstractTestUIWithLog {

    @Override
    protected void setup(VaadinRequest request) {
        TextField name = new TextField("Name (Alt+N)");
        name.addShortcutListener(
                new FocusShortcut(name, KeyCode.N, ModifierKey.ALT));
        name.addFocusListener(event -> log("Alt+N"));

        TextField address = new TextField("Address (Alt+A)");
        address.addShortcutListener(new FocusShortcut(address, "&Address"));
        address.addFocusListener(event -> log("Alt+A"));

        TextField name2 = new TextField("Name (Ctrl+Shift+D)");
        name2.addShortcutListener(new FocusShortcut(name2, KeyCode.D,
                ModifierKey.CTRL, ModifierKey.SHIFT));
        name2.addFocusListener(event -> log("Ctrl+Shift+D"));

        addComponents(name, address, name2);
    }

}