Search in sources :

Example 26 with MenuItem

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

the class ActionButtonRepresentation method makeBaseButton.

// private int calls = 0;
/**
 * Create <code>base</code>, either single-action button
 *  or menu for selecting one out of N actions
 */
private ButtonBase makeBaseButton() {
    final ActionInfos actions = model_widget.propActions().getValue();
    final ButtonBase result;
    if (actions.isExecutedAsOne() || actions.getActions().size() < 2) {
        final Button button = new Button();
        button.setOnAction(event -> handleActions(actions.getActions()));
        result = button;
    } else {
        final MenuButton button = new MenuButton();
        // Experimenting with ways to force update of popup location,
        // #226
        button.showingProperty().addListener((prop, old, showing) -> {
            if (showing) {
            // System.out.println("Showing " + model_widget + " menu: " + showing);
            // if (++calls > 2)
            // {
            // System.out.println("Hack!");
            // if (button.getPopupSide() == Side.BOTTOM)
            // button.setPopupSide(Side.LEFT);
            // else
            // button.setPopupSide(Side.BOTTOM);
            // // button.layout();
            // }
            }
        });
        for (final ActionInfo action : actions.getActions()) {
            final MenuItem item = new MenuItem(makeActionText(action), new ImageView(new Image(action.getType().getIconStream())));
            item.getStyleClass().add("action_button_item");
            item.setOnAction(event -> handleAction(action));
            button.getItems().add(item);
        }
        result = button;
    }
    result.setStyle(background);
    result.getStyleClass().add("action_button");
    result.setMnemonicParsing(false);
    // Model has width/height, but JFX widget has min, pref, max size.
    // updateChanges() will set the 'pref' size, so make min use that as well.
    result.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
    // Monitor keys that modify the OpenDisplayActionInfo.Target.
    // Use filter to capture event that's otherwise already handled.
    result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers);
    // Need to attach TT to the specific button, not the common jfx_node Pane
    TooltipSupport.attach(result, model_widget.propTooltip());
    result.setCursor(Cursor.HAND);
    return result;
}
Also used : Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) MenuButton(javafx.scene.control.MenuButton) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) MenuItem(javafx.scene.control.MenuItem) ButtonBase(javafx.scene.control.ButtonBase) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 27 with MenuItem

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

the class MenuButtonDemo method start.

@Override
public void start(final Stage stage) {
    final MenuButton button1 = new MenuButton("Plain Button", null, new MenuItem("Item 1"), new MenuItem("Item 2"));
    button1.getStyleClass().add("action_button");
    final MenuItem item = new MenuItem("Action Button Item");
    item.getStyleClass().add("action_button_item");
    final MenuButton button2 = new MenuButton("Dark Button", null, item, new MenuItem("Plain Item"));
    button2.setStyle(JFXUtil.shadedStyle(new WidgetColor(100, 0, 0)));
    button2.setTextFill(Color.YELLOW);
    button2.getStyleClass().add("action_button");
    final HBox box = new HBox(button1, button2);
    final Scene scene = new Scene(box, 800, 700);
    // XXX Enable scenic view to debug styles
    // ScenicView.show(scene);
    JFXRepresentation.setSceneStyle(scene);
    stage.setScene(scene);
    stage.setTitle("MenuButtons");
    stage.show();
}
Also used : HBox(javafx.scene.layout.HBox) WidgetColor(org.csstudio.display.builder.model.properties.WidgetColor) MenuButton(javafx.scene.control.MenuButton) MenuItem(javafx.scene.control.MenuItem) Scene(javafx.scene.Scene)

Example 28 with MenuItem

use of javafx.scene.control.MenuItem in project blue by kunstmusik.

the class UserSoundObjectLibrary method buildContextMenu.

public ContextMenu buildContextMenu(TreeView<LibraryItem<SoundObject>> treeView) {
    ContextMenu popupMenu = new ContextMenu();
    // popupMenu.getItems().add(new MenuItem("Test"));
    ObservableList<TreeItem<LibraryItem<SoundObject>>> selectedItems = treeView.getSelectionModel().getSelectedItems();
    final ScoreController.ScoreObjectBuffer scoreObjectBuffer = ScoreController.getInstance().getScoreObjectBuffer();
    // FOLDER MENU ITEMS
    List<MenuItem> folderMenuItems = new ArrayList<>();
    MenuItem addFolder = new MenuItem("Add Folder");
    addFolder.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        item.getChildren().add(new LibraryTreeItem(new LibraryItem<>("New Folder")));
    });
    MenuItem deleteFolder = new MenuItem("Delete Folder");
    deleteFolder.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        item.getParent().getChildren().remove(item);
    });
    MenuItem paste = new MenuItem("Paste SoundObject");
    paste.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        SoundObject sObj = (SoundObject) scoreObjectBuffer.scoreObjects.get(0).deepCopy();
        if (!SoundObjectUtilities.isOrContainsInstance(sObj)) {
            item.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
        }
    });
    folderMenuItems.add(addFolder);
    folderMenuItems.add(deleteFolder);
    folderMenuItems.add(paste);
    // FOLDER MENU ITEMS
    List<MenuItem> sObjMenuItems = new ArrayList<>();
    MenuItem cut = new MenuItem("Cut");
    cut.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        SoundObject sObj = item.getValue().getValue();
        if (sObj == null) {
            return;
        }
        scoreObjectBuffer.clear();
        scoreObjectBuffer.scoreObjects.add(sObj.deepCopy());
        scoreObjectBuffer.layerIndexes.add(0);
        item.getParent().getChildren().remove(item);
    });
    MenuItem copy = new MenuItem("Copy");
    copy.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        SoundObject sObj = item.getValue().getValue();
        if (sObj == null) {
            return;
        }
        scoreObjectBuffer.clear();
        scoreObjectBuffer.scoreObjects.add(sObj.deepCopy());
        scoreObjectBuffer.layerIndexes.add(0);
    });
    MenuItem delete = new MenuItem("Delete");
    delete.setOnAction(evt -> {
        TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
        item.getParent().getChildren().remove(item);
    });
    sObjMenuItems.add(cut);
    sObjMenuItems.add(copy);
    sObjMenuItems.add(new SeparatorMenuItem());
    sObjMenuItems.add(delete);
    popupMenu.getItems().addAll(folderMenuItems);
    popupMenu.getItems().addAll(sObjMenuItems);
    popupMenu.setOnShowing(evt -> {
        if (selectedItems.size() == 1) {
            TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
            boolean isFolder = item.getValue().getValue() == null;
            deleteFolder.setDisable(item == soundObjectLibrary.getRoot());
            if (isFolder) {
                boolean isScoreObj = scoreObjectBuffer.scoreObjects.size() == 1 && scoreObjectBuffer.scoreObjects.get(0) instanceof SoundObject;
                if (isScoreObj) {
                    SoundObject sObj = (SoundObject) scoreObjectBuffer.scoreObjects.get(0);
                    paste.setDisable(SoundObjectUtilities.isOrContainsInstance(sObj));
                } else {
                    paste.setDisable(true);
                }
            }
            for (MenuItem menuItem : folderMenuItems) {
                menuItem.setVisible(isFolder);
            }
            for (MenuItem menuItem : sObjMenuItems) {
                menuItem.setVisible(!isFolder);
            }
        }
    });
    return popupMenu;
}
Also used : LibraryItem(blue.library.LibraryItem) LibraryTreeItem(blue.library.LibraryTreeItem) TreeItem(javafx.scene.control.TreeItem) LibraryTreeItem(blue.library.LibraryTreeItem) ArrayList(java.util.ArrayList) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ScoreController(blue.ui.core.score.ScoreController) SoundObject(blue.soundObject.SoundObject)

Example 29 with MenuItem

use of javafx.scene.control.MenuItem in project blue by kunstmusik.

the class BSBObjectViewHolder method getContextMenu.

private static ContextMenu getContextMenu() {
    if (MENU == null) {
        MENU = new ContextMenu();
        MenuItem cut = new MenuItem("Cut");
        cut.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.cut();
        });
        MenuItem copy = new MenuItem("Copy");
        copy.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.copy();
        });
        MenuItem remove = new MenuItem("Remove");
        remove.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.remove();
        });
        MenuItem makeGroup = new MenuItem("Make Group");
        makeGroup.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            List<BSBGroup> groupsList = data.groupsList;
            List<BSBObject> bsbObjs = selection.selection.stream().map(b -> b.deepCopy()).collect(Collectors.toList());
            int x = Integer.MAX_VALUE;
            int y = Integer.MAX_VALUE;
            for (BSBObject bsbObj : bsbObjs) {
                x = Math.min(x, bsbObj.getX());
                y = Math.min(y, bsbObj.getY());
            }
            for (BSBObject bsbObj : bsbObjs) {
                bsbObj.setX(bsbObj.getX() - x + 10);
                bsbObj.setY(bsbObj.getY() - y + 10);
            }
            selection.remove();
            BSBGroup group = new BSBGroup();
            group.interfaceItemsProperty().addAll(bsbObjs);
            group.setX(x);
            group.setY(y);
            groupsList.get(groupsList.size() - 1).addBSBObject(group);
        });
        MenuItem breakGroup = new MenuItem("Break Group");
        breakGroup.setOnAction((ActionEvent e) -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            List<BSBGroup> groupsList = data.groupsList;
            BSBGroup group = (BSBGroup) selection.selection.toArray()[0];
            int x = group.getX();
            int y = group.getY();
            selection.remove();
            BSBGroup rootGroup = groupsList.get(groupsList.size() - 1);
            for (BSBObject bsbObj : group) {
                BSBObject temp = bsbObj.deepCopy();
                temp.setX(temp.getX() + x);
                temp.setY(temp.getY() + y);
                rootGroup.addBSBObject(temp);
            }
            ;
        });
        final Menu align = new Menu("Align");
        final Menu distribute = new Menu("Distribute");
        EventHandler<ActionEvent> alignListener = ae -> {
            MenuItem source = (MenuItem) ae.getSource();
            Alignment alignment = (Alignment) source.getUserData();
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            AlignmentUtils.align(selection.getSelectedNodes(), alignment);
        };
        EventHandler<ActionEvent> distributeListener = ae -> {
            MenuItem source = (MenuItem) ae.getSource();
            Alignment alignment = (Alignment) source.getUserData();
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            AlignmentUtils.distribute(selection.getSelectedNodes(), alignment);
        };
        for (Alignment alignment : Alignment.values()) {
            MenuItem a = new MenuItem(alignment.toString());
            a.setUserData(alignment);
            a.setOnAction(alignListener);
            MenuItem d = new MenuItem(alignment.toString());
            d.setUserData(alignment);
            d.setOnAction(distributeListener);
            align.getItems().add(a);
            distribute.getItems().add(d);
        }
        MENU.getItems().addAll(cut, copy, remove);
        MENU.getItems().addAll(new SeparatorMenuItem(), makeGroup, breakGroup);
        MENU.getItems().addAll(new SeparatorMenuItem(), align, distribute);
        MENU.setOnHidden(e -> MENU.setUserData(null));
        MENU.setOnShowing(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            align.setDisable(selection.selection.size() < 2);
            distribute.setDisable(selection.selection.size() < 2);
            breakGroup.setDisable(selection.selection.size() != 1 || selection.selection.stream().noneMatch((x) -> x instanceof BSBGroup));
        });
    }
    return MENU;
}
Also used : EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene) BooleanBinding(javafx.beans.binding.BooleanBinding) BoundingBox(javafx.geometry.BoundingBox) MouseEvent(javafx.scene.input.MouseEvent) Bindings(javafx.beans.binding.Bindings) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup) ContextMenu(javafx.scene.control.ContextMenu) Point2D(javafx.geometry.Point2D) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) Pane(javafx.scene.layout.Pane) Color(javafx.scene.paint.Color) MenuItem(javafx.scene.control.MenuItem) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Menu(javafx.scene.control.Menu) Cursor(javafx.scene.Cursor) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) Region(javafx.scene.layout.Region) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup)

Example 30 with MenuItem

use of javafx.scene.control.MenuItem in project blue by kunstmusik.

the class PresetPane method setPresetsMenu.

private void setPresetsMenu(PresetGroup pGroup, Menu parent) {
    for (PresetGroup subGroup : pGroup.getSubGroups()) {
        Menu menu = new Menu(subGroup.getPresetGroupName());
        setPresetsMenu(subGroup, menu);
        if (parent == null) {
            rootMenu.getItems().add(menu);
        } else {
            parent.getItems().add(menu);
        }
    }
    for (Preset preset : pGroup.getPresets()) {
        MenuItem item = new MenuItem(preset.getPresetName());
        item.setUserData(preset);
        item.setOnAction(presetSelectedAction);
        if (parent == null) {
            rootMenu.getItems().add(item);
        } else {
            parent.getItems().add(item);
        }
    }
    if (parent == null) {
        rootMenu.getItems().add(new SeparatorMenuItem());
    } else {
        parent.getItems().add(new SeparatorMenuItem());
    }
    MenuItem addFolder = new MenuItem("Add Folder");
    addFolder.setUserData(pGroup);
    addFolder.setOnAction(addFolderAction);
    MenuItem addPreset = new MenuItem("Add Preset");
    addPreset.setUserData(pGroup);
    addPreset.setOnAction(addPresetAction);
    if (parent == null) {
        MenuItem syncPresets = new MenuItem("Synchronize Presets");
        syncPresets.setOnAction(e -> {
            PresetsUtilities.synchronizePresets(getPresetGroup(), bsbInterface);
        });
        MenuItem managePresets = new MenuItem("Manage Presets");
        managePresets.setOnAction(e -> {
            PresetGroup[] retVal = new PresetGroup[1];
            CountDownLatch latch = new CountDownLatch(1);
            SwingUtilities.invokeLater(() -> {
                try {
                    if (presetsManager == null) {
                        presetsManager = new PresetsManagerDialog(WindowManager.getDefault().getMainWindow());
                    }
                    retVal[0] = presetsManager.editPresetGroup(pGroup);
                } finally {
                    latch.countDown();
                }
            });
            try {
                latch.await();
            } catch (InterruptedException ex) {
                Exceptions.printStackTrace(ex);
            }
            if (retVal[0] != null) {
                pGroup.setPresets(retVal[0].getPresets());
                pGroup.setSubGroups(retVal[0].getSubGroups());
                updatePresetMenu();
                Preset preset = pGroup.findPresetByUniqueId(pGroup.getCurrentPresetUniqueId());
                if (preset == null) {
                    pGroup.setCurrentPresetUniqueId(null);
                    pGroup.setCurrentPresetModified(false);
                }
                updateCurrentPresetUI();
            }
        });
        rootMenu.getItems().addAll(addFolder, addPreset, new SeparatorMenuItem(), syncPresets, managePresets);
    } else {
        parent.getItems().addAll(addFolder, addPreset);
    }
}
Also used : Preset(blue.orchestra.blueSynthBuilder.Preset) PresetGroup(blue.orchestra.blueSynthBuilder.PresetGroup) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) CountDownLatch(java.util.concurrent.CountDownLatch) PresetsManagerDialog(blue.orchestra.editor.blueSynthBuilder.PresetsManagerDialog)

Aggregations

MenuItem (javafx.scene.control.MenuItem)133 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 List (java.util.List)20 Scene (javafx.scene.Scene)20 ArrayList (java.util.ArrayList)19 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 FXCollections (javafx.collections.FXCollections)11 ImageView (javafx.scene.image.ImageView)11 KeyCodeCombination (javafx.scene.input.KeyCodeCombination)11