Search in sources :

Example 91 with MenuItem

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

the class DisplayEditor method createMenuItem.

private MenuItem createMenuItem(final ActionDescription action) {
    final MenuItem item = new MenuItem();
    try {
        item.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource(action.getIconResourcePath()))));
    } catch (final Exception ex) {
        logger.log(Level.WARNING, "Cannot load action icon", ex);
    }
    item.setText(action.getToolTip());
    item.setOnAction(event -> action.run(this));
    return item;
}
Also used : MenuItem(javafx.scene.control.MenuItem) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 92 with MenuItem

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

the class ScriptsDialog method createScriptsTable.

/**
 * @return Node for UI elements that edit the scripts
 */
private Region createScriptsTable() {
    scripts_icon_col = new TableColumn<>();
    scripts_icon_col.setCellValueFactory(cdf -> new SimpleObjectProperty<ImageView>(getScriptImage(cdf.getValue())) {

        {
            bind(Bindings.createObjectBinding(() -> getScriptImage(cdf.getValue()), cdf.getValue().fileProperty()));
        }
    });
    scripts_icon_col.setCellFactory(col -> new TableCell<ScriptItem, ImageView>() {

        /* Instance initializer. */
        {
            setAlignment(Pos.CENTER_LEFT);
        }

        @Override
        protected void updateItem(final ImageView item, final boolean empty) {
            super.updateItem(item, empty);
            super.setGraphic(item);
        }
    });
    scripts_icon_col.setEditable(false);
    scripts_icon_col.setSortable(false);
    scripts_icon_col.setMaxWidth(25);
    scripts_icon_col.setMinWidth(25);
    // Create table with editable script 'file' column
    scripts_name_col = new TableColumn<>(Messages.ScriptsDialog_ColScript);
    scripts_name_col.setCellValueFactory(new PropertyValueFactory<ScriptItem, String>("file"));
    scripts_name_col.setCellFactory(col -> new TextFieldTableCell<ScriptItem, String>(new DefaultStringConverter()) {

        private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
            if (!n)
                cancelEdit();
        };

        @Override
        public void cancelEdit() {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.cancelEdit();
        }

        @Override
        public void startEdit() {
            super.startEdit();
            ((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
        }

        @Override
        public void commitEdit(final String newValue) {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.commitEdit(newValue);
            Platform.runLater(() -> btn_pv_add.requestFocus());
        }
    });
    scripts_name_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        script_items.get(row).file.set(event.getNewValue());
        fixupScripts(row);
    });
    scripts_table = new TableView<>(script_items);
    scripts_table.getColumns().add(scripts_icon_col);
    scripts_table.getColumns().add(scripts_name_col);
    scripts_table.setEditable(true);
    scripts_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    scripts_table.setTooltip(new Tooltip(Messages.ScriptsDialog_ScriptsTT));
    scripts_table.setPlaceholder(new Label(Messages.ScriptsDialog_NoScripts));
    // Buttons
    addMenuButton = new MenuButton(Messages.Add, JFXUtil.getIcon("add.png"), new MenuItem(Messages.AddPythonFile, JFXUtil.getIcon("file-python.png")) {

        {
            setOnAction(e -> addPythonFile());
        }
    }, new MenuItem(Messages.AddJavaScriptFile, JFXUtil.getIcon("file-javascript.png")) {

        {
            setOnAction(e -> addJavaScriptFile());
        }
    }, new SeparatorMenuItem(), new MenuItem(Messages.AddEmbeddedPython, JFXUtil.getIcon("python.png")) {

        {
            setOnAction(e -> addEmbeddedJython());
        }
    }, new MenuItem(Messages.AddEmbeddedJavaScript, JFXUtil.getIcon("javascript.png")) {

        {
            setOnAction(e -> addEmbeddedJavaScript());
        }
    });
    addMenuButton.setMaxWidth(Double.MAX_VALUE);
    addMenuButton.setAlignment(Pos.CENTER_LEFT);
    btn_script_remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    btn_script_remove.setMaxWidth(Double.MAX_VALUE);
    btn_script_remove.setAlignment(Pos.CENTER_LEFT);
    btn_script_remove.setDisable(true);
    btn_script_remove.setOnAction(event -> {
        final int sel = scripts_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            script_items.remove(sel);
            fixupScripts(sel);
        }
    });
    btn_edit = new SplitMenuButton(convertToFileMenuItem, new SeparatorMenuItem(), convertToEmbeddedPythonMenuItem, convertToEmbeddedJavaScriptMenuItem);
    btn_edit.setText(Messages.Select);
    btn_edit.setGraphic(JFXUtil.getIcon("select-file.png"));
    btn_edit.setMaxWidth(Double.MAX_VALUE);
    btn_edit.setMinWidth(120);
    btn_edit.setAlignment(Pos.CENTER_LEFT);
    btn_edit.setDisable(true);
    btn_edit.setOnAction(e -> editOrSelect());
    final VBox buttons = new VBox(10, addMenuButton, btn_script_remove, btn_edit);
    final HBox content = new HBox(10, scripts_table, buttons);
    HBox.setHgrow(scripts_table, Priority.ALWAYS);
    HBox.setHgrow(buttons, Priority.NEVER);
    return content;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) HBox(javafx.scene.layout.HBox) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Priority(javafx.scene.layout.Priority) List(java.util.List) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) MenuButton(javafx.scene.control.MenuButton) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) StringProperty(javafx.beans.property.StringProperty) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) SplitMenuButton(javafx.scene.control.SplitMenuButton) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) HBox(javafx.scene.layout.HBox) SplitMenuButton(javafx.scene.control.SplitMenuButton) Label(javafx.scene.control.Label) MenuButton(javafx.scene.control.MenuButton) SplitMenuButton(javafx.scene.control.SplitMenuButton) Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) SplitMenuButton(javafx.scene.control.SplitMenuButton) TextField(javafx.scene.control.TextField) ImageView(javafx.scene.image.ImageView) Tooltip(javafx.scene.control.Tooltip) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) VBox(javafx.scene.layout.VBox)

Example 93 with MenuItem

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

the class AutocompleteMenu method createMenuItem.

private final MenuItem createMenuItem(final String text) {
    final MenuItem item = new MenuItem(text);
    item.setOnAction((event) -> {
        if (current_field == null)
            return;
        current_field.setText(text);
    // Menu's key_pressed handler will send ENTER on to current_field
    });
    item.getStyleClass().add("ac-menu-item");
    item.setMnemonicParsing(false);
    return item;
}
Also used : MenuItem(javafx.scene.control.MenuItem) CustomMenuItem(javafx.scene.control.CustomMenuItem)

Example 94 with MenuItem

use of javafx.scene.control.MenuItem in project uPMT by coco35700.

the class MomentContextMenu method init.

public void init(Stage stage) {
    HBox root = new HBox();
    root.setPadding(new Insets(5));
    root.setSpacing(5);
    // Create ContextMenu
    contextMenu = new ContextMenu();
    MenuItem item1 = new MenuItem("Menu Item 1");
    item1.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
        // clique sur item1
        }
    });
    MenuItem item2 = new MenuItem("Menu Item 2");
    item2.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
        // clique sur item2
        }
    });
    Button item3 = new Button("Bt");
// Add MenuItem to ContextMenu
// contextMenu.getItems().addAll(item1, item2, item3);
}
Also used : HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem)

Example 95 with MenuItem

use of javafx.scene.control.MenuItem in project certmgr by hdecarne.

the class CertOptionsController method resetStorePresetMenuHelper.

private void resetStorePresetMenuHelper(ObservableList<MenuItem> menuItems, Set<UserCertStoreEntry> storeEntries, String indent) {
    for (UserCertStoreEntry storeEntry : storeEntries) {
        if (storeEntry.hasCRT() || storeEntry.hasCSR()) {
            MenuItem storeEntryMenuItem = new MenuItem(CertOptionsI18N.formatSTR_MENU_STORE_PRESET(indent, storeEntry.id().getAlias(), X500Names.toString(storeEntry.dn())));
            storeEntryMenuItem.setUserData(CertOptionsTemplates.wrap(storeEntry));
            storeEntryMenuItem.setOnAction(this::onCmdApplyTemplate);
            menuItems.add(storeEntryMenuItem);
            String nextIndent = (Strings.notEmpty(indent) ? "  " + indent : " \u21b3");
            resetStorePresetMenuHelper(menuItems, storeEntry.issuedEntries(), nextIndent);
        }
    }
}
Also used : MenuItem(javafx.scene.control.MenuItem) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Aggregations

MenuItem (javafx.scene.control.MenuItem)136 ContextMenu (javafx.scene.control.ContextMenu)72 Menu (javafx.scene.control.Menu)41 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)41 ActionEvent (javafx.event.ActionEvent)30 File (java.io.File)23 VBox (javafx.scene.layout.VBox)21 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Scene (javafx.scene.Scene)20 Label (javafx.scene.control.Label)19 Collectors (java.util.stream.Collectors)16 MenuBar (javafx.scene.control.MenuBar)15 ObservableList (javafx.collections.ObservableList)13 IOException (java.io.IOException)12 EventHandler (javafx.event.EventHandler)12 Button (javafx.scene.control.Button)12 ImageView (javafx.scene.image.ImageView)12 FXCollections (javafx.collections.FXCollections)11 KeyCodeCombination (javafx.scene.input.KeyCodeCombination)11