/** * 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)))); }
/** * 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>&, ^, *, \, !, +</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()])); }
@Subscribe public void requestScene( final SceneEvent sceneType ) { final Scene scene = _injector.getInstance( sceneType.getType( ) ); scene.getAccelerators( ).put( new KeyCodeCombination( KeyCode.F11 ), ( ) -> { _primaryStage.setFullScreen( !_primaryStage.isFullScreen( ) ); } ); scene.getAccelerators( ).put( new KeyCodeCombination( KeyCode.ESCAPE ), ( ) -> { _eventBus.post( new SceneEvent( ConfigurationScene.class ) ); } ); LOGGER.info( "Change scene to " + sceneType.getType( ).getSimpleName( ) ); _primaryStage.setScene( scene ); if ( scene instanceof WallScene ) _apiMonitoringService.activate( ); else _apiMonitoringService.pause( ); }
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; }
private String convert(KeyEvent e) { return TaskUtil.firstSuccess( () -> new KeyCodeCombination(e.getCode(), e.isShiftDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isControlDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isAltDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isMetaDown() ? ModifierValue.DOWN : ModifierValue.UP, ModifierValue.UP).toString(), () -> { KeyCodeCombination key = new KeyCodeCombination(KeyCode.A, e.isShiftDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isControlDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isAltDown() ? ModifierValue.DOWN : ModifierValue.UP, e.isMetaDown() ? ModifierValue.DOWN : ModifierValue.UP, ModifierValue.UP); String name = key.getName(); return name.substring(0, name.length() - key.getCode().getName().length()); }); }
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 }
/** * 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(); }
/** * 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(); }
@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(); }
/** * * 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); }
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; }
/** * 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()])); }
@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()); } }); }
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; }
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(); } } }); }
private void handleKeyPressed(KeyEvent e) { if (e.isConsumed()) { return; } if (new KeyCodeCombination(KeyCode.ESCAPE).match(e)) { close(); e.consume(); return; } if (new KeyCodeCombination(KeyCode.ENTER).match(e)) { Button defaultButton = (Button) container.lookup("#defaultButton"); defaultButton.arm(); e.consume(); return; } }
private void onKeyPressed(KeyEvent event) { if (event.isConsumed()) { return; } if (new KeyCodeCombination(DIGIT7, SHORTCUT_DOWN).match(event)) { performCommenting(); event.consume(); return; } if (new KeyCodeCombination(S, SHORTCUT_DOWN).match(event)) { save(); event.consume(); return; } if (new KeyCodeCombination(F, SHORTCUT_DOWN).match(event)) { findReplace(); event.consume(); return; } }
private KeyBinding setKey( final KeyBinding b, final KeyCodeCombination k, final Map<KeyBinding, KeyCodeCombination> keysMap ) { if (k == null) { final KeyCodeCombination previous = keysMap.get(b); if (previous != null) { keys.remove(previous); keysMap.remove(b); } return null; } final KeyBinding last = keys.put(k, b); removeOldBinding(last, b, k); keysMap.put(b, k); return last; }
@Override public JSONObject getJSON() { final JSONObject o = new JSONObject(); final JSONArray a = new JSONArray(); for (final KeyCodeCombination key : keys.keySet()) { final JSONObject k = new JSONObject(); k.put("code", key.getCode().toString()); k.put("control", key.getControl().toString()); k.put("alt", key.getAlt().toString()); k.put("meta", key.getMeta().toString()); k.put("shift", key.getShift().toString()); k.put("shortcut", key.getShortcut().toString()); k.put("action", keys.get(key).toString()); k.put("primary", primaryKeys.get(keys.get(key)).equals(key)); a.put(k); } o.put("keys", a); return o; }
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; }
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); }
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); }
/** * 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()); }); }
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; }
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; } }
@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"); } }
/** * Presses the provided {@link KeyCodeCombination}'s keys. * * @param kb the KeyCodeCombination * @return true, if successful */ @SuppressWarnings("deprecation") protected boolean keysDown(KeyCodeCombination kb) { try { if (kb.getShortcut() == ModifierValue.DOWN) { robot.keyPress(shortcutKeyEvent); Thread.sleep(modifiersPressSleepTime); } if (kb.getAlt() == ModifierValue.DOWN) { robot.keyPress(KeyEvent.VK_ALT); Thread.sleep(modifiersPressSleepTime); } if (kb.getShift() == ModifierValue.DOWN) { robot.keyPress(KeyEvent.VK_SHIFT); Thread.sleep(modifiersPressSleepTime); } // I know this is a bad practice. Do you have any idea how to avoid this, stranger? robot.keyPress(kb.getCode().impl_getCode()); Thread.sleep(modifiersPressSleepTime); } catch (InterruptedException e) { logger.debug("Haha, not this time, InterruptedException!"); return false; } return true; }
/** * Releases the provided {@link KeyCodeCombination}'s keys. * * @param kb the KeyCodeCombination * @return true, if successful */ @SuppressWarnings("deprecation") protected boolean keysUp(KeyCodeCombination kb) { try { // I know this is a bad practice. Do you have any idea how to avoid this, stranger? robot.keyRelease(kb.getCode().impl_getCode()); Thread.sleep(modifiersPressSleepTime); if (kb.getShift() == ModifierValue.DOWN) { robot.keyRelease(KeyEvent.VK_SHIFT); Thread.sleep(modifiersPressSleepTime); } if (kb.getAlt() == ModifierValue.DOWN) { robot.keyRelease(KeyEvent.VK_ALT); Thread.sleep(modifiersPressSleepTime); } if (kb.getShortcut() == ModifierValue.DOWN) { robot.keyRelease(shortcutKeyEvent); } } catch (InterruptedException e) { logger.debug("Haha, not this time, InterruptedException!"); return false; } return true; }
/** * Fills Hotkeys tab with fields and values to edit KeyCodeCombinations of Hotkeys. */ private void initializeHotkeysTab() { int rowToFill = 1; // Start filling from second row, because first row is column names. for (Entry<Hotkey, ObjectProperty<KeyCodeCombination>> entry : HotkeyManager .getRegisteredHotkeys().entrySet()) { Hotkey hk = entry.getKey(); KeyCodeCombination kcc = entry.getValue().get(); HotkeyRow hkRow = new HotkeyRow(hk); allHotkeyRows.add(hkRow); hkRow.setCurrentKeyCodeCombination(kcc); hotkeysGridPane.addRow(rowToFill, hkRow.getDescriptionLabel(), hkRow.getKeyTextField(), hkRow.getModifiersTextField(), hkRow.getRestoreDefaultButton()); hkRow.setValidationSupport(validationSupport); rowToFill++; } }
private void initializeBindings() { StringBinding readableKey = Bindings.createStringBinding(() -> { KeyCodeCombination kcc = keyCombinationProperty.get(); if (kcc == null) { disableModifiersTextFieldValidation(); return ""; } else { enableModifiersTextFieldValidation(); return kcc.getCode().getName(); } }, keyCombinationProperty); StringBinding readableModifiers = Bindings.createStringBinding(() -> { return modifiersTextFromKeyCombination(keyCombinationProperty.get()); }, keyCombinationProperty); modifiersTextField.textProperty().bind(readableModifiers); keyTextField.textProperty().bind(readableKey); // Disable Modifiers field if Key is not set. modifiersTextField.disableProperty().bind(keyTextField.textProperty().isEmpty()); }
private void initializeBindings() { StringBinding readableKey = Bindings.createStringBinding(() -> { KeyCodeCombination kcc = keyCombinationProperty.get(); if (kcc == null || kcc.getCode() == KeyCode.CLEAR) { return ""; } else { return kcc.getCode().getName(); } }, keyCombinationProperty); StringBinding readableModifiers = Bindings.createStringBinding(() -> { return modifiersTextFromKeyCombination(keyCombinationProperty.get()); }, keyCombinationProperty); modifiersTextField.textProperty().bind(readableModifiers); keyTextField.textProperty().bind(readableKey); // Disable Modifiers field if Key is not set. modifiersTextField.disableProperty().bind(keyTextField.textProperty().isEmpty()); }
@Override public void initialize(URL location, ResourceBundle resources) { xHBox.getChildren().add(xTextField); yHBox.getChildren().add(yTextField); wHBox.getChildren().add(wTextField); hHBox.getChildren().add(hTextField); selectRegionButtonOrigText = selectRegionButton.getText(); selectRegionButton.setGraphic(crosshairIcon); selectRegionButton.sceneProperty().addListener((o, oldVal, newVal) -> { ObjectProperty<KeyCodeCombination> opkcc = HotkeyManager .getKeyCodeCombinationPropertyOfHotkey(Hotkey.SELECTREGION); if (newVal != null) { // If inside the Scene, add runnable of this button to Hotkey. HotkeyManager.setSelectRegionRunnable(selectRegionRunnable); // Change text of the button to show Hotkey. changeSelectRegionButtonBasedOnKeyCombination(opkcc.get()); opkcc.addListener(selectRegionHotkeyListener); } else { opkcc.removeListener(selectRegionHotkeyListener); changeSelectRegionButtonBasedOnKeyCombination(null); // If outside the Scene, remove runnable of this button from Hotkey. HotkeyManager.setSelectRegionRunnable(null); } }); }
@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; }
private List<KeyCode> getKeyCodes(KeyCodeCombination combination) { List<KeyCode> keys = new ArrayList<>(); if (combination.getAlt() == KeyCombination.ModifierValue.DOWN) { keys.add(KeyCode.ALT); } if (combination.getShift() == KeyCombination.ModifierValue.DOWN) { keys.add(KeyCode.SHIFT); } if (combination.getMeta() == KeyCombination.ModifierValue.DOWN) { keys.add(KeyCode.META); } if (combination.getControl() == KeyCombination.ModifierValue.DOWN) { keys.add(KeyCode.CONTROL); } if (combination.getShortcut() == KeyCombination.ModifierValue.DOWN) { // Fix bug with internal method not having a proper code for SHORTCUT. // Dispatch manually based on platform. if (PlatformSpecific.isOnMac()) { keys.add(KeyCode.META); } else { keys.add(KeyCode.CONTROL); } } keys.add(combination.getCode()); return keys; }
static String getStringRepresentation(String keyCodePropertyName) { if (ScreenFXConfig.getInstance().get(keyCodePropertyName) instanceof KeyCodeCombination) { return ((KeyCodeCombination) ScreenFXConfig.getInstance().get(keyCodePropertyName)).getName(); } if (ScreenFXConfig.getInstance().get(keyCodePropertyName) instanceof KeyCombination) { return ((KeyCombination) ScreenFXConfig.getInstance().get(keyCodePropertyName)).getName(); } if (ScreenFXConfig.getInstance().get(keyCodePropertyName) instanceof KeyCharacterCombination) { return ((KeyCharacterCombination) ScreenFXConfig.getInstance().get(keyCodePropertyName)) .getName(); } if (ScreenFXConfig.getInstance().get(keyCodePropertyName) instanceof KeyCode) { return ((KeyCode) ScreenFXConfig.getInstance().get(keyCodePropertyName)).getName(); } return null; }