本文整理汇总了Java中javafx.scene.input.KeyCombination.Modifier方法的典型用法代码示例。如果您正苦于以下问题:Java KeyCombination.Modifier方法的具体用法?Java KeyCombination.Modifier怎么用?Java KeyCombination.Modifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.input.KeyCombination
的用法示例。
在下文中一共展示了KeyCombination.Modifier方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translateAccelerator
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
/**
* converts a swing accelerator key to a JavaFX key combination
*
* @param acceleratorKey
* @return key combination
*/
public static KeyCombination translateAccelerator(KeyStroke acceleratorKey) {
final List<KeyCombination.Modifier> modifiers = new ArrayList<>();
if ((acceleratorKey.getModifiers() & java.awt.event.InputEvent.SHIFT_DOWN_MASK) != 0)
modifiers.add(KeyCombination.SHIFT_DOWN);
if ((acceleratorKey.getModifiers() & java.awt.event.InputEvent.CTRL_DOWN_MASK) != 0)
modifiers.add(KeyCombination.CONTROL_DOWN);
if ((acceleratorKey.getModifiers() & java.awt.event.InputEvent.ALT_DOWN_MASK) != 0)
modifiers.add(KeyCombination.ALT_DOWN);
if ((acceleratorKey.getModifiers() & InputEvent.META_DOWN_MASK) != 0)
modifiers.add(KeyCombination.META_DOWN);
KeyCode keyCode = FXSwingUtilities.getKeyCodeFX(acceleratorKey.getKeyCode());
return new KeyCodeCombination(keyCode, modifiers.toArray(new KeyCombination.Modifier[modifiers.size()]));
}
示例2: parseSubMenus
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
protected void parseSubMenus (Menu menu, JsonArray jsonArray) {
for (int i = 0; i < jsonArray.size(); i++) {
//get json object
JsonObject entry = jsonArray.getJsonObject(i);
//get event and title
String event = entry.getString("event");
String title = entry.getString("title");
//create new menu item
MenuItem menuItem = new MenuItem(title);
//add click handler
menuItem.setOnAction(event1 -> {
System.out.println("open activitiy: " + event);
EventBus.getInstance().raiseEvent("open_activity", event);
});
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN));
//check for shortcut
if (entry.containsKey("shortcut") && !entry.getString("shortcut").isEmpty()) {
String keys[] = entry.getString("shortcut").split("\\+");
if (keys.length > 1) {
KeyCombination.Modifier modifier = null;
if (keys[1].equals("SHIFT_DOWN")) {
modifier = KeyCombination.SHIFT_DOWN;
} else {
throw new UnsupportedOperationException("Unsupported key code: " + keys[1]);
}
//KeyCombination combination = KeyCombination.keyCombination(keys[1]);
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0]), modifier));
} else if (keys.length == 1) {
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0])));
} else {
//no shortcut is set
}
}
//add menu item to menu
menu.getItems().add(menuItem);
}
}
示例3: keyPressed
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
static EventPattern<Event, KeyEvent> keyPressed(KeyCode code, KeyCombination.Modifier... modifiers) {
return keyPressed(new KeyCodeCombination(code, modifiers));
}
示例4: keyReleased
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
static EventPattern<Event, KeyEvent> keyReleased(KeyCode code, KeyCombination.Modifier... modifiers) {
return keyReleased(new KeyCodeCombination(code, modifiers));
}
示例5: keyTyped
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
static EventPattern<Event, KeyEvent> keyTyped(Predicate<String> charTest, KeyCombination.Modifier... modifiers) {
KeyTypedCombination combination = new KeyTypedCombination(charTest, modifiers);
return keyTyped().onlyIf(combination::match);
}
示例6: KeyCodePatternCombination
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
KeyCodePatternCombination(Predicate<KeyCode> keyTest, KeyCombination.Modifier... modifiers) {
super(modifiers);
this.keyTest = keyTest;
}
示例7: KeyPairs
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
public KeyPairs(KeyCode keyCode, KeyCombination.Modifier... modifiers) {
this.keyCodes = new KeyCode[]{keyCode};
this.combination = new KeyCodeCombination(keyCode, modifiers);
}
示例8: setHotKey
import javafx.scene.input.KeyCombination; //导入方法依赖的package包/类
/**
* Set hot key for menu element with shift
*
* @param item MenuItem
* @param keyCode KeyCode
*/
private void setHotKey(MenuItem item, KeyCode keyCode, KeyCombination.Modifier keyMod) {
item.setAccelerator(new KeyCodeCombination(keyCode, keyMod, keyModifier));
}