下面列出了怎么用javafx.scene.input.KeyCombination.ModifierValue的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void start(Stage stage) throws IOException {
try {
this.stage = stage;
stage.setTitle("BlockMap map viewer");
stage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
Scene scene = new Scene(root, 700, 450);
scene.getStylesheets().add("/de/piegames/blockmap/gui/standalone/style.css");
stage.setScene(scene);
stage.show();
scene.getAccelerators().put(new KeyCodeCombination(KeyCode.L, ModifierValue.UP, ModifierValue.DOWN, ModifierValue.UP,
ModifierValue.UP, ModifierValue.ANY), controller.worldInput::requestFocus);
GuiMainPreloader.splashScreen.hide();
/* Put this last to guarantee that the application is fully initialized once instance!=null. */
instance = this;
} catch (Throwable t) {
checkLogger();
log.fatal("Cannot start BlockMap", t);
System.exit(-1);
}
}
private static String getDownModifierMask(KeyCombination kc) {
StringBuilder contextMenuKeyModifiers = new StringBuilder();
if (kc.getControl() == ModifierValue.DOWN) {
contextMenuKeyModifiers.append("Ctrl+");
}
if (kc.getAlt() == ModifierValue.DOWN) {
contextMenuKeyModifiers.append("Alt+");
}
if (kc.getMeta() == ModifierValue.DOWN) {
contextMenuKeyModifiers.append("Meta+");
}
if (kc.getShift() == ModifierValue.DOWN) {
contextMenuKeyModifiers.append("Shift+");
}
return contextMenuKeyModifiers.toString();
}
@Test
public void testCreateMenuItemWithAll()
{
MenuItem item = aMenuFactory.createMenuItem("file.open", false, e -> {});
assertEquals("_Open", item.getText());
assertNotNull(item.getGraphic());
KeyCombination accelerator = item.getAccelerator();
assertNotNull(accelerator);
if( System.getProperty("os.name", "unknown").toLowerCase().startsWith("mac") )
{
assertEquals("Meta+O", accelerator.getName());
}
else
{
assertEquals(ModifierValue.DOWN, accelerator.getControl());
assertEquals("Ctrl+O", accelerator.getName());
}
}