Search in sources :

Example 1 with LibraryItem

use of blue.library.LibraryItem 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 2 with LibraryItem

use of blue.library.LibraryItem in project blue by kunstmusik.

the class SoundObjectImportPane method importSoundObjectToLibrary.

protected void importSoundObjectToLibrary(Library<SoundObject> lib, SoundObject sObj) {
    for (TreeItem<LibraryItem<SoundObject>> item : lib.getRoot().getChildren()) {
        if (!item.isLeaf() && item.getValue().toString().equals("Imported SoundObjects")) {
            item.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
            return;
        }
    }
    LibraryTreeItem importFolder = new LibraryTreeItem(new LibraryItem<>("Imported SoundObjects"));
    importFolder.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
    lib.getRoot().getChildren().add(importFolder);
}
Also used : LibraryItem(blue.library.LibraryItem) LibraryTreeItem(blue.library.LibraryTreeItem)

Example 3 with LibraryItem

use of blue.library.LibraryItem in project blue by kunstmusik.

the class SoundObjectExportPane method jbInit.

private void jbInit() throws Exception {
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    soundObjectListPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    categoryPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    cateogriesLabel.setText(BlueSystem.getString("common.categories"));
    categoryPanel.setLayout(new BorderLayout());
    this.add(namePasswordPanel, BorderLayout.NORTH);
    this.add(mainSplitPane, BorderLayout.CENTER);
    this.add(jPanel2, BorderLayout.SOUTH);
    descriptionText.setText(BlueSystem.getString("blueShare.enterDescription"));
    descriptionText.setLineWrap(true);
    descriptionScrollPane.setBorder(new TitledBorder(null, BlueSystem.getString("blueShare.instrDescription")));
    submitButton.setText(BlueSystem.getString("common.submit"));
    soundObjectListPanel.setLayout(new BorderLayout());
    iLabel.setText("SoundObjects from Library");
    // soundObjectLibraryTree.setSelectionModel(TreeSelectionModel.SINGLE_TREE_SELECTION);
    topSplitPane.add(soundObjectListPanel, JSplitPane.LEFT);
    soundObjectListPanel.add(soundObjectListScrollPane, BorderLayout.CENTER);
    soundObjectListPanel.add(iLabel, BorderLayout.NORTH);
    soundObjectListScrollPane.getViewport().add(soundObjectLibraryTree, null);
    descriptionScrollPane.getViewport().add(descriptionText, null);
    jPanel2.add(submitButton, null);
    topSplitPane.setDividerLocation(300);
    mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    mainSplitPane.add(topSplitPane, JSplitPane.TOP);
    mainSplitPane.add(descriptionScrollPane, JSplitPane.BOTTOM);
    topSplitPane.add(categoryPanel, JSplitPane.RIGHT);
    categoryPanel.add(cateogriesLabel, BorderLayout.NORTH);
    categoryPanel.add(categoryScrollPane, BorderLayout.CENTER);
    categoryScrollPane.getViewport().add(categoryTree, null);
    mainSplitPane.setDividerLocation(200);
    submitButton.addActionListener((ActionEvent e) -> {
        submitSoundObject();
    });
    soundObjectLibraryTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = soundObjectLibraryTree.getSelectionPath();
            if (path == null) {
                descriptionText.setText(SELECT_INSTR_TEXT);
                descriptionText.setEnabled(false);
                return;
            }
            Object userObj = path.getLastPathComponent();
            TreeItem<LibraryItem<SoundObject>> node = (TreeItem<LibraryItem<SoundObject>>) userObj;
            if (!node.isLeaf()) {
                descriptionText.setText(SELECT_INSTR_TEXT);
                descriptionText.setEnabled(false);
                return;
            }
            SoundObject instr = node.getValue().getValue();
            if (instr instanceof Sound) {
                descriptionText.setText(((Sound) instr).getComment());
            } else if (instr instanceof ObjectBuilder) {
                descriptionText.setText(((ObjectBuilder) instr).getComment());
            } else {
                descriptionText.setText("");
            }
            descriptionText.setEnabled(true);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) LibraryItem(blue.library.LibraryItem) TreeItem(javafx.scene.control.TreeItem) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) Sound(blue.soundObject.Sound) ObjectBuilder(blue.soundObject.ObjectBuilder) TitledBorder(javax.swing.border.TitledBorder) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) SoundObject(blue.soundObject.SoundObject) SoundObject(blue.soundObject.SoundObject)

Example 4 with LibraryItem

use of blue.library.LibraryItem in project blue by kunstmusik.

the class SoundObjectExportPane method submitSoundObject.

private void submitSoundObject() {
    try {
        TreePath path = soundObjectLibraryTree.getSelectionPath();
        if (path == null) {
            return;
        }
        Object userObj = path.getLastPathComponent();
        TreeItem<LibraryItem<SoundObject>> node = (TreeItem<LibraryItem<SoundObject>>) userObj;
        if (!node.isLeaf()) {
            return;
        }
        SoundObject soundObject = node.getValue().getValue();
        DefaultMutableTreeNode tempNode = (DefaultMutableTreeNode) categoryTree.getSelectionPath().getLastPathComponent();
        BlueShareSoundObjectCategory category = (BlueShareSoundObjectCategory) tempNode.getUserObject();
        String username = namePasswordPanel.getUsername();
        String password = namePasswordPanel.getPassword();
        int categoryId = category.getCategoryId();
        String name = soundObject.getName();
        String soundObjectType = soundObject.getClass().getName();
        String description = descriptionText.getText();
        String soundObjectText = soundObject.saveAsXML(new HashMap<>()).toString();
        System.out.println(soundObject.saveAsXML(new HashMap<>()).getTextString());
        BlueShareRemoteCaller.submitSoundObject(username, password, categoryId, name, soundObjectType, description, soundObjectText);
    } catch (IOException | XmlRpcException e) {
        JOptionPane.showMessageDialog(null, "Error submitting SoundObject" + "\n\n" + e.getLocalizedMessage(), BlueSystem.getString("common.error"), JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }
    JOptionPane.showMessageDialog(null, "SoundObject was successfully received.", BlueSystem.getString("common.success"), JOptionPane.PLAIN_MESSAGE);
}
Also used : LibraryItem(blue.library.LibraryItem) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeItem(javafx.scene.control.TreeItem) HashMap(java.util.HashMap) IOException(java.io.IOException) TreePath(javax.swing.tree.TreePath) SoundObject(blue.soundObject.SoundObject) SoundObject(blue.soundObject.SoundObject) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

LibraryItem (blue.library.LibraryItem)4 SoundObject (blue.soundObject.SoundObject)3 TreeItem (javafx.scene.control.TreeItem)3 LibraryTreeItem (blue.library.LibraryTreeItem)2 TreePath (javax.swing.tree.TreePath)2 ObjectBuilder (blue.soundObject.ObjectBuilder)1 Sound (blue.soundObject.Sound)1 ScoreController (blue.ui.core.score.ScoreController)1 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ContextMenu (javafx.scene.control.ContextMenu)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 TitledBorder (javax.swing.border.TitledBorder)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1