public void drop(DropTargetDropEvent dtde) { logger.info("Drop: " + dtde); if (dtde.isDataFlavorSupported(OWLObjectDataFlavor.OWL_OBJECT_DATA_FLAVOR)) { try { List<OWLObject> objects = (List<OWLObject>) dtde.getTransferable().getTransferData(OWLObjectDataFlavor.OWL_OBJECT_DATA_FLAVOR); List<OWLClass> clses = new ArrayList<OWLClass>(); for (OWLObject obj : objects) { if (obj instanceof OWLClass) { clses.add((OWLClass) obj); } } if (!clses.isEmpty()) { getAssertedGraphComponent().getVisualisedObjectManager().showObjects(clses.toArray()); dtde.dropComplete(true); } } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); DataFlavor[] flavors = null; try { Transferable t = dtde.getTransferable(); iterator = null; flavors = t.getTransferDataFlavors(); if (IJ.debugMode) IJ.log("DragAndDrop.drop: " + flavors.length + " flavors"); for (int i = 0; i < flavors.length; i++) { if (IJ.debugMode) IJ.log(" flavor[" + i + "]: " + flavors[i].getMimeType()); if (flavors[i].isFlavorJavaFileListType()) { Object data = t.getTransferData(DataFlavor.javaFileListFlavor); iterator = ((List) data).iterator(); break; } else if (flavors[i].isFlavorTextType()) { Object ob = t.getTransferData(flavors[i]); if (!(ob instanceof String)) continue; String s = ob.toString().trim(); if (IJ.isLinux() && s.length() > 1 && (int) s.charAt(1) == 0) s = fixLinuxString(s); ArrayList list = new ArrayList(); if (s.indexOf("href=\"") != -1 || s.indexOf("src=\"") != -1) { s = parseHTML(s); if (IJ.debugMode) IJ.log(" url: " + s); list.add(s); this.iterator = list.iterator(); break; } BufferedReader br = new BufferedReader(new StringReader(s)); String tmp; while (null != (tmp = br.readLine())) { tmp = java.net.URLDecoder.decode(tmp.replaceAll("\\+", "%2b"), "UTF-8"); if (tmp.startsWith("file://")) tmp = tmp.substring(7); if (IJ.debugMode) IJ.log(" content: " + tmp); if (tmp.startsWith("http://")) list.add(s); else list.add(new File(tmp)); } this.iterator = list.iterator(); break; } } if (iterator != null) { Thread thread = new Thread(this, "DrawAndDrop"); thread.setPriority(Math.max(thread.getPriority() - 1, Thread.MIN_PRIORITY)); thread.start(); } } catch (Exception e) { dtde.dropComplete(false); return; } dtde.dropComplete(true); if (flavors == null || flavors.length == 0) { if (IJ.isMacOSX()) IJ.error( "First drag and drop ignored. Please try again. You can avoid this\n" + "problem by dragging to the toolbar instead of the status bar."); else IJ.error("Drag and drop failed"); } }
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); }