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;
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations