Search in sources :

Example 1 with PresetsManagerDialog

use of blue.orchestra.editor.blueSynthBuilder.PresetsManagerDialog 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

Preset (blue.orchestra.blueSynthBuilder.Preset)1 PresetGroup (blue.orchestra.blueSynthBuilder.PresetGroup)1 PresetsManagerDialog (blue.orchestra.editor.blueSynthBuilder.PresetsManagerDialog)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ContextMenu (javafx.scene.control.ContextMenu)1 Menu (javafx.scene.control.Menu)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1