use of blue.InstrumentLibrary 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();
}
}
use of blue.InstrumentLibrary in project blue by kunstmusik.
the class InstrumentImportPane method importInstrument.
private void importInstrument() {
InstrumentOption iOption = iTableModel.getInstrumentOption(instrumentTable.getSelectedRow());
if (iOption == null) {
return;
}
try {
Instrument instrument = BlueShareRemoteCaller.getInstrument(iOption);
if (instrument == null) {
String error = BlueSystem.getString("blueShare.importError");
JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
return;
}
// data.getOrchestra().addInstrument(instrument);
// instrumentTreeModel.reload();
InstrumentLibrary instrLib = BlueSystem.getUserInstrumentLibrary();
instrLib.importInstrument(instrument);
String message = BlueSystem.getString("blueShare.importSuccess");
JOptionPane.showMessageDialog(null, message, BlueSystem.getString("common.success"), JOptionPane.PLAIN_MESSAGE);
} catch (ParseException pe) {
String error = BlueSystem.getString("blueShare.selectServer.couldNotReadResponse");
JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
return;
} catch (XmlRpcException xre) {
String error = "Error: " + xre.getLocalizedMessage();
JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
return;
} catch (IOException ioe) {
String error = "Error: " + ioe.getLocalizedMessage();
JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
return;
}
}
Aggregations