Java 类javafx.scene.input.KeyCombination 实例源码

项目:primitivefxmvc    文件:GenericView.java   
/**
 * Creates stage by calling createScene and with almost every properties of object.
 *
 * @see GenericView#createScene()
 * @see javafx.stage.Stage
 * @return
 * @throws IOException
 */
public Stage createStage() throws IOException {
    Stage stage = new Stage();

    if (this.getTitle() != null) stage.setTitle(this.getTitle());

    stage.setScene(this.createScene());

    stage.setResizable(this.isResizable());
    stage.setMaximized(this.isMaximized());
    stage.setFullScreen(this.isFullscreen());
    stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);

    if (!this.isDecorated()) stage.initStyle(StageStyle.UNDECORATED);
    if (this.isModal()) stage.initModality(Modality.APPLICATION_MODAL);

    if (this.getIcon() != null)
        stage.getIcons().add(this.getIcon());

    if (this.getIcon() == null && GenericView.getGlobalIcon() != null)
        stage.getIcons().add(GenericView.getGlobalIcon());

    return stage;
}
项目:EC_GroupProj_CSC143    文件:MainWindowController.java   
/**
 * Called when the GUI is created. If we need to do something special to anything in the GUI, we do it in here.
 */
@FXML
public void initialize() {
    //Gives the "reset board" menu option the shortcut of ctrl+r
    resetBoard.setAccelerator(new KeyCodeCombination(KeyCode.R,  KeyCombination.CONTROL_DOWN));
    exit.setAccelerator(new KeyCodeCombination(KeyCode.F4, KeyCombination.ALT_DOWN));
    for (int x = 0; x < boardWidth; x++) {
        for (int y = 0; y < boardHeight; y++) {
            board.add(new FXSpace(), x, y);
        }
    }
    board.setMaxWidth(FXSpace.WIDTH * boardWidth);
    board.setMaxHeight(FXSpace.HEIGHT * boardHeight);
    board.setBorder(new Border(new BorderStroke(Color.LIGHTGREY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));

    for (int x = 0; x < tileTrayWidth; x++) {
        tileTray.add(new FXSpace(), x, 0);
    }
    tileTray.setMaxWidth(FXSpace.WIDTH * tileTrayWidth);
    tileTray.setMaxHeight(FXSpace.HEIGHT * 1);
    tileTray.setBorder(new Border(new BorderStroke(Color.LIGHTGREY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));
}
项目:marathonv5    文件:FXContextMenuTriggers.java   
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();
}
项目:fxutils    文件:FXKeyboard.java   
/**
 * Convenience method for building {@link KeyCombination} objects from a string descriptor.
 * Supports any combination of Ctrl (or Mac Command), Alt, Shift plus one of the following:
 * <ul>
 * <li>letter [A-Z], case insensitive</li>
 * <li>digit [0-9]</li>
 * <li>backspace, space</li>
 * <li>&amp;, ^, *, \, !, +</li>
 * </ul>
 * 
 * @param keyCombination A string representing a key combination
 * @return A JavaFX <code>KeyCombination</code> object
 */
public static KeyCombination buildKeyCombination(String keyCombination) {
    keyCombination = keyCombination.toLowerCase();
    List<String> keys = Arrays.asList(keyCombination.split("\\+"));
    if(keys.size() < 1)
        throw new IllegalArgumentException("Key combination is empty");

    String stringCode = keys.get(keys.size() - 1);
    KeyCode keyCode = asKeyCombinationMain(stringCode);

    List<Modifier> modifiers = keys.stream()
            .limit(keys.size() - 1)
            .distinct()
            .map(FXKeyboard::asKeyCombinationModifier)
            .collect(Collectors.toList());  

    return new KeyCodeCombination(keyCode, modifiers.toArray(new Modifier[modifiers.size()]));
}
项目:boomer-tuner    文件:RootView.java   
private Menu createViewMenu() {
    final Menu view = new Menu("View");
    final CheckMenuItem darkMode = new CheckMenuItem("Dark Mode");
    darkMode.setSelected(rootModel.darkModeProperty().get());
    rootModel.darkModeProperty().addListener((obs, old, val) -> darkMode.setSelected(val));
    darkMode.setOnAction(e -> {
        rootController.toggleDarkMode(getStylesheets());
        invertImages();
    });

    final MenuItem lyrics = new MenuItem("Show Lyrics");
    lyrics.setOnAction(e -> rootController.lyricsPressed());
    lyrics.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN));

    view.getItems().addAll(darkMode, lyrics);
    return view;
}
项目:CSS-Editor-FX    文件:OptionsController.java   
@Override
protected void updateItem(KeyCombination item, boolean empty) {
  super.updateItem(item, empty);
  if (empty) {
    setText(null);
    setGraphic(null);
  } else {
    if (isEditing()) {
      setText(null);
      setGraphic(field);
    } else {
      setText(getString());
      setGraphic(null);
    }
  }
}
项目:CSS-Editor-FX    文件:OptionsController.java   
private void createField() {
  field = new TextField(getString());
  field.setEditable(false);
  field.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
    if (e.getCode() == KeyCode.ENTER) {
      try {
        commitEdit(KeyCombination.valueOf(field.getText()));
      } catch (Exception ee) {
        cancelEdit();
      }
    } else if (e.getCode() == KeyCode.ESCAPE) {
      cancelEdit();
    } else {
      field.setText(convert(e).toString());
    }
    e.consume();
  });
}
项目:qupath-tracking-extension    文件:QuPathTrackingExtension.java   
public void installExtension(QuPathGUI qupath) {
    initDefaultViewTrackerFactory(qupath.getViewer());

    if (System.getProperty("os.name").toLowerCase().contains("linux")) {
        DisplayHelpers.showInfoNotification("Tracking extension issue reporting",
                "Bug reports and feature requests can be logged at:\n" +
                "http://github.com/Alanocallaghan/qupath-tracking-extension");
    } else {
        QuPathGUI.addMenuItems(
                qupath.getMenu("Extensions>Tracking", true),
                QuPathGUI.createCommandAction(
                        new OpenWebpageCommand(qupath,
                                "http://github.com/Alanocallaghan/qupath-tracking-extension/issues"),
                        "Bug reports/issues")
        );
    }

    QuPathGUI.addMenuItems(
            qupath.getMenu("Extensions>Tracking", true),
            QuPathGUI.createCommandAction(new TrackingQuPathLoadCommand(), "Tracking extension"),
            new KeyCodeCombination(KeyCode.T, KeyCombination.CONTROL_DOWN)
            );

       // TODO: Use md5 sum to tie tracking instance to image (using MessageDigest) http://stackoverflow.com/questions/4187111/how-to-get-the-md5sum-of-a-file-in-java

}
项目:Game-Engine-Vooga    文件:FullScreenWindowItem.java   
/**
 * Action to be taken on the selection of this menuItem
 */
@Override
public void handle() {
    /*
     * Shuts the stage and sets fullscreen directives and defines
     * a KeyCombination and shows the stage
     * 
     */
    this.myGameRunner.getGameDisplay().getStage().close();
    this.myGameRunner.getGameDisplay().getStage().setFullScreen(true);
    this.myGameRunner.getGameDisplay().getStage().setFullScreenExitHint(EXIT_MESSAGE);
    this.myGameRunner.getGameDisplay().getStage()
                .setFullScreenExitKeyCombination
                (new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN));
    this.myGameRunner.getGameDisplay().getStage().show();
}
项目:Game-Engine-Vooga    文件:GetPlayerHelpHelpItem.java   
/**
 * Takes the user to the customized help page
 * 
 * @param link
 */
private void popup(String link){
    myBrowser = new WebView();
    myWebEngine = myBrowser.getEngine();
    myWebEngine.load(link);
    VBox vbox = new VBox();
    Scene scene = new Scene(vbox);
    Stage stage = new Stage();        
    vbox.getChildren().addAll(myBrowser);
    VBox.setVgrow(myBrowser, Priority.ALWAYS);
    stage.setScene(scene);
    stage.setFullScreen(true);
    stage.setFullScreenExitHint(EXIT_MESSAGE);
    stage.setFullScreenExitKeyCombination
    (new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN));
    stage.show();
}
项目:Incubator    文件:StartApplication.java   
@Override
public void start(Stage primaryStage) throws Exception {
    final ApplicationView applicationView = new ApplicationView();
    final ApplicationPresenter applicationPresenter = applicationView.getRealPresenter();

    final Scene scene = new Scene(applicationView.getView(), 1920, 1080);
    scene.setOnKeyReleased((KeyEvent event) -> {
        this.onKeyReleased(event);
    });
    primaryStage.setScene(scene);

    primaryStage.setFullScreen(true);
    primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
    primaryStage.setTitle(this.getProperty(KEY__APPLICATION__TITLE) + this.getProperty(KEY__APPLICATION__VERSION));
    primaryStage.setOnCloseRequest((WindowEvent we) -> {
       we.consume();

       this.onCloseRequest();
    });

    primaryStage.show();
    applicationPresenter.initializeAfterWindowIsShowing();
}
项目:Gargoyle    文件:SqlTabPanExample.java   
@Override
public void start(Stage primaryStage) throws NotYetSupportException, GargoyleConnectionFailException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    primaryStage.setTitle("Database Exam");

    CommonsSqllPan sqlPane = CommonsSqllPan.getSqlPane();
    sqlPane.getStylesheets().add(SkinManager.getInstance().getSkin());
    BorderPane root = new BorderPane(sqlPane);
    Menu menu = new Menu("Exam");
    MenuItem e = new MenuItem("exam");
    e.setOnAction(System.out::println);
    e.setAccelerator(new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
    menu.getItems().add(e);
    root.setTop(new MenuBar(menu));

    primaryStage.setScene(new Scene(root, 1100, 700));

    primaryStage.show();

    // Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA);

    // DockPane.initializeDefaultUserAgentStylesheet();

}
项目:Gargoyle    文件:CodeAreaHelper.java   
/**
 *
 * 2016-10-27 키 이벤트를 setAccelerator를 사용하지않고 이벤트 방식으로 변경 이유 : 도킹기능을 적용하하면
 * setAccelerator에 등록된 이벤트가 호출안됨
 *
 * @작성자 : KYJ
 * @작성일 : 2016. 10. 27.
 */
public void createMenus() {

    Menu menuSearch = findAndReplaceHelper.createMenus();

    menuMoveToLine = new MenuItem("Move to line");
    miToUppercase = new MenuItem("To Uppercase");
    miToLowercase = new MenuItem("To Lowercase");

    menuMoveToLine.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN));
    menuMoveToLine.setOnAction(this::moveToLineEvent);
    miToUppercase.setAccelerator(new KeyCodeCombination(KeyCode.U, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
    miToUppercase.setOnAction(this::toUppercaseEvent);
    miToLowercase.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
    miToLowercase.setOnAction(this::toLowercaseEvent);

    codeArea.getContextMenu().getItems().addAll(menuSearch, menuMoveToLine, miToUppercase, miToLowercase);

}
项目:Gargoyle    文件:DockTab.java   
public static void removeAcceleratorsFromScene(List<? extends MenuItem> items, Scene scene) {
    if (scene == null) {
        return;
    }

    for (final MenuItem menuitem : items) {
        if (menuitem instanceof Menu) {
            // TODO remove the menu listener from the menu.items list

            // remove the accelerators of items contained within the menu
            removeAcceleratorsFromScene(((Menu) menuitem).getItems(), scene);
        } else {
            // remove the removed MenuItem accelerator KeyCombination from
            // the scene accelerators map
            final Map<KeyCombination, Runnable> accelerators = scene.getAccelerators();
            accelerators.remove(menuitem.getAccelerator());
        }
    }
}
项目:xframium-java    文件:PluginsStage.java   
public void select (boolean activate)
{
  if (activate)
    plugin.activate ();
  else
    plugin.deactivate ();

  if (requestMenuItem == null && plugin.doesRequest ())
  {
    requestMenuItem = new MenuItem (name.getText ());
    requestMenuItem.setOnAction (e -> processPluginRequest (plugin));
    requestMenuItem.setAccelerator (new KeyCodeCombination (keyCodes[requestMenus++],
        KeyCombination.SHORTCUT_DOWN));
  }

  isActivated = activate;
}
项目:L2smr    文件:Controller.java   
private void initializeKeyCombinations() {
    Map<KeyCombination, Runnable> keyCombinations = new HashMap<>();
    keyCombinations.put(keyCombination("F1"), this::showHelp);
    keyCombinations.put(keyCombination("CTRL+O"), this::chooseL2Folder);
    keyCombinations.put(keyCombination("CTRL+M"), this::modify);
    keyCombinations.put(keyCombination("CTRL+E"), this::exportSM);
    keyCombinations.put(keyCombination("CTRL+I"), this::importSM);
    keyCombinations.put(keyCombination("CTRL+T"), this::exportSMT3d);

    getStage().getScene().addEventFilter(KeyEvent.KEY_PRESSED, event -> keyCombinations.entrySet()
            .stream()
            .filter(e -> e.getKey().match(event))
            .findAny()
            .ifPresent(e -> {
                e.getValue().run();
                event.consume();
            }));
}
项目:megan-ce    文件:CommandManagerFX.java   
/**
 * 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()]));
}
项目:openjfx-8u-dev-tests    文件:MenuBarAppManual.java   
public KeyCombination getShortcut() {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < mods.length; i++) {
        if (((mask >> i) & 1) != 0) {
            stringBuilder.append(mods[i]).append("+");
        }
    }
    stringBuilder.append(c);

    if (++c > 'Z') {
        c = 'A';
        mask++;
    }

    KeyCombination kk = KeyCombination.keyCombination(stringBuilder.toString());
    return kk;
}
项目:openjfx-8u-dev-tests    文件:staticPropertyLoadApp.java   
@Override
public Node impl_drawNode() {
    /*
    MenuItem mi = new MenuItem();
    mi.setText("open...");
    mi.setGraphic(new ImageView());
    mi.setAccelerator(KeyCombination.keyCombination("CTRL+N"));
     */

    try {
        mi2 = FXMLLoader.load(resource);
    } catch (Exception e) {
        System.out.println("message: " + e.getMessage());
        e.printStackTrace();
        reportGetterFailure("exception thrown.");
    }
    System.out.println("DEBUG: menuItem.getText()=" + ((null != mi2) ? mi2.getText() : "(null)"));
    if ((null != mi2)
            && (0 == "open...".compareTo(mi2.getText()))
            && (KeyCombination.keyCombination("CTRL+N").equals(mi2.getAccelerator()))) {
        return retRec;
    } else {
        reportGetterFailure("failed.");
        return redRectangle;
    }
}
项目:MagicMetro    文件:Main.java   
@Override
public void start(Stage primaryStage) throws Exception {
    this.stage = primaryStage;
    initMapScripts();
    MenuManager menuManager = new MenuManager(this.stage, this.mapScripts);
    menuManager.DisplayMenus();
    this.stage.show();

    //TODO: shortcut to go fullscreen?

    // shortcut to exit fullscreen
    this.stage.setFullScreenExitKeyCombination(new KeyCodeCombination(KeyCode.F, KeyCombination.SHIFT_DOWN));

    this.stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            TimeManager.getInstance().end();
            EventDispatcher.getInstance().fire(new GameExitEvent());
        }
    });
}
项目:qupath    文件:DefaultScriptEditor.java   
Action createOpenAction(final String name) {
    Action action = new Action(name, e -> {

        String dirPath = PathPrefs.getScriptsPath();
        File dir = null;
        if (dirPath != null)
            dir = new File(dirPath);
        File file = QuPathGUI.getSharedDialogHelper().promptForFile("Choose script file", dir, "Known script files", SCRIPT_EXTENSIONS);
        if (file == null)
            return;
        try {
            addScript(file, true);
            PathPrefs.setScriptsPath(file.getParent());
        } catch (Exception ex) {
            logger.error("Unable to open script file: {}", ex);
            ex.printStackTrace();
        }
    });
    action.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    return action;
}
项目:LuoYing    文件:UIManager.java   
private static void JfxUndoRedoKeyEventToJme() {
    Jfx.getJfxRoot().addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
        final KeyCombination undo = new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN);
        final KeyCombination redo = new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN);
        final KeyCombination save = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN);
        final KeyCombination saveAll = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN);
        @Override
        public void handle(KeyEvent ke) {
            if (save.match(ke)) {
                ((Editor) Jfx.getJmeApp()).save();
            } else if (saveAll.match(ke)) {
                ((Editor) Jfx.getJmeApp()).saveAll();
            } else if(redo.match(ke)) {
                ((Editor) Jfx.getJmeApp()).redo();
            } else if (undo.match(ke)) {
                ((Editor) Jfx.getJmeApp()).undo();
            }
        }
    });
}
项目:CSS-Editor-FX    文件:OptionsController.java   
@Override
protected void updateItem(KeyCombination item, boolean empty) {
  super.updateItem(item, empty);
  if (empty) {
    setText(null);
    setGraphic(null);
  } else {
    if (isEditing()) {
      setText(null);
      setGraphic(field);
    } else {
      setText(getString());
      setGraphic(null);
    }
  }
}
项目:CSS-Editor-FX    文件:OptionsController.java   
private void createField() {
  field = new TextField(getString());
  field.setEditable(false);
  field.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
    if (e.getCode() == KeyCode.ENTER) {
      try {
        commitEdit(KeyCombination.valueOf(field.getText()));
      } catch (Exception ee) {
        cancelEdit();
      }
    } else if (e.getCode() == KeyCode.ESCAPE) {
      cancelEdit();
    } else {
      field.setText(convert(e).toString());
    }
    e.consume();
  });
}
项目:addressbook-level4    文件:MainWindow.java   
/**
 * Sets the accelerator of a MenuItem.
 * @param keyCombination the KeyCombination value of the accelerator
 */
private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
    menuItem.setAccelerator(keyCombination);

    /*
     * TODO: the code below can be removed once the bug reported here
     * https://bugs.openjdk.java.net/browse/JDK-8131666
     * is fixed in later version of SDK.
     *
     * According to the bug report, TextInputControl (TextField, TextArea) will
     * consume function-key events. Because CommandBox contains a TextField, and
     * ResultDisplay contains a TextArea, thus some accelerators (e.g F1) will
     * not work when the focus is in them because the key event is consumed by
     * the TextInputControl(s).
     *
     * For now, we add following event filter to capture such key events and open
     * help window purposely so to support accelerators even when focus is
     * in CommandBox or ResultDisplay.
     */
    getRoot().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        if (event.getTarget() instanceof TextInputControl && keyCombination.match(event)) {
            menuItem.getOnAction().handle(new ActionEvent());
            event.consume();
        }
    });
}
项目:viskell    文件:MenuActions.java   
protected List<MenuItem> fileMenuItems() {
    List<MenuItem> list = new ArrayList<>();

    MenuItem menuNew = new MenuItem("New");
    menuNew.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN));
    menuNew.setOnAction(this::onNew);
    list.add(menuNew);

    MenuItem menuOpen = new MenuItem("Open...");
    menuOpen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    menuOpen.setOnAction(this::onOpen);
    list.add(menuOpen);

    MenuItem menuSave = new MenuItem("Save");
    menuSave.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN));
    menuSave.setOnAction(this::onSave);
    list.add(menuSave);

    MenuItem menuSaveAs = new MenuItem("Save as...");
    menuSaveAs.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.SHIFT_DOWN, KeyCombination.SHORTCUT_DOWN));
    menuSaveAs.setOnAction(this::onSaveAs);
    list.add(menuSaveAs);

    return list;
}
项目:maptranslator    文件:TranslateEditWindow.java   
private TranslateEditWindow(TranslateEntry entry) {
    stage = new Stage(StageStyle.UTILITY);
    stage.setTitle(translate("translate_edit.title"));
    txt = new TextArea(entry.targetProperty.get());
    btnRestore = new Button(translate("translate_edit.reset"));
    btnOk = new Button(translate("translate_edit.submit"));
    this.entry = entry;

    HBox btnBox = new HBox(btnRestore, btnOk);
    BorderPane rootPane = new BorderPane();
    rootPane.setCenter(txt);
    rootPane.setBottom(btnBox);
    stage.setScene(new Scene(rootPane));

    stage.getScene().addMnemonic(new Mnemonic(btnOk, new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN)));

    btnRestore.setOnAction(event -> restore());
    btnOk.setOnAction(event -> saveAndClose());
    stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN), this::saveAndClose);
    stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN), this::restore);
}
项目:maptranslator    文件:NodeEditWindow.java   
private NodeEditWindow(Node node) {
    this.node = node;
    stage = new Stage(StageStyle.UTILITY);
    stage.setTitle(translate("node_edit.title"));
    txt = new TextArea(node.getText().get());
    btnRestore = new Button(translate("node_edit.reset"));
    btnOk = new Button(translate("node_edit.submit"));

    HBox btnBox = new HBox(btnRestore, btnOk);
    BorderPane rootPane = new BorderPane();
    rootPane.setTop(new Label(node.getPath()));
    rootPane.setCenter(txt);
    rootPane.setBottom(btnBox);
    stage.setScene(new Scene(rootPane));

    stage.getScene().addMnemonic(new Mnemonic(btnOk, new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN)));

    btnRestore.setOnAction(event -> restore());
    btnOk.setOnAction(event -> saveAndClose());
    stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN), this::saveAndClose);
    stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN), this::restore);
}
项目:slidedown    文件:FullScreenController.java   
public static void showStage(WebView webView, SplitPane mainSplitPane) throws IOException {
    int webViewIndex = mainSplitPane.getItems().indexOf(webView);

    FXMLLoader loader = new FXMLLoader(FullScreenController.class.getResource("/fxml/fullscreen.fxml"));
    loader.load();

    FullScreenController controller = loader.getController();
    controller.borderPane.setCenter(webView);

    Stage stage = new Stage(StageStyle.UTILITY);
    stage.setFullScreenExitKeyCombination(KeyCombination.keyCombination("F11"));
    stage.setFullScreen(true);

    Scene scene = new Scene(loader.getRoot());

    scene.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
        if (e.getCode() == KeyCode.F11) {
            stage.close();
            mainSplitPane.getItems().set(webViewIndex, webView);
        }
    });

    stage.setScene(scene);
    stage.show();
}
项目:dnainator    文件:HotkeyHelpDialogTest.java   
/**
 * Test creating a {@link HotkeyHelpDialog}.
 * Ensure that there is a button.
 * Use a given menu.
 */
@Test
public void testCreateMenus() {
    Platform.runLater(() -> {
        Menu menu = new Menu();
        MenuItem mi = new MenuItem();
        mi.setAccelerator(new KeyCodeCombination(KeyCode.F1, KeyCombination.SHORTCUT_ANY));
        menu.getItems().add(mi);

        hhd = new HotkeyHelpDialog(pane, menu);
        // CHECKSTYLE.OFF: MagicNumber
        assertEquals(1, hhd.getButtonTypes().size());
        assertEquals(300, hhd.getDialogPane().getPrefWidth(), 0.001);
        // CHECKSTYLE.ON: MagicNumber
        assertEquals(TITLE, hhd.getTitle());
        assertEquals(TITLE, hhd.getHeaderText());
        assertEquals(Modality.NONE, hhd.getModality());

        GridPane gp = (GridPane) hhd.getDialogPane().getContent();
        assertFalse(gp.getChildren().isEmpty());
    });
}
项目:dm3270    文件:PluginsStage.java   
public void select (boolean activate)
{
  if (activate)
    plugin.activate ();
  else
    plugin.deactivate ();

  if (requestMenuItem == null && plugin.doesRequest ())
  {
    requestMenuItem = new MenuItem (name.getText ());
    requestMenuItem.setOnAction (e -> processPluginRequest (plugin));
    requestMenuItem.setAccelerator (new KeyCodeCombination (keyCodes[requestMenus++],
        KeyCombination.SHORTCUT_DOWN));
  }

  isActivated = activate;
}
项目:JVx.javafx    文件:ScenicViewLoader.java   
/**
 * Attaches ScenicView to the given {@link Scene}, and opens it if the given
 * {@link KeyCombination} is pressed.
 * <p>
 * This is done by installing an {@link EventHandler} as filter on the
 * {@link Scene}.
 * 
 * @param pScene the {@link Scene}.
 * @param pKeyCombination the {@link KeyCombination}.
 * @return {@code true} if it could be successfully attached. {@code false}
 *         if either the given {@link Scene} or {@link KeyCombination} was
 *         {@code null}, or ScenicView could not be loaded.
 */
public static boolean attach(Scene pScene, KeyCombination pKeyCombination)
{
    if (pScene == null || pKeyCombination == null)
    {
        return false;
    }

    Class<?> scenicView = loadScenicView(pScene.getClass().getClassLoader());

    if (scenicView != null)
    {
        pScene.addEventFilter(KeyEvent.KEY_PRESSED, new ScenicViewKeyHandler(pScene, scenicView, pKeyCombination));
        return true;
    }

    return false;
}
项目:JVx.javafx    文件:ScenicViewLoader.java   
/**
 * Creates a new instance of {@link ScenicViewKeyHandler}.
 *
 * @param pScene the {@link Scene}.
 * @param pScenicViewClass the {@link Class} of ScenicView.
 * @param pKeyCombination the {@link KeyCombination} that triggers
 *            ScenicView.
 */
public ScenicViewKeyHandler(Scene pScene, Class<?> pScenicViewClass, KeyCombination pKeyCombination)
{
    scene = pScene;
    scenicViewClass = pScenicViewClass;
    keyCombination = pKeyCombination;

    try
    {
        showMethod = scenicViewClass.getDeclaredMethod("show", Scene.class);
    }
    catch (NoSuchMethodException | SecurityException e)
    {
        // Should not happen.
    }
}
项目:Cachoeira    文件:MainMenuBar.java   
private Menu createProjectMenu() {
    createProject = new MenuItem("Create");
    createProject.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN));
    openProject = new MenuItem("Open");
    openProject.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
    saveProject = new MenuItem("Save");
    saveProject.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN));
    saveAsProject = new MenuItem("Save as");
    saveAsProject.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.SHIFT_DOWN, KeyCombination.CONTROL_DOWN));
    Menu resourcesMenu = new Menu("Resources");
    exportResources = new MenuItem("Export");
    importResources = new MenuItem("Import");
    resourcesMenu.getItems().addAll(exportResources, importResources);
    exit = new MenuItem("Exit");
    Menu projectMenu = new Menu("Project");
    projectMenu.getItems().addAll(createProject, openProject, saveProject, saveAsProject, resourcesMenu, new SeparatorMenuItem(), exit);
    return projectMenu;
}
项目:BetonQuest-Editor    文件:EcoController.java   
private void keyAction(KeyEvent event, Action add, Action edit, Action delete) {
    if (event.getCode() == KeyCode.DELETE) {
        if (delete != null) {
            delete.act();
        }
        event.consume();
        return;
    }
    if (event.getCode() == KeyCode.ENTER) {
        if (edit != null) {
            edit.act();
        }
        event.consume();
        return;
    }
    KeyCombination combintation = new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    if (combintation.match(event)) {
        if (add != null) {
            add.act();
        }
        event.consume();
        return;
    }
}
项目:BetonQuest-Editor    文件:OtherController.java   
private void keyAction(KeyEvent event, Action add, Action edit, Action delete) {
    if (event.getCode() == KeyCode.DELETE) {
        if (delete != null) {
            delete.act();
        }
        event.consume();
        return;
    }
    if (event.getCode() == KeyCode.ENTER) {
        if (edit != null) {
            edit.act();
        }
        event.consume();
        return;
    }
    KeyCombination combintation = new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    if (combintation.match(event)) {
        if (add != null) {
            add.act();
        }
        event.consume();
        return;
    }
}
项目:BetonQuest-Editor    文件:ConversationController.java   
private void keyAction(KeyEvent event, Action add, Action edit, Action delete) {
    if (event.getCode() == KeyCode.DELETE) {
        if (delete != null) {
            delete.act();
        }
        event.consume();
        return;
    }
    if (event.getCode() == KeyCode.ENTER) {
        if (edit != null) {
            edit.act();
        }
        event.consume();
        return;
    }
    KeyCombination combintation = new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    if (combintation.match(event)) {
        if (add != null) {
            add.act();
        }
        event.consume();
        return;
    }
}
项目:BetonQuest-Editor    文件:MainController.java   
private void keyAction(KeyEvent event, Action add, Action edit, Action delete) {
    if (event.getCode() == KeyCode.DELETE) {
        if (delete != null) {
            delete.act();
        }
        event.consume();
        return;
    }
    if (event.getCode() == KeyCode.ENTER) {
        if (edit != null) {
            edit.act();
        }
        event.consume();
        return;
    }
    KeyCombination combintation = new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    if (combintation.match(event)) {
        if (add != null) {
            add.act();
        }
        event.consume();
        return;
    }
}
项目:StreamSis    文件:HotkeyAction.java   
@Override
public void init() {
    super.init();
    if (keysProperty.get() != null) {
        if (keysProperty.get().isEmpty()) {
            elementInfo.setAsBroken("Hotkey is empty");
            return;
        }
    } else {
        elementInfo.setAsBroken("Hotkey is not defined");
        return;
    }
    keyCombination = (KeyCodeCombination) KeyCombination.keyCombination(keysProperty.get());
    // If no modifiers are pressed, lets consider HotkeyAction as broken, because it's not a
    // hotkey.
    if (keyCombination == null) {
        elementInfo.setAsBroken("Hotkey is invalid");
        return;
    }
    if (keyCombination.getCode().equals(emptyCode)) {
        elementInfo.setAsBroken("Key is not defined");
    }
}
项目:LogFX    文件:LogFX.java   
@MustCallOnJavaFXThread
private Menu fileMenu() {
    Menu menu = new Menu( "_File" );
    menu.setMnemonicParsing( true );

    MenuItem open = new MenuItem( "_Open File" );
    open.setAccelerator( new KeyCodeCombination( KeyCode.O, KeyCombination.SHORTCUT_DOWN ) );
    open.setMnemonicParsing( true );
    open.setOnAction( ( event ) -> new FileOpener( stage, this::open ) );

    MenuItem showLogFxLog = new MenuItem( "Open LogFX Log" );
    showLogFxLog.setAccelerator( new KeyCodeCombination( KeyCode.O,
            KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN ) );
    showLogFxLog.setOnAction( ( event ) ->
            open( LogFXLogFactory.INSTANCE.getLogFilePath().toFile() ) );

    MenuItem close = new MenuItem( "E_xit" );
    close.setAccelerator( new KeyCodeCombination( KeyCode.W,
            KeyCombination.SHIFT_DOWN, KeyCombination.SHORTCUT_DOWN ) );
    close.setMnemonicParsing( true );
    close.setOnAction( ( event ) -> stage.close() );
    menu.getItems().addAll( open, showLogFxLog, close );

    return menu;
}