List of usage examples for javafx.scene.control CustomMenuItem setOnAction
public final void setOnAction(EventHandler<ActionEvent> value)
From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java
private void updateRecentFilesMenu() { List<MenuItem> items = new ArrayList<>(); List<File> filesToClear = new ArrayList<>(); for (final File f : recentFiles) { if (f.exists() && f.isFile()) { CustomMenuItem item = new CustomMenuItem(new Label(f.getName())); item.setOnAction(e -> loadSourceFromFile(f)); item.setMnemonicParsing(false); Tooltip.install(item.getContent(), new Tooltip(f.getAbsolutePath())); items.add(item);//from w w w . ja va2 s . c o m } else { filesToClear.add(f); } } recentFiles.removeAll(filesToClear); if (items.isEmpty()) { openRecentMenu.setDisable(true); return; } Collections.reverse(items); items.add(new SeparatorMenuItem()); MenuItem clearItem = new MenuItem(); clearItem.setText("Clear menu"); clearItem.setOnAction(e -> { recentFiles.clear(); openRecentMenu.setDisable(true); }); items.add(clearItem); openRecentMenu.getItems().setAll(items); }
From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java
private void autoComplete(int slashPosition, String input, ContextMenu autoCompletePopup) { XPathSuggestions xPathSuggestions = new XPathSuggestions(parent.getLanguageVersion().getLanguage()); List<String> suggestions = xPathSuggestions.getXPathSuggestions(input.trim()); List<CustomMenuItem> resultToDisplay = new ArrayList<>(); if (!suggestions.isEmpty()) { for (int i = 0; i < suggestions.size() && i < 5; i++) { final String searchResult = suggestions.get(i); Label entryLabel = new Label(); entryLabel.setGraphic(highlightXPathSuggestion(suggestions.get(i), input)); entryLabel.setPrefHeight(5); CustomMenuItem item = new CustomMenuItem(entryLabel, true); resultToDisplay.add(item);/*from w w w. j av a 2 s . c om*/ item.setOnAction(e -> { xpathExpressionArea.replaceText(slashPosition, slashPosition + input.length(), searchResult); autoCompletePopup.hide(); }); } } autoCompletePopup.getItems().setAll(resultToDisplay); xpathExpressionArea.getCharacterBoundsOnScreen(slashPosition, slashPosition + input.length()).ifPresent( bounds -> autoCompletePopup.show(xpathExpressionArea, bounds.getMinX(), bounds.getMaxY())); }