public void drop(DropTargetDropEvent event) { if (!isDropAcceptable(event)) { event.rejectDrop(); return; } event.acceptDrop(DnDConstants.ACTION_COPY); Transferable transferable = event.getTransferable(); MessageCollection messages = new MessageCollection(); try { List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); for (File file : files) { try { ResourceLocator locator = new ResourceLocator(file.getAbsolutePath()); IGV.getInstance().load(locator, panel); } catch (DataLoadException de) { messages.append(de.getMessage()); } } String obj = transferable.getTransferData(DataFlavor.stringFlavor).toString(); if (HttpUtils.isRemoteURL(obj)) { IGV.getInstance().load(new ResourceLocator(obj), panel); } if (messages != null && !messages.isEmpty()) { log.error(messages.getFormattedMessage()); MessageUtils.showMessage(messages.getFormattedMessage()); } } catch (Exception e) { String obj = null; try { obj = transferable.getTransferData(DataFlavor.stringFlavor).toString(); if (HttpUtils.isRemoteURL(obj)) { IGV.getInstance().load(new ResourceLocator(obj), panel); } } catch (Exception e1) { log.error(e1); if (messages != null && !messages.isEmpty()) { MessageUtils.showMessage(messages.getFormattedMessage()); } } } IGV.getMainFrame().repaint(); event.dropComplete(true); }
public boolean isDropAcceptable(DropTargetDropEvent event) { // usually, you // check the // available // data flavors // here // in this program, we accept all flavors return (event.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0; }