本文整理匯總了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));
}