Search in sources :

Example 11 with InstrumentCategory

use of blue.orchestra.InstrumentCategory in project blue by kunstmusik.

the class InstrumentLibrary method findParent.

private InstrumentCategory findParent(InstrumentCategory cat, Object obj) {
    if (ListUtil.containsByRef(cat.getInstruments(), obj) || ListUtil.containsByRef(cat.getSubCategories(), obj)) {
        return cat;
    }
    for (Iterator iter = cat.getSubCategories().iterator(); iter.hasNext(); ) {
        InstrumentCategory c = (InstrumentCategory) iter.next();
        InstrumentCategory temp = findParent(c, obj);
        if (temp != null) {
            return temp;
        }
    }
    return null;
}
Also used : InstrumentCategory(blue.orchestra.InstrumentCategory)

Example 12 with InstrumentCategory

use of blue.orchestra.InstrumentCategory in project blue by kunstmusik.

the class InstrumentLibrary method importLibrary.

/**
 * @param library
 */
public void importLibrary(InstrumentLibrary library) {
    InstrumentCategory category = library.getRootInstrumentCategory();
    category.setCategoryName("Imported from Project");
    addCategory(getRootInstrumentCategory(), category);
}
Also used : InstrumentCategory(blue.orchestra.InstrumentCategory)

Example 13 with InstrumentCategory

use of blue.orchestra.InstrumentCategory in project blue by kunstmusik.

the class UserInstrumentTreePopup method addInstrumentCategory.

private void addInstrumentCategory() {
    InstrumentCategory newCategory = new InstrumentCategory();
    addInstrumentCategory(newCategory);
}
Also used : InstrumentCategory(blue.orchestra.InstrumentCategory)

Example 14 with InstrumentCategory

use of blue.orchestra.InstrumentCategory in project blue by kunstmusik.

the class InstrumentTreeDropTarget method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    Object node = parentpath.getLastPathComponent();
    if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_CAT_FLAVOR)) {
        if (!(node instanceof InstrumentCategory)) {
            dtde.rejectDrop();
            return;
        }
        if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable tr = dtde.getTransferable();
            try {
                Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_CAT_FLAVOR);
                InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
                InstrumentCategory parentNode = (InstrumentCategory) node;
                InstrumentCategory instrumentCategory = (InstrumentCategory) transferNode;
                // iLibrary.removeCategory(instrumentCategory);
                iLibrary.addCategory(parentNode, instrumentCategory);
                dtde.dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                dtde.dropComplete(false);
            }
        } else {
            dtde.rejectDrop();
        }
    } else if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_FLAVOR)) {
        dtde.acceptDrop(dtde.getDropAction());
        try {
            Transferable tr = dtde.getTransferable();
            Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_FLAVOR);
            Instrument instrument = (Instrument) transferNode;
            InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
            if (instrument instanceof BlueSynthBuilder) {
                ((BlueSynthBuilder) instrument).clearParameters();
            }
            // iLibrary.removeInstrument(instrument);
            if (node instanceof InstrumentCategory) {
                InstrumentCategory parentNode = (InstrumentCategory) node;
                iLibrary.addInstrument(parentNode, instrument);
            } else if (node instanceof Instrument) {
                InstrumentCategory parentNode = (InstrumentCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
                int index = ListUtil.indexOfByRef(parentNode.getInstruments(), node);
                int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
                Rectangle bounds = tree.getRowBounds(closestRow);
                if (pt.y > bounds.y + bounds.height) {
                    iLibrary.addInstrument(parentNode, instrument);
                } else {
                    iLibrary.addInstrument(parentNode, index, instrument);
                }
            }
            dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
            dtde.dropComplete(false);
        }
    } else {
        dtde.rejectDrop();
    }
}
Also used : DropTargetContext(java.awt.dnd.DropTargetContext) Transferable(java.awt.datatransfer.Transferable) Rectangle(java.awt.Rectangle) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) InstrumentLibrary(blue.InstrumentLibrary) Instrument(blue.orchestra.Instrument) InstrumentCategory(blue.orchestra.InstrumentCategory)

Aggregations

InstrumentCategory (blue.orchestra.InstrumentCategory)14 Instrument (blue.orchestra.Instrument)5 TreeModelEvent (javax.swing.event.TreeModelEvent)3 TreePath (javax.swing.tree.TreePath)3 Point (java.awt.Point)2 DropTargetContext (java.awt.dnd.DropTargetContext)2 JTree (javax.swing.JTree)2 InstrumentLibrary (blue.InstrumentLibrary)1 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)1 Rectangle (java.awt.Rectangle)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1