Search in sources :

Example 1 with CustomMenuItem

use of javafx.scene.control.CustomMenuItem in project pmd by pmd.

the class MainDesignerController method updateRecentFilesMenu.

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);
        } 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);
}
Also used : Tooltip(javafx.scene.control.Tooltip) ArrayList(java.util.ArrayList) Label(javafx.scene.control.Label) CustomMenuItem(javafx.scene.control.CustomMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) CustomMenuItem(javafx.scene.control.CustomMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) File(java.io.File)

Example 2 with CustomMenuItem

use of javafx.scene.control.CustomMenuItem in project org.csstudio.display.builder by kasemir.

the class AutocompleteMenu method createHeaderItem.

private final CustomMenuItem createHeaderItem(final String header) {
    final CustomMenuItem item = new CustomMenuItem(new Text(header), false);
    item.getStyleClass().add("ac-menu-label");
    item.setHideOnClick(false);
    item.setMnemonicParsing(false);
    return item;
}
Also used : Text(javafx.scene.text.Text) CustomMenuItem(javafx.scene.control.CustomMenuItem)

Aggregations

CustomMenuItem (javafx.scene.control.CustomMenuItem)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Label (javafx.scene.control.Label)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 Tooltip (javafx.scene.control.Tooltip)1 Text (javafx.scene.text.Text)1