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;
}
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);
}
use of blue.orchestra.InstrumentCategory in project blue by kunstmusik.
the class UserInstrumentTreePopup method addInstrumentCategory.
private void addInstrumentCategory() {
InstrumentCategory newCategory = new InstrumentCategory();
addInstrumentCategory(newCategory);
}
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();
}
}
Aggregations