Search in sources :

Example 1 with UserDefinedOpcode

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

the class UDOUtilities method appendUserDefinedOpcodes.

/**
 * Given a list of Opcodes, append them to the passed in master list. A
 * hashmap filled with key-value pairs of old UDO names to newly assigned
 * UDO names will be returned. The returned map may not contain any values
 * if no replacement of names are needed.
 *
 * @param newList
 * @param masterList
 * @return
 */
public static HashMap appendUserDefinedOpcodes(OpcodeList newList, OpcodeList masterList) {
    HashMap keyValues = new HashMap();
    for (Iterator iter = newList.iterator(); iter.hasNext(); ) {
        UserDefinedOpcode udo = (UserDefinedOpcode) iter.next();
        if (keyValues.size() > 0) {
            udo.codeBody = TextUtilities.replaceOpcodeNames(keyValues, udo.codeBody);
        }
        String oldName = udo.getOpcodeName();
        String newName = masterList.getNameOfEquivalentCopy(udo);
        if (newName == null) {
            if (!masterList.isNameUnique(oldName)) {
                newName = masterList.getUniqueName();
                udo.setOpcodeName(newName);
            }
            masterList.addOpcode(udo);
        }
        if (newName != null && !newName.equals(oldName)) {
            keyValues.put(oldName, newName);
        }
    }
    return keyValues;
}
Also used : HashMap(java.util.HashMap) UserDefinedOpcode(blue.udo.UserDefinedOpcode) Iterator(java.util.Iterator)

Example 2 with UserDefinedOpcode

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

the class OpcodeListChildren method createNodes.

@Override
protected Node[] createNodes(OpcodeList key) {
    Node[] returnNodes = new Node[key.size()];
    for (int i = 0; i < returnNodes.length; i++) {
        final UserDefinedOpcode udo = key.get(i);
        returnNodes[i] = new UDONode(udo);
        returnNodes[i].setDisplayName(udo.getOpcodeName());
        System.out.println(udo.getOpcodeName());
    }
    return returnNodes;
}
Also used : UserDefinedOpcode(blue.udo.UserDefinedOpcode) Node(org.openide.nodes.Node)

Example 3 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode 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 4 with UserDefinedOpcode

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

the class UDOTreePopup method removeUDO.

private void removeUDO() {
    UserDefinedOpcode udo = (UserDefinedOpcode) userObj;
    instrGUI.removeUDO(udo);
}
Also used : UserDefinedOpcode(blue.udo.UserDefinedOpcode)

Example 5 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode 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)

Aggregations

UserDefinedOpcode (blue.udo.UserDefinedOpcode)22 UDOCategory (blue.udo.UDOCategory)6 Point (java.awt.Point)6 IOException (java.io.IOException)4 File (java.io.File)3 TreePath (javax.swing.tree.TreePath)3 OpcodeList (blue.udo.OpcodeList)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 Arrangement (blue.Arrangement)1 Parameter (blue.automation.Parameter)1 GenericInstrument (blue.orchestra.GenericInstrument)1 BSBCompilationUnit (blue.orchestra.blueSynthBuilder.BSBCompilationUnit)1 UDOLibrary (blue.udo.UDOLibrary)1 Document (electric.xml.Document)1 Element (electric.xml.Element)1 ParseException (electric.xml.ParseException)1 Rectangle (java.awt.Rectangle)1