Search in sources :

Example 1 with UDOCategory

use of blue.udo.UDOCategory in project blue by kunstmusik.

the class UDOTreePopup method copyNode.

protected void copyNode() {
    if (userObj == instrGUI.iLibrary.getRoot()) {
        return;
    }
    Object bufObj;
    if (userObj instanceof UserDefinedOpcode) {
        bufObj = new UserDefinedOpcode((UserDefinedOpcode) userObj);
    } else {
        bufObj = new UDOCategory((UDOCategory) userObj);
    }
    UDOBuffer.getInstance().setBufferedObject(bufObj);
}
Also used : UDOCategory(blue.udo.UDOCategory) UserDefinedOpcode(blue.udo.UserDefinedOpcode)

Example 2 with UDOCategory

use of blue.udo.UDOCategory in project blue by kunstmusik.

the class UDOTreePopup method addUDOCategory.

private void addUDOCategory() {
    UDOCategory newCategory = new UDOCategory();
    addUDOCategory(newCategory);
}
Also used : UDOCategory(blue.udo.UDOCategory)

Example 3 with UDOCategory

use of blue.udo.UDOCategory in project blue by kunstmusik.

the class UDOTreeDropTarget 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(TransferableUDO.UDO_CAT_FLAVOR)) {
        if (!(node instanceof UDOCategory)) {
            dtde.rejectDrop();
            return;
        }
        if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable tr = dtde.getTransferable();
            try {
                Object transferNode = tr.getTransferData(TransferableUDO.UDO_CAT_FLAVOR);
                UDOCategory udoCategory = (UDOCategory) transferNode;
                UDOCategory parentNode = (UDOCategory) node;
                UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();
                udoLibrary.addCategory(parentNode, udoCategory);
                dtde.dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                dtde.dropComplete(false);
            }
        } else {
            dtde.rejectDrop();
        }
    } else if (dtde.isDataFlavorSupported(TransferableUDO.UDO_FLAVOR)) {
        dtde.acceptDrop(dtde.getDropAction());
        try {
            Transferable tr = dtde.getTransferable();
            Object transferNode = tr.getTransferData(TransferableUDO.UDO_FLAVOR);
            UserDefinedOpcode udo = (UserDefinedOpcode) transferNode;
            UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();
            // iLibrary.removeInstrument(instrument);
            if (node instanceof UDOCategory) {
                UDOCategory parentNode = (UDOCategory) node;
                udoLibrary.addUDO(parentNode, udo);
            } else if (node instanceof UserDefinedOpcode) {
                UDOCategory parentNode = (UDOCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
                int index = ListUtil.indexOfByRef(parentNode.getUserDefinedOpcodes(), node);
                int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
                Rectangle bounds = tree.getRowBounds(closestRow);
                if (pt.y > bounds.y + bounds.height) {
                    udoLibrary.addUDO(parentNode, udo);
                } else {
                    udoLibrary.addUDO(parentNode, index, udo);
                }
            }
            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) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) JTree(javax.swing.JTree) UDOCategory(blue.udo.UDOCategory) TreePath(javax.swing.tree.TreePath) UDOLibrary(blue.udo.UDOLibrary) UserDefinedOpcode(blue.udo.UserDefinedOpcode)

Example 4 with UDOCategory

use of blue.udo.UDOCategory in project blue by kunstmusik.

the class OpcodeListEditPanel method handlePaste.

private void handlePaste(Object obj) {
    if (obj instanceof UserDefinedOpcode) {
        opcodeList.addOpcode(new UserDefinedOpcode((UserDefinedOpcode) obj));
    } else if (obj instanceof UserDefinedOpcode[]) {
        UserDefinedOpcode[] udos = (UserDefinedOpcode[]) obj;
        UserDefinedOpcode[] copies = new UserDefinedOpcode[udos.length];
        for (int i = 0; i < udos.length; i++) {
            copies[i] = new UserDefinedOpcode(udos[i]);
        }
        opcodeList.addOpcodes(copies);
    } else if (obj instanceof UDOCategory) {
        UDOCategory cat = (UDOCategory) obj;
        ArrayList<UserDefinedOpcode> udos = cat.getAllUserDefinedOpcodes();
        UserDefinedOpcode[] copies = new UserDefinedOpcode[udos.size()];
        for (int i = 0; i < udos.size(); i++) {
            copies[i] = new UserDefinedOpcode(udos.get(i));
        }
        opcodeList.addOpcodes(copies);
    }
}
Also used : UDOCategory(blue.udo.UDOCategory) UserDefinedOpcode(blue.udo.UserDefinedOpcode) Point(java.awt.Point)

Example 5 with UDOCategory

use of blue.udo.UDOCategory in project blue by kunstmusik.

the class UDOTreePopup method addUDO.

private void addUDO() {
    UserDefinedOpcode newUDO = new UserDefinedOpcode();
    UDOCategory currentCategory = (UDOCategory) userObj;
    instrGUI.iLibrary.addUDO(currentCategory, newUDO);
/*
         * BlueUndoManager.setUndoManager("orchestra"); BlueUndoManager.addEdit(
         * new AddEdit(orchTableModel, clone, new Integer(iNum)));
         */
}
Also used : UDOCategory(blue.udo.UDOCategory) UserDefinedOpcode(blue.udo.UserDefinedOpcode)

Aggregations

UDOCategory (blue.udo.UDOCategory)9 UserDefinedOpcode (blue.udo.UserDefinedOpcode)6 Point (java.awt.Point)3 TreePath (javax.swing.tree.TreePath)3 DropTargetContext (java.awt.dnd.DropTargetContext)2 JTree (javax.swing.JTree)2 UDOLibrary (blue.udo.UDOLibrary)1 Rectangle (java.awt.Rectangle)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1