@Override protected void beforeParentInit() { try { SettingsPersistenceUtil.restoreProperties(this, DesignerUtil.getSettingsFile()); } catch (Exception e) { // shouldn't prevent the app from opening // in case the file is corrupted, it will be overwritten on shutdown e.printStackTrace(); } initializeViewAnimation(); licenseMenuItem.setOnAction(e -> showLicensePopup()); openFileMenuItem.setOnAction(e -> onOpenFileClicked()); openRecentMenu.setOnAction(e -> updateRecentFilesMenu()); openRecentMenu.setOnShowing(e -> updateRecentFilesMenu()); fileMenu.setOnShowing(e -> onFileMenuShowing()); setupAuxclasspathMenuItem.setOnAction(e -> sourceEditorController.showAuxclasspathSetupPopup(designerRoot)); openEventLogMenuItem.setOnAction(e -> eventLogController.getValue().showPopup()); openEventLogMenuItem.textProperty().bind( designerRoot.getLogger().numNewLogEntriesProperty().map(i -> "Exception log (" + (i > 0 ? i : "no") + " new)") ); }
/** * Configures a {@link MenuItem} with the specified action. * * @param menuItem the menu item to configre * @param action the action * @param iconSize the icon size */ public static void configureMenuItem(MenuItem menuItem, FXAction action, int iconSize) { menuItem.setMnemonicParsing(true); menuItem.textProperty().bind(action.displayNameProperty()); menuItem.acceleratorProperty().bind(action.acceleratorProperty()); menuItem.setOnAction(action); menuItem.disableProperty().bind(action.enabledProperty().not()); if (action.getGraphicFactory() != null) { Node graphic = action.getGraphicFactory().createGraphic(iconSize); if (graphic != null) { menuItem.setGraphic(graphic); } } }
private static void unconfigure(final MenuItem menuItem) { if (menuItem == null || !(menuItem.getOnAction() instanceof Action)) { return; } Action action = (Action) menuItem.getOnAction(); menuItem.styleProperty().unbind(); menuItem.textProperty().unbind(); menuItem.disableProperty().unbind(); menuItem.acceleratorProperty().unbind(); menuItem.graphicProperty().unbind(); action.getProperties().removeListener(new MenuItemPropertiesMapChangeListener<>(menuItem, action)); if (menuItem instanceof RadioMenuItem) { ((RadioMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty()); } else if (menuItem instanceof CheckMenuItem) { ((CheckMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty()); } menuItem.setOnAction(null); }
menuItem.textProperty().bind(action.textProperty()); menuItem.disableProperty().bind(action.disabledProperty()); menuItem.acceleratorProperty().bind(action.acceleratorProperty());