Vaadin 如何通过 AbstractField.FocusShortcut 中的 shorthand 符号使用快捷方式将 &Address 转换为 Alt+A?

How Vaadin translates &Address to Alt+A using shortcut by a shorthand notation in AbstractField.FocusShortcut?

正在阅读 Vaadin 之书的这一页:

https://vaadin.com/book/vaadin7/-/page/advanced.shortcuts.html

You can also specify the shortcut by a shorthand notation, where the shortcut key is indicated with an ampersand (&).

// A field with Alt+A bound to it, using shorthand notation
TextField address = new TextField("Address (Alt+A)");
address.addShortcutListener(
        new AbstractField.FocusShortcut(address, "&Address"));

This is especially useful for internationalization, so that you can determine the shortcut key from the localized string.

如果我将此 address 文本字段对象添加到我的布局中,然后我按 Alt+A,该字段将获得焦点。

但是 Vaadin 怎么知道“&Address”是 ALT+A???它是在内部解析字符串还是将其与某些内容进行比较?

键盘快捷键的“&Address”shorthand notation 是什么?还有其他 shorthand 符号吗?

来自ShortcutAction javadocs:

Insert one or more modifier characters before the character to use as keycode. E.g "&Save" will make a shortcut responding to ALT-S, "E^xit" will respond to CTRL-X. Multiple modifiers can be used, e.g "&^Delete" will respond to CTRL-ALT-D (the order of the modifier characters is not important).

The modifier characters will be removed from the caption. The modifier character is be escaped by itself: two consecutive characters are turned into the original character w/o the special meaning. E.g "Save&&&close" will respond to ALT-C, and the caption will say "Save&close".

共有三个修饰字符:^ (ctrl)、& (alt) 和 _ (shift)。在内部,Vaadin 使用正则表达式解析 shorthand 标题,匹配修饰符字符并构建键盘快捷键。可以看看代码here.