List of usage examples for javafx.scene.control MenuBar MenuBar
public MenuBar()
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("Menu Sample"); Scene scene = new Scene(new VBox(), 400, 350); scene.setFill(Color.OLDLACE); name.setFont(new Font("Verdana Bold", 22)); binName.setFont(new Font("Arial Italic", 10)); pic.setFitHeight(150);// w w w .j av a 2 s . c o m pic.setPreserveRatio(true); description.setWrapText(true); description.setTextAlignment(TextAlignment.JUSTIFY); shuffle(); MenuBar menuBar = new MenuBar(); // --- Graphical elements final VBox vbox = new VBox(); vbox.setAlignment(Pos.CENTER); vbox.setSpacing(10); vbox.setPadding(new Insets(0, 10, 0, 10)); vbox.getChildren().addAll(name, binName, pic, description); // --- Menu File Menu menuFile = new Menu("File"); MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png"))); add.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { shuffle(); vbox.setVisible(true); } }); MenuItem clear = new MenuItem("Clear"); clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X")); clear.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { vbox.setVisible(false); } }); MenuItem exit = new MenuItem("Exit"); exit.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.exit(0); } }); menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit); // --- Menu Edit Menu menuEdit = new Menu("Edit"); Menu menuEffect = new Menu("Picture Effect"); final ToggleGroup groupEffect = new ToggleGroup(); for (Entry effect : effects) { RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey()); itemEffect.setUserData(effect.getValue()); itemEffect.setToggleGroup(groupEffect); menuEffect.getItems().add(itemEffect); } final MenuItem noEffects = new MenuItem("No Effects"); noEffects.setDisable(true); noEffects.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { pic.setEffect(null); groupEffect.getSelectedToggle().setSelected(false); noEffects.setDisable(true); } }); groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) { if (groupEffect.getSelectedToggle() != null) { Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData(); pic.setEffect(effect); noEffects.setDisable(false); } else { noEffects.setDisable(true); } } }); menuEdit.getItems().addAll(menuEffect, noEffects); // --- Menu View Menu menuView = new Menu("View"); CheckMenuItem titleView = createMenuItem("Title", name); CheckMenuItem binNameView = createMenuItem("Binomial name", binName); CheckMenuItem picView = createMenuItem("Picture", pic); CheckMenuItem descriptionView = createMenuItem("Decsription", description); menuView.getItems().addAll(titleView, binNameView, picView, descriptionView); menuBar.getMenus().addAll(menuFile, menuEdit, menuView); // --- Context Menu final ContextMenu cm = new ContextMenu(); MenuItem cmItem1 = new MenuItem("Copy Image"); cmItem1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putImage(pic.getImage()); clipboard.setContent(content); } }); cm.getItems().add(cmItem1); pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) cm.show(pic, e.getScreenX(), e.getScreenY()); } }); ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox); stage.setScene(scene); stage.show(); }
From source file:org.nmrfx.processor.gui.MainApp.java
MenuBar makeMenuBar(String appName) { MenuToolkit tk = null;/*from w w w. j a va 2 s. c om*/ if (isMac()) { tk = MenuToolkit.toolkit(); } MenuBar menuBar = new MenuBar(); // Application Menu // TBD: services menu Menu appMenu = new Menu(appName); // Name for appMenu can't be set at // Runtime MenuItem aboutItem = null; Stage aboutStage = makeAbout(appName); if (tk != null) { aboutItem = tk.createAboutMenuItem(appName, aboutStage); } else { aboutItem = new MenuItem("About..."); aboutItem.setOnAction(e -> aboutStage.show()); } MenuItem prefsItem = new MenuItem("Preferences..."); MenuItem quitItem; prefsItem.setOnAction(e -> showPreferences(e)); if (tk != null) { quitItem = tk.createQuitMenuItem(appName); appMenu.getItems().addAll(aboutItem, new SeparatorMenuItem(), prefsItem, new SeparatorMenuItem(), tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(), new SeparatorMenuItem(), quitItem); // createQuitMeneItem doesn't result in stop or quit being called // therefore we can't check for waiting till a commit is done before leaving // so explicitly set action to quit quitItem.setOnAction(e -> quit()); } else { quitItem = new MenuItem("Quit"); quitItem.setOnAction(e -> quit()); } // File Menu (items TBD) Menu fileMenu = new Menu("File"); MenuItem openMenuItem = new MenuItem("Open and Draw..."); openMenuItem.setOnAction(e -> FXMLController.getActiveController().openAction(e)); MenuItem addMenuItem = new MenuItem("Open..."); addMenuItem.setOnAction(e -> FXMLController.getActiveController().addNoDrawAction(e)); MenuItem newMenuItem = new MenuItem("New Window..."); newMenuItem.setOnAction(e -> newGraphics(e)); Menu recentMenuItem = new Menu("Open and Draw Recent"); List<Path> recentDatasets = PreferencesController.getRecentDatasets(); for (Path path : recentDatasets) { int count = path.getNameCount(); int first = count - 3; first = first >= 0 ? first : 0; Path subPath = path.subpath(first, count); MenuItem datasetMenuItem = new MenuItem(subPath.toString()); datasetMenuItem .setOnAction(e -> FXMLController.getActiveController().openFile(path.toString(), false, false)); recentMenuItem.getItems().add(datasetMenuItem); } MenuItem pdfMenuItem = new MenuItem("Export PDF..."); pdfMenuItem.setOnAction(e -> FXMLController.getActiveController().exportPDFAction(e)); MenuItem svgMenuItem = new MenuItem("Export SVG..."); svgMenuItem.setOnAction(e -> FXMLController.getActiveController().exportSVGAction(e)); MenuItem loadPeakListMenuItem = new MenuItem("Load PeakLists"); loadPeakListMenuItem.setOnAction(e -> loadPeakLists()); Menu projectMenu = new Menu("Projects"); MenuItem projectOpenMenuItem = new MenuItem("Open..."); projectOpenMenuItem.setOnAction(e -> loadProject()); MenuItem projectSaveAsMenuItem = new MenuItem("Save As..."); projectSaveAsMenuItem.setOnAction(e -> saveProjectAs()); MenuItem projectSaveMenuItem = new MenuItem("Save"); projectSaveMenuItem.setOnAction(e -> saveProject()); Menu recentProjectMenuItem = new Menu("Open Recent"); List<Path> recentProjects = PreferencesController.getRecentProjects(); for (Path path : recentProjects) { int count = path.getNameCount(); int first = count - 3; first = first >= 0 ? first : 0; Path subPath = path.subpath(first, count); MenuItem projectMenuItem = new MenuItem(subPath.toString()); projectMenuItem.setOnAction(e -> loadProject(path)); recentProjectMenuItem.getItems().add(projectMenuItem); } projectMenu.getItems().addAll(projectOpenMenuItem, recentProjectMenuItem, projectSaveMenuItem, projectSaveAsMenuItem); fileMenu.getItems().addAll(openMenuItem, addMenuItem, newMenuItem, recentMenuItem, new SeparatorMenuItem(), pdfMenuItem, svgMenuItem, loadPeakListMenuItem); Menu spectraMenu = new Menu("Spectra"); MenuItem deleteItem = new MenuItem("Delete Spectrum"); deleteItem.setOnAction(e -> FXMLController.getActiveController().removeChart()); MenuItem syncMenuItem = new MenuItem("Sync Axes"); syncMenuItem.setOnAction(e -> PolyChart.activeChart.syncSceneMates()); Menu arrangeMenu = new Menu("Arrange"); MenuItem horizItem = new MenuItem("Horizontal"); horizItem.setOnAction( e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.HORIZONTAL)); MenuItem vertItem = new MenuItem("Vertical"); vertItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.VERTICAL)); MenuItem gridItem = new MenuItem("Grid"); gridItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.GRID)); MenuItem overlayItem = new MenuItem("Overlay"); overlayItem.setOnAction(e -> FXMLController.getActiveController().overlay()); MenuItem minimizeItem = new MenuItem("Minimize Borders"); minimizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(true)); MenuItem normalizeItem = new MenuItem("Normal Borders"); normalizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(false)); arrangeMenu.getItems().addAll(horizItem, vertItem, gridItem, overlayItem, minimizeItem, normalizeItem); MenuItem alignMenuItem = new MenuItem("Align Spectra"); alignMenuItem.setOnAction(e -> FXMLController.getActiveController().alignCenters()); MenuItem analyzeMenuItem = new MenuItem("Analyzer..."); analyzeMenuItem.setOnAction(e -> showAnalyzer(e)); spectraMenu.getItems().addAll(deleteItem, arrangeMenu, syncMenuItem, alignMenuItem, analyzeMenuItem); // Format (items TBD) // Menu formatMenu = new Menu("Format"); // formatMenu.getItems().addAll(new MenuItem("TBD")); // View Menu (items TBD) Menu viewMenu = new Menu("View"); MenuItem dataMenuItem = new MenuItem("Show Datasets"); dataMenuItem.setOnAction(e -> showDatasetsTable(e)); MenuItem consoleMenuItem = new MenuItem("Show Console"); consoleMenuItem.setOnAction(e -> showConsole(e)); MenuItem attrMenuItem = new MenuItem("Show Attributes"); attrMenuItem.setOnAction(e -> FXMLController.getActiveController().showSpecAttrAction(e)); MenuItem procMenuItem = new MenuItem("Show Processor"); procMenuItem.setOnAction(e -> FXMLController.getActiveController().showProcessorAction(e)); MenuItem scannerMenuItem = new MenuItem("Show Scanner"); scannerMenuItem.setOnAction(e -> FXMLController.getActiveController().showScannerAction(e)); viewMenu.getItems().addAll(consoleMenuItem, dataMenuItem, attrMenuItem, procMenuItem, scannerMenuItem); Menu peakMenu = new Menu("Peaks"); MenuItem peakAttrMenuItem = new MenuItem("Show Peak Tool"); peakAttrMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakAttrAction(e)); MenuItem peakNavigatorMenuItem = new MenuItem("Show Peak Navigator"); peakNavigatorMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakNavigator()); MenuItem linkPeakDimsMenuItem = new MenuItem("Link by Labels"); linkPeakDimsMenuItem.setOnAction(e -> FXMLController.getActiveController().linkPeakDims()); MenuItem peakSliderMenuItem = new MenuItem("Show Peak Slider"); peakSliderMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakSlider()); peakMenu.getItems().addAll(peakAttrMenuItem, peakNavigatorMenuItem, linkPeakDimsMenuItem, peakSliderMenuItem); // Window Menu // TBD standard window menu items // Help Menu (items TBD) Menu helpMenu = new Menu("Help"); MenuItem webSiteMenuItem = new MenuItem("NMRFx Web Site"); webSiteMenuItem.setOnAction(e -> showWebSiteAction(e)); MenuItem docsMenuItem = new MenuItem("Online Documentation"); docsMenuItem.setOnAction(e -> showDocAction(e)); MenuItem versionMenuItem = new MenuItem("Check Version"); versionMenuItem.setOnAction(e -> showVersionAction(e)); MenuItem mailingListItem = new MenuItem("Mailing List Site"); mailingListItem.setOnAction(e -> showMailingListAction(e)); MenuItem refMenuItem = new MenuItem("NMRFx Publication"); refMenuItem.setOnAction(e -> { MainApp.hostServices.showDocument("http://link.springer.com/article/10.1007/s10858-016-0049-6"); }); // home // mailing list // helpMenu.getItems().addAll(docsMenuItem, webSiteMenuItem, mailingListItem, versionMenuItem, refMenuItem); if (tk != null) { Menu windowMenu = new Menu("Window"); windowMenu.getItems().addAll(tk.createMinimizeMenuItem(), tk.createZoomMenuItem(), tk.createCycleWindowsItem(), new SeparatorMenuItem(), tk.createBringAllToFrontItem()); menuBar.getMenus().addAll(appMenu, fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, windowMenu, helpMenu); tk.autoAddWindowMenuItems(windowMenu); tk.setGlobalMenuBar(menuBar); } else { fileMenu.getItems().add(prefsItem); fileMenu.getItems().add(quitItem); menuBar.getMenus().addAll(fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, helpMenu); helpMenu.getItems().add(0, aboutItem); } return menuBar; }
From source file:qupath.lib.gui.tma.TMASummaryViewer.java
private void initialize() { model = new TMATableModel(); groupByIDProperty.addListener((v, o, n) -> refreshTableData()); MenuBar menuBar = new MenuBar(); Menu menuFile = new Menu("File"); MenuItem miOpen = new MenuItem("Open..."); miOpen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN)); miOpen.setOnAction(e -> {//from w w w . j a va 2 s . c o m File file = QuPathGUI.getDialogHelper(stage).promptForFile(null, null, "TMA data files", new String[] { "qptma" }); if (file == null) return; setInputFile(file); }); MenuItem miSave = new MenuItem("Save As..."); miSave.setAccelerator( new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miSave.setOnAction( e -> SummaryMeasurementTableCommand.saveTableModel(model, null, Collections.emptyList())); MenuItem miImportFromImage = new MenuItem("Import from current image..."); miImportFromImage.setAccelerator( new KeyCodeCombination(KeyCode.I, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miImportFromImage.setOnAction(e -> setTMAEntriesFromOpenImage()); MenuItem miImportFromProject = new MenuItem("Import from current project... (experimental)"); miImportFromProject.setAccelerator( new KeyCodeCombination(KeyCode.P, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miImportFromProject.setOnAction(e -> setTMAEntriesFromOpenProject()); MenuItem miImportClipboard = new MenuItem("Import from clipboard..."); miImportClipboard.setOnAction(e -> { String text = Clipboard.getSystemClipboard().getString(); if (text == null) { DisplayHelpers.showErrorMessage("Import scores", "Clipboard is empty!"); return; } int n = importScores(text); if (n > 0) { setTMAEntries(new ArrayList<>(entriesBase)); } DisplayHelpers.showMessageDialog("Import scores", "Number of scores imported: " + n); }); Menu menuEdit = new Menu("Edit"); MenuItem miCopy = new MenuItem("Copy table to clipboard"); miCopy.setOnAction(e -> { SummaryMeasurementTableCommand.copyTableContentsToClipboard(model, Collections.emptyList()); }); combinedPredicate.addListener((v, o, n) -> { // We want any other changes triggered by this to have happened, // so that the data has already been updated Platform.runLater(() -> handleTableContentChange()); }); // Reset the scores for missing cores - this ensures they will be NaN and not influence subsequent results MenuItem miResetMissingScores = new MenuItem("Reset scores for missing cores"); miResetMissingScores.setOnAction(e -> { int changes = 0; for (TMAEntry entry : entriesBase) { if (!entry.isMissing()) continue; boolean changed = false; for (String m : entry.getMeasurementNames().toArray(new String[0])) { if (!TMASummaryEntry.isSurvivalColumn(m) && !Double.isNaN(entry.getMeasurementAsDouble(m))) { entry.putMeasurement(m, null); changed = true; } } if (changed) changes++; } if (changes == 0) { logger.info("No changes made when resetting scores for missing cores!"); return; } logger.info("{} change(s) made when resetting scores for missing cores!", changes); table.refresh(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); if (histogramDisplay != null) histogramDisplay.refreshHistogram(); }); menuEdit.getItems().add(miResetMissingScores); QuPathGUI.addMenuItems(menuFile, miOpen, miSave, null, miImportClipboard, null, miImportFromImage, miImportFromProject); menuBar.getMenus().add(menuFile); menuEdit.getItems().add(miCopy); menuBar.getMenus().add(menuEdit); menuFile.setOnShowing(e -> { boolean imageDataAvailable = QuPathGUI.getInstance() != null && QuPathGUI.getInstance().getImageData() != null && QuPathGUI.getInstance().getImageData().getHierarchy().getTMAGrid() != null; miImportFromImage.setDisable(!imageDataAvailable); boolean projectAvailable = QuPathGUI.getInstance() != null && QuPathGUI.getInstance().getProject() != null && !QuPathGUI.getInstance().getProject().getImageList().isEmpty(); miImportFromProject.setDisable(!projectAvailable); }); // Double-clicking previously used for comments... but conflicts with tree table expansion // table.setOnMouseClicked(e -> { // if (!e.isPopupTrigger() && e.getClickCount() > 1) // promptForComment(); // }); table.setPlaceholder(new Text("Drag TMA data folder onto window, or choose File -> Open")); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); BorderPane pane = new BorderPane(); pane.setTop(menuBar); menuBar.setUseSystemMenuBar(true); // Create options ToolBar toolbar = new ToolBar(); Label labelMeasurementMethod = new Label("Combination method"); labelMeasurementMethod.setLabelFor(comboMeasurementMethod); labelMeasurementMethod .setTooltip(new Tooltip("Method whereby measurements for multiple cores with the same " + TMACoreObject.KEY_UNIQUE_ID + " will be combined")); CheckBox cbHidePane = new CheckBox("Hide pane"); cbHidePane.setSelected(hidePaneProperty.get()); cbHidePane.selectedProperty().bindBidirectional(hidePaneProperty); CheckBox cbGroupByID = new CheckBox("Group by ID"); entriesBase.addListener((Change<? extends TMAEntry> event) -> { if (!event.getList().stream().anyMatch(e -> e.getMetadataValue(TMACoreObject.KEY_UNIQUE_ID) != null)) { cbGroupByID.setSelected(false); cbGroupByID.setDisable(true); } else { cbGroupByID.setDisable(false); } }); cbGroupByID.setSelected(groupByIDProperty.get()); cbGroupByID.selectedProperty().bindBidirectional(groupByIDProperty); CheckBox cbUseSelected = new CheckBox("Use selection only"); cbUseSelected.selectedProperty().bindBidirectional(useSelectedProperty); CheckBox cbSkipMissing = new CheckBox("Hide missing cores"); cbSkipMissing.selectedProperty().bindBidirectional(skipMissingCoresProperty); skipMissingCoresProperty.addListener((v, o, n) -> { table.refresh(); updateSurvivalCurves(); if (histogramDisplay != null) histogramDisplay.refreshHistogram(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); }); toolbar.getItems().addAll(labelMeasurementMethod, comboMeasurementMethod, new Separator(Orientation.VERTICAL), cbHidePane, new Separator(Orientation.VERTICAL), cbGroupByID, new Separator(Orientation.VERTICAL), cbUseSelected, new Separator(Orientation.VERTICAL), cbSkipMissing); comboMeasurementMethod.getItems().addAll(MeasurementCombinationMethod.values()); comboMeasurementMethod.getSelectionModel().select(MeasurementCombinationMethod.MEDIAN); selectedMeasurementCombinationProperty.addListener((v, o, n) -> table.refresh()); ContextMenu popup = new ContextMenu(); MenuItem miSetMissing = new MenuItem("Set missing"); miSetMissing.setOnAction(e -> setSelectedMissingStatus(true)); MenuItem miSetAvailable = new MenuItem("Set available"); miSetAvailable.setOnAction(e -> setSelectedMissingStatus(false)); MenuItem miExpand = new MenuItem("Expand all"); miExpand.setOnAction(e -> { if (table.getRoot() == null) return; for (TreeItem<?> item : table.getRoot().getChildren()) { item.setExpanded(true); } }); MenuItem miCollapse = new MenuItem("Collapse all"); miCollapse.setOnAction(e -> { if (table.getRoot() == null) return; for (TreeItem<?> item : table.getRoot().getChildren()) { item.setExpanded(false); } }); popup.getItems().addAll(miSetMissing, miSetAvailable, new SeparatorMenuItem(), miExpand, miCollapse); table.setContextMenu(popup); table.setRowFactory(e -> { TreeTableRow<TMAEntry> row = new TreeTableRow<>(); // // Make rows invisible if they don't pass the predicate // row.visibleProperty().bind(Bindings.createBooleanBinding(() -> { // TMAEntry entry = row.getItem(); // if (entry == null || (entry.isMissing() && skipMissingCoresProperty.get())) // return false; // return entries.getPredicate() == null || entries.getPredicate().test(entry); // }, // skipMissingCoresProperty, // entries.predicateProperty())); // Style rows according to what they contain row.styleProperty().bind(Bindings.createStringBinding(() -> { if (row.isSelected()) return ""; TMAEntry entry = row.getItem(); if (entry == null || entry instanceof TMASummaryEntry) return ""; else if (entry.isMissing()) return "-fx-background-color:rgb(225,225,232)"; else return "-fx-background-color:rgb(240,240,245)"; }, row.itemProperty(), row.selectedProperty())); // row.itemProperty().addListener((v, o, n) -> { // if (n == null || n instanceof TMASummaryEntry || row.isSelected()) // row.setStyle(""); // else if (n.isMissing()) // row.setStyle("-fx-background-color:rgb(225,225,232)"); // else // row.setStyle("-fx-background-color:rgb(240,240,245)"); // }); return row; }); BorderPane paneTable = new BorderPane(); paneTable.setTop(toolbar); paneTable.setCenter(table); MasterDetailPane mdTablePane = new MasterDetailPane(Side.RIGHT, paneTable, createSidePane(), true); mdTablePane.showDetailNodeProperty().bind(Bindings.createBooleanBinding( () -> !hidePaneProperty.get() && !entriesBase.isEmpty(), hidePaneProperty, entriesBase)); mdTablePane.setDividerPosition(2.0 / 3.0); pane.setCenter(mdTablePane); model.getEntries().addListener(new ListChangeListener<TMAEntry>() { @Override public void onChanged(ListChangeListener.Change<? extends TMAEntry> c) { if (histogramDisplay != null) histogramDisplay.refreshHistogram(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); } }); Label labelPredicate = new Label(); labelPredicate.setPadding(new Insets(5, 5, 5, 5)); labelPredicate.setAlignment(Pos.CENTER); // labelPredicate.setStyle("-fx-background-color: rgba(20, 120, 20, 0.15);"); labelPredicate.setStyle("-fx-background-color: rgba(120, 20, 20, 0.15);"); labelPredicate.textProperty().addListener((v, o, n) -> { if (n.trim().length() > 0) pane.setBottom(labelPredicate); else pane.setBottom(null); }); labelPredicate.setMaxWidth(Double.MAX_VALUE); labelPredicate.setMaxHeight(labelPredicate.getPrefHeight()); labelPredicate.setTextAlignment(TextAlignment.CENTER); predicateMeasurements.addListener((v, o, n) -> { if (n == null) labelPredicate.setText(""); else if (n instanceof TablePredicate) { TablePredicate tp = (TablePredicate) n; if (tp.getOriginalCommand().trim().isEmpty()) labelPredicate.setText(""); else labelPredicate.setText("Predicate: " + tp.getOriginalCommand()); } else labelPredicate.setText("Predicate: " + n.toString()); }); // predicate.set(new TablePredicate("\"Tumor\" > 100")); scene = new Scene(pane); scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> { KeyCode code = e.getCode(); if ((code == KeyCode.SPACE || code == KeyCode.ENTER) && entrySelected != null) { promptForComment(); return; } }); }
From source file:be.makercafe.apps.makerbench.Main.java
/** * Creates the menubar/*from w w w. j ava2 s . c o m*/ * * @return */ private MenuBar createMenuBar() { MenuBar bar = new MenuBar(); Menu projectMenu = new Menu("Project"); MenuItem openProject = new MenuItem("Open..."); openProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { directoryChooser.setTitle("Please choose a project folder"); File file = directoryChooser.showDialog(stage); viewer.setRoot(setRootFolder(file)); } }); Menu newProject = new Menu("New"); MenuItem newFolder = new MenuItem("Folder..."); newFolder.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TextInputDialog dialog = new TextInputDialog("my_project_folder"); dialog.setTitle("New folder"); dialog.setHeaderText("Create a new folder"); dialog.setContentText("Folder name:"); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { String homeDir = System.getProperty("user.home"); System.out.println("Folder name: " + result.get()); System.out.println("User home: " + homeDir); } } }); newProject.getItems().add(newFolder); MenuItem importProject = new MenuItem("Import"); importProject.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.CONTROL_DOWN)); importProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Import"); } }); MenuItem deleteProject = new MenuItem("Delete"); deleteProject.setAccelerator(new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN)); deleteProject.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Delete"); } }); projectMenu.getItems().addAll(openProject, newProject, importProject, deleteProject); Menu helpMenu = new Menu("Help"); MenuItem aboutItem = new MenuItem("About"); aboutItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Information Dialog"); alert.setHeaderText("About makerbench"); alert.setContentText( "Makerbench is an open source IDE for designing and manufacturing objects and code.\nWritten by Luc De pauw\n\nUses opensource libraries from the next projects:\n-RichtextFX by Tomas Mikula\n-JCSG by Michael Hoffer\n-ControlsFX by FXexperience.com"); alert.showAndWait(); } }); helpMenu.getItems().add(aboutItem); bar.getMenus().addAll(projectMenu, helpMenu); return bar; }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param primaryStage/*w w w .j a v a 2s . c o m*/ * @param racine * @param taille * @throws Exception */ private void creeMenu(VBox racine, int taille) throws Exception { //Pane myPane = (Pane) FXMLLoader.load(getClass().getResource("menuPrincipal.fxml")); VBox myPane = new VBox(); myPane.setPrefHeight(80); myPane.setPrefWidth(3000); MenuBar menuPrincipal = new MenuBar(); menuPrincipal.setMinHeight(25); menuPrincipal.setPrefHeight(29); menuPrincipal.setPrefWidth(3000); /* Menu projets */ Menu menuProjet = new Menu(rb.getString("projets")); menuPrincipal.getMenus().add(menuProjet); nouveauProjet = new MenuItem(rb.getString("nouveauProjet")); nouveauProjet.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); menuProjet.getItems().add(nouveauProjet); chargeProjet = new MenuItem(rb.getString("ouvrirProjet")); chargeProjet.setAccelerator(KeyCombination.keyCombination("Ctrl+O")); menuProjet.getItems().add(chargeProjet); sauveProjet = new MenuItem(rb.getString("sauverProjet")); sauveProjet.setDisable(true); sauveProjet.setAccelerator(KeyCombination.keyCombination("Ctrl+S")); menuProjet.getItems().add(sauveProjet); sauveSousProjet = new MenuItem(rb.getString("sauverProjetSous")); sauveSousProjet.setDisable(true); sauveSousProjet.setAccelerator(KeyCombination.keyCombination("Shift+Ctrl+S")); menuProjet.getItems().add(sauveSousProjet); derniersProjets = new Menu(rb.getString("derniersProjets")); // derniersProjets.setDisable(true); menuProjet.getItems().add(derniersProjets); fichHistoFichiers = new File(repertConfig.getAbsolutePath() + File.separator + "derniersprojets.cfg"); nombreHistoFichiers = 0; if (fichHistoFichiers.exists()) { FileReader fr; fr = new FileReader(fichHistoFichiers); try (BufferedReader br = new BufferedReader(fr)) { while ((texteHisto = br.readLine()) != null) { MenuItem menuDerniersFichiers = new MenuItem(texteHisto); derniersProjets.getItems().add(menuDerniersFichiers); histoFichiers[nombreHistoFichiers] = texteHisto; nombreHistoFichiers++; menuDerniersFichiers.setOnAction((ActionEvent e) -> { MenuItem mnu = (MenuItem) e.getSource(); try { try { projetChargeNom(mnu.getText()); } catch (InterruptedException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); } } } SeparatorMenuItem sep1 = new SeparatorMenuItem(); menuProjet.getItems().add(sep1); fermerProjet = new MenuItem(rb.getString("quitterApplication")); fermerProjet.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); menuProjet.getItems().add(fermerProjet); /* Menu affichage */ Menu menuAffichage = new Menu(rb.getString("affichage")); menuPrincipal.getMenus().add(menuAffichage); affichageVisite = new MenuItem(rb.getString("main.creationVisite")); affichageVisite.setAccelerator(KeyCombination.keyCombination("Ctrl+1")); menuAffichage.getItems().add(affichageVisite); affichageInterface = new MenuItem(rb.getString("main.creationInterface")); affichageInterface.setAccelerator(KeyCombination.keyCombination("Ctrl+2")); menuAffichage.getItems().add(affichageInterface); affichagePlan = new MenuItem(rb.getString("main.tabPlan")); affichagePlan.setAccelerator(KeyCombination.keyCombination("Ctrl+3")); affichagePlan.setDisable(true); menuAffichage.getItems().add(affichagePlan); SeparatorMenuItem sep3 = new SeparatorMenuItem(); menuAffichage.getItems().add(sep3); configTransformation = new MenuItem(rb.getString("affichageConfiguration")); menuAffichage.getItems().add(configTransformation); /* Menu panoramiques */ menuPanoramique = new Menu(rb.getString("panoramiques")); menuPanoramique.setDisable(true); menuPrincipal.getMenus().add(menuPanoramique); ajouterPano = new MenuItem(rb.getString("ajouterPanoramiques")); ajouterPano.setAccelerator(KeyCombination.keyCombination("Ctrl+A")); menuPanoramique.getItems().add(ajouterPano); ajouterPlan = new MenuItem(rb.getString("ajouterPlan")); ajouterPlan.setAccelerator(KeyCombination.keyCombination("Ctrl+P")); menuPanoramique.getItems().add(ajouterPlan); ajouterPlan.setDisable(true); SeparatorMenuItem sep2 = new SeparatorMenuItem(); menuPanoramique.getItems().add(sep2); visiteGenere = new MenuItem(rb.getString("genererVisite")); visiteGenere.setDisable(true); visiteGenere.setAccelerator(KeyCombination.keyCombination("Ctrl+V")); menuPanoramique.getItems().add(visiteGenere); /* Menu Modles */ menuModeles = new Menu(rb.getString("menuModele")); menuPrincipal.getMenus().add(menuModeles); chargerModele = new MenuItem(rb.getString("modeleCharger")); menuModeles.getItems().add(chargerModele); sauverModele = new MenuItem(rb.getString("modeleSauver")); menuModeles.getItems().add(sauverModele); /* Menu transformations */ menuTransformation = new Menu(rb.getString("outils")); menuPrincipal.getMenus().add(menuTransformation); equi2CubeTransformation = new MenuItem(rb.getString("outilsEqui2Cube")); menuTransformation.getItems().add(equi2CubeTransformation); cube2EquiTransformation = new MenuItem(rb.getString("outilsCube2Equi")); menuTransformation.getItems().add(cube2EquiTransformation); /* Menu Aide */ Menu menuAide = new Menu(rb.getString("aide")); menuPrincipal.getMenus().add(menuAide); aide = new MenuItem(rb.getString("aideAide")); aide.setAccelerator(KeyCombination.keyCombination("Ctrl+H")); menuAide.getItems().add(aide); SeparatorMenuItem sep4 = new SeparatorMenuItem(); menuAide.getItems().add(sep4); aPropos = new MenuItem(rb.getString("aideAPropos")); menuAide.getItems().add(aPropos); /* barre de boutons */ HBox barreBouton = new HBox(); barreBouton.getStyleClass().add("menuBarreOutils1"); barreBouton.setPrefHeight(50); barreBouton.setMinHeight(50); barreBouton.setPrefWidth(3000); /* Bouton nouveau Projet */ ScrollPane spBtnNouvprojet = new ScrollPane(); spBtnNouvprojet.getStyleClass().add("menuBarreOutils"); spBtnNouvprojet.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnNouvprojet.setPrefHeight(35); spBtnNouvprojet.setMaxHeight(35); spBtnNouvprojet.setPadding(new Insets(2)); spBtnNouvprojet.setPrefWidth(35); HBox.setMargin(spBtnNouvprojet, new Insets(5, 15, 0, 15)); imgNouveauProjet = new ImageView( new Image("file:" + repertAppli + File.separator + "images/nouveauProjet.png")); spBtnNouvprojet.setContent(imgNouveauProjet); Tooltip t0 = new Tooltip(rb.getString("nouveauProjet")); t0.setStyle(tooltipStyle); spBtnNouvprojet.setTooltip(t0); barreBouton.getChildren().add(spBtnNouvprojet); /* Bouton ouvrir Projet */ ScrollPane spBtnOuvrirProjet = new ScrollPane(); spBtnOuvrirProjet.getStyleClass().add("menuBarreOutils"); spBtnOuvrirProjet.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnOuvrirProjet.setPrefHeight(35); spBtnOuvrirProjet.setMaxHeight(35); spBtnOuvrirProjet.setPadding(new Insets(2)); spBtnOuvrirProjet.setPrefWidth(35); HBox.setMargin(spBtnOuvrirProjet, new Insets(5, 15, 0, 0)); imgChargeProjet = new ImageView( new Image("file:" + repertAppli + File.separator + "images/ouvrirProjet.png")); spBtnOuvrirProjet.setContent(imgChargeProjet); Tooltip t1 = new Tooltip(rb.getString("ouvrirProjet")); t1.setStyle(tooltipStyle); spBtnOuvrirProjet.setTooltip(t1); barreBouton.getChildren().add(spBtnOuvrirProjet); /* Bouton sauve Projet */ ScrollPane spBtnSauveProjet = new ScrollPane(); spBtnSauveProjet.getStyleClass().add("menuBarreOutils"); spBtnSauveProjet.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnSauveProjet.setPrefHeight(35); spBtnSauveProjet.setMaxHeight(35); spBtnSauveProjet.setPadding(new Insets(2)); spBtnSauveProjet.setPrefWidth(35); HBox.setMargin(spBtnSauveProjet, new Insets(5, 15, 0, 0)); imgSauveProjet = new ImageView( new Image("file:" + repertAppli + File.separator + "images/sauveProjet.png")); spBtnSauveProjet.setContent(imgSauveProjet); Tooltip t2 = new Tooltip(rb.getString("sauverProjet")); t2.setStyle(tooltipStyle); spBtnSauveProjet.setTooltip(t2); barreBouton.getChildren().add(spBtnSauveProjet); Separator sepImages = new Separator(Orientation.VERTICAL); sepImages.prefHeight(200); barreBouton.getChildren().add(sepImages); imgSauveProjet.setDisable(true); imgSauveProjet.setOpacity(0.3); /* Bouton Ajoute Panoramique */ ScrollPane spBtnAjoutePano = new ScrollPane(); spBtnAjoutePano.getStyleClass().add("menuBarreOutils"); spBtnAjoutePano.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnAjoutePano.setPrefHeight(35); spBtnAjoutePano.setMaxHeight(35); spBtnAjoutePano.setPadding(new Insets(2)); spBtnAjoutePano.setPrefWidth(35); HBox.setMargin(spBtnAjoutePano, new Insets(5, 15, 0, 15)); imgAjouterPano = new ImageView( new Image("file:" + repertAppli + File.separator + "images/ajoutePanoramique.png")); spBtnAjoutePano.setContent(imgAjouterPano); Tooltip t3 = new Tooltip(rb.getString("ajouterPanoramiques")); t3.setStyle(tooltipStyle); spBtnAjoutePano.setTooltip(t3); barreBouton.getChildren().add(spBtnAjoutePano); imgAjouterPano.setDisable(true); imgAjouterPano.setOpacity(0.3); /* Bouton Ajoute Panoramique */ ScrollPane spBtnAjoutePlan = new ScrollPane(); spBtnAjoutePlan.getStyleClass().add("menuBarreOutils"); spBtnAjoutePlan.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnAjoutePlan.setPrefHeight(35); spBtnAjoutePlan.setMaxHeight(35); spBtnAjoutePlan.setPadding(new Insets(2)); spBtnAjoutePlan.setPrefWidth(35); HBox.setMargin(spBtnAjoutePlan, new Insets(5, 15, 0, 15)); imgAjouterPlan = new ImageView(new Image("file:" + repertAppli + File.separator + "images/ajoutePlan.png")); spBtnAjoutePlan.setContent(imgAjouterPlan); Tooltip t31 = new Tooltip(rb.getString("ajouterPlan")); t31.setStyle(tooltipStyle); spBtnAjoutePlan.setTooltip(t31); barreBouton.getChildren().add(spBtnAjoutePlan); imgAjouterPlan.setDisable(true); imgAjouterPlan.setOpacity(0.3); /* Bouton Gnre */ ScrollPane spBtnGenereVisite = new ScrollPane(); spBtnGenereVisite.getStyleClass().add("menuBarreOutils"); spBtnGenereVisite.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnGenereVisite.setPrefHeight(35); spBtnGenereVisite.setMaxHeight(35); spBtnGenereVisite.setPadding(new Insets(2)); spBtnGenereVisite.setPrefWidth(70); HBox.setMargin(spBtnGenereVisite, new Insets(5, 15, 0, 0)); imgVisiteGenere = new ImageView( new Image("file:" + repertAppli + File.separator + "images/genereVisite.png")); spBtnGenereVisite.setContent(imgVisiteGenere); Tooltip t4 = new Tooltip(rb.getString("genererVisite")); t4.setStyle(tooltipStyle); spBtnGenereVisite.setTooltip(t4); barreBouton.getChildren().add(spBtnGenereVisite); imgVisiteGenere.setDisable(true); imgVisiteGenere.setOpacity(0.3); Separator sepImages1 = new Separator(Orientation.VERTICAL); sepImages1.prefHeight(200); barreBouton.getChildren().add(sepImages1); /* Bouton equi -> faces de Cube */ ScrollPane spBtnEqui2Cube = new ScrollPane(); spBtnEqui2Cube.getStyleClass().add("menuBarreOutils"); spBtnEqui2Cube.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnEqui2Cube.setPrefHeight(35); spBtnEqui2Cube.setMaxHeight(35); spBtnEqui2Cube.setPadding(new Insets(2)); spBtnEqui2Cube.setPrefWidth(109); HBox.setMargin(spBtnEqui2Cube, new Insets(5, 15, 0, 250)); imgEqui2Cube = new ImageView(new Image("file:" + repertAppli + File.separator + "images/equi2cube.png")); spBtnEqui2Cube.setContent(imgEqui2Cube); Tooltip t6 = new Tooltip(rb.getString("outilsEqui2Cube")); t6.setStyle(tooltipStyle); spBtnEqui2Cube.setTooltip(t6); barreBouton.getChildren().add(spBtnEqui2Cube); /* Bouton faces de cube -> equi */ ScrollPane spBtnCube2Equi = new ScrollPane(); spBtnCube2Equi.getStyleClass().add("menuBarreOutils"); spBtnCube2Equi.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); spBtnCube2Equi.setPrefHeight(35); spBtnCube2Equi.setMaxHeight(35); spBtnCube2Equi.setPadding(new Insets(2)); spBtnCube2Equi.setPrefWidth(109); HBox.setMargin(spBtnCube2Equi, new Insets(5, 25, 0, 0)); imgCube2Equi = new ImageView(new Image("file:" + repertAppli + File.separator + "images/cube2equi.png")); spBtnCube2Equi.setContent(imgCube2Equi); Tooltip t5 = new Tooltip(rb.getString("outilsCube2Equi")); t5.setStyle(tooltipStyle); spBtnCube2Equi.setTooltip(t5); barreBouton.getChildren().add(spBtnCube2Equi); myPane.getChildren().addAll(menuPrincipal, barreBouton); racine.getChildren().add(myPane); nouveauProjet.setOnAction((ActionEvent e) -> { projetsNouveau(); }); chargeProjet.setOnAction((ActionEvent e) -> { try { try { projetCharge(); } catch (InterruptedException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); sauveProjet.setOnAction((ActionEvent e) -> { try { projetSauve(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); sauveSousProjet.setOnAction((ActionEvent e) -> { try { projetSauveSous(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); visiteGenere.setOnAction((ActionEvent e) -> { try { genereVisite(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); fermerProjet.setOnAction((ActionEvent e) -> { try { projetsFermer(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); ajouterPano.setOnAction((ActionEvent e) -> { try { panoramiquesAjouter(); } catch (InterruptedException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); ajouterPlan.setOnAction((ActionEvent e) -> { planAjouter(); }); aPropos.setOnAction((ActionEvent e) -> { aideapropos(); }); aide.setOnAction((ActionEvent e) -> { AideDialogController.affiche(); }); chargerModele.setOnAction((ActionEvent e) -> { try { modeleCharger(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); sauverModele.setOnAction((ActionEvent e) -> { try { modeleSauver(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); cube2EquiTransformation.setOnAction((ActionEvent e) -> { transformationCube2Equi(); }); equi2CubeTransformation.setOnAction((ActionEvent e) -> { transformationEqui2Cube(); }); affichageVisite.setOnAction((ActionEvent e) -> { tabPaneEnvironnement.getSelectionModel().select(0); }); affichageInterface.setOnAction((ActionEvent e) -> { tabPaneEnvironnement.getSelectionModel().select(1); }); affichagePlan.setOnAction((ActionEvent e) -> { if (!tabPlan.isDisabled()) { tabPaneEnvironnement.getSelectionModel().select(2); } }); configTransformation.setOnAction((ActionEvent e) -> { try { ConfigDialogController cfg = new ConfigDialogController(); cfg.afficheFenetre(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); spBtnNouvprojet.setOnMouseClicked((MouseEvent t) -> { projetsNouveau(); }); spBtnOuvrirProjet.setOnMouseClicked((MouseEvent t) -> { try { try { projetCharge(); } catch (InterruptedException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); spBtnSauveProjet.setOnMouseClicked((MouseEvent t) -> { try { projetSauve(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); spBtnAjoutePano.setOnMouseClicked((MouseEvent t) -> { try { panoramiquesAjouter(); } catch (InterruptedException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); spBtnAjoutePlan.setOnMouseClicked((MouseEvent t) -> { planAjouter(); }); spBtnGenereVisite.setOnMouseClicked((MouseEvent t) -> { try { genereVisite(); } catch (IOException ex) { Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex); } }); spBtnEqui2Cube.setOnMouseClicked((MouseEvent t) -> { transformationEqui2Cube(); }); spBtnCube2Equi.setOnMouseClicked((MouseEvent t) -> { transformationCube2Equi(); }); }