Exemple #1
0
  private void acceptDrop(DropTargetDropEvent dtde) {
    int dragaction = dtde.getDropAction();

    if (dragaction != 0) {
      dtde.acceptDrop(dragaction);
    } else {
      dtde.acceptDrop(ALL_ACTIONS);
    }
  }
  public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      try {
        content =
            (java.util.List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
        repaint();
      } catch (UnsupportedFlavorException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      dtde.dropComplete(true);

      boolean listsAreEqual = true;

      for (int i = 0; i < content.size(); i++) {
        if (!FileListTransferable.files[i].getName().equals(content.get(i).getName())) {
          listsAreEqual = false;
        }
      }

      if (listsAreEqual) {
        System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
        System.exit(0);
      }
    }
    dtde.rejectDrop();
    System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED);
    System.exit(1);
  }
Exemple #3
0
  public void drop(DropTargetDropEvent dtde) {
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
      dtde.rejectDrop();
      return;
    }
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    Vector<RowContainer> oldvec = this.filevector;

    Transferable transferable = dtde.getTransferable();
    try {
      java.util.List<File> filelist =
          (java.util.List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
      for (File f : filelist) {
        filevector.add(new RowContainer(f));

        model.fireTableDataChanged();
        System.out.println(f.toString());
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (UnsupportedFlavorException ex) {
      ex.printStackTrace();
    }
    dtde.dropComplete(true);
    File[] filar = new File[filevector.size()];
    for (int i = 0; i < filevector.size(); i++) {
      filar[i] = filevector.get(i).getFile();
    }
    super.firePropertyChange("filevector", null, filar);
  }
 private void processDrop(DropData dropData, DropTargetDropEvent dropTargetDropEvent) {
   putEntryAtPoint(dropData.whatToDrop, dropData.whereInTable);
   _widget.addEntry(dropData.whatToDrop);
   _underlyingTable.setRowSelectionInterval(dropData.whereInTable.x, dropData.whereInTable.x);
   _underlyingTable.setColumnSelectionInterval(dropData.whereInTable.y, dropData.whereInTable.y);
   dropTargetDropEvent.acceptDrop(dropTargetDropEvent.getDropAction());
   dropTargetDropEvent.dropComplete(true);
 }
Exemple #5
0
 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);
    }
  public void drop(DropTargetDropEvent evt) {
    try {
      Transferable t = evt.getTransferable();

      if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

        String s = (String) t.getTransferData(DataFlavor.stringFlavor);
        evt.getDropTargetContext().dropComplete(true);
        process(s);
      } else {
        evt.rejectDrop();
      }
    } catch (IOException e) {
      evt.rejectDrop();
    } catch (UnsupportedFlavorException e) {
      evt.rejectDrop();
    }
  }
 @Override
 public void drop(DropTargetDropEvent dtde) {
   try {
     if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
       dtde.acceptDrop(DnDConstants.ACTION_COPY);
       Transferable t = dtde.getTransferable();
       List list = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
       for (Object o : list) {
         if (o instanceof File) {
           File f = (File) o;
           System.out.println(f.getAbsolutePath());
         }
       }
       dtde.dropComplete(true);
       return;
     }
   } catch (UnsupportedFlavorException | IOException ex) {
     ex.printStackTrace();
   }
   dtde.rejectDrop();
 }
    public void drop(DropTargetDropEvent e) {
      if (dragSource != null) {
        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        Point p = e.getLocation();
        int targetRow = rowAtPoint(p);

        Object edge =
            graph.insertEdge(
                null,
                null,
                null,
                dragSource.cell,
                JTableRenderer.this.cell,
                "sourceRow=" + sourceRow + ";targetRow=" + targetRow);
        graph.setSelectionCell(edge);

        // System.out.println("clearing drag source");
        dragSource = null;
        e.dropComplete(true);
      } else {
        e.rejectDrop();
      }
    }