コード例 #1
0
ファイル: FileList.java プロジェクト: ken1ma/sysart-itext
  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);
  }
コード例 #2
0
ファイル: DragAndDrop.java プロジェクト: Jondeen/imagej1
 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");
   }
 }
コード例 #3
0
ファイル: JDropListener.java プロジェクト: lmop/jbidwatcher
  public StringBuffer getTransferData(Transferable t) {
    StringBuffer xferData = null;
    Object dropped;
    DataFlavor dtf;

    dtf = testAllFlavors(t);

    JConfig.log().logVerboseDebug("dtf == " + dtf);

    try {
      if (dtf == _htmlFlavor || dtf == _utf8HtmlFlavor || dtf == _thtmlFlavor) {
        /*
         * Annoying.
         */
        if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
          System.out.println("Ick: " + t.getTransferData(DataFlavor.getTextPlainUnicodeFlavor()));
      }
      dropped = t.getTransferData(dtf);
    } catch (IOException ioe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("I/O Exception: " + ioe);
        return null;
      }
    } catch (UnsupportedFlavorException ufe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("Unsupported flavor: " + dtf);
        return null;
      }
    }

    if (dropped != null) {
      if (dropped instanceof InputStream) {
        JConfig.log().logVerboseDebug("Dropped an InputStream");
        xferData = getInputStreamData(t, dtf, (InputStream) dropped);
      } else if (dropped instanceof Reader) {
        JConfig.log().logVerboseDebug("Dropped a Reader");
        xferData = getDataFromReader(new BufferedReader((Reader) dropped));
      } else if (dropped instanceof java.net.URL) {
        JConfig.log().logVerboseDebug("Dropped a URL");
        JConfig.log().logVerboseDebug("Got: " + dropped.toString());

        xferData = new StringBuffer(dropped.toString());
      } else if (dropped instanceof String) {
        JConfig.log().logVerboseDebug("Dropped a String");
        xferData = new StringBuffer((String) dropped);
      }

      return (xferData);
    }
    return null;
  }
コード例 #4
0
ファイル: BaseXLayout.java プロジェクト: adrianber/basex
 /**
  * Returns the contents of the specified transferable.
  *
  * @param tr transferable
  * @return contents
  */
 @SuppressWarnings("unchecked")
 public static ArrayList<Object> contents(final Transferable tr) {
   final ArrayList<Object> list = new ArrayList<>();
   try {
     if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
       for (final File fl : (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor))
         list.add(fl);
     } else if (tr.isDataFlavorSupported(DataFlavor.stringFlavor)) {
       list.add(tr.getTransferData(DataFlavor.stringFlavor));
     }
   } catch (final Exception ex) {
     Util.stack(ex);
   }
   return list;
 }
コード例 #5
0
 private DropData convertEventIntoDropData(DropTargetDropEvent dropTargetDropEvent) {
   Transferable transferable = dropTargetDropEvent.getTransferable();
   Point tableLocation = getTableLocationForEvent(dropTargetDropEvent);
   if (null != _underlyingTable.getValueAt(tableLocation.x, tableLocation.y)) {
     return null;
   }
   Instance entry;
   try {
     entry = (Instance) transferable.getTransferData(_flavor);
   } catch (Exception e) {
     return null;
   }
   if ((null == entry) || !entry.hasType(_entryCls)) {
     return null;
   }
   return new DropData(tableLocation, entry);
 }
コード例 #6
0
ファイル: JDropListener.java プロジェクト: lmop/jbidwatcher
 private boolean testFlavor(DataFlavor inFlavor, Transferable t) {
   if (inFlavor != null) {
     if (t.isDataFlavorSupported(inFlavor)) {
       JConfig.log().logVerboseDebug("Accepting(2): " + inFlavor.getMimeType());
       return true;
     }
   }
   return false;
 }
コード例 #7
0
  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();
    }
  }
コード例 #8
0
ファイル: MainPanel.java プロジェクト: mhcrnl/java-swing-tips
 @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();
 }
コード例 #9
0
ファイル: JDropListener.java プロジェクト: lmop/jbidwatcher
  private void dumpFlavorsOld(Transferable t) {
    DataFlavor[] dfa = t.getTransferDataFlavors();

    if (dfa != null) {
      if (dfa.length == 0) {
        JConfig.log().logVerboseDebug("Trying a second attack...");
        try {
          Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
          Transferable t2 = sysClip.getContents(null);
          StringBuffer stBuff;

          stBuff = getTransferData(t2);
          JConfig.log().logVerboseDebug("Check out: " + stBuff);
        } catch (Exception e) {
          JConfig.log().handleException("Caught: " + e, e);
        }
        JConfig.log().logVerboseDebug("Done trying a second attack...");
      }
    }
    dumpDataFlavors(dfa);
  }
コード例 #10
0
ファイル: JDropListener.java プロジェクト: lmop/jbidwatcher
  public void drop(DropTargetDropEvent dtde) {
    Transferable t = dtde.getTransferable();
    StringBuffer dropData = null;
    DataFlavor dtf;

    JConfig.log().logVerboseDebug("Dropping!");

    if (t.getTransferDataFlavors().length == 0) {
      Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t2 = sysClip.getContents(null);
      DataFlavor[] dfa2;
      int j;

      JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard.");
      dfa2 = null;

      if (t2 != null) {
        JConfig.log().logVerboseDebug("t2 is not null: " + t2);
        dfa2 = t2.getTransferDataFlavors();
        JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!");
      } else {
        JConfig.log().logVerboseDebug("t2 is null!");
      }

      if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) {
        if (dfa2 != null) {
          if (dfa2.length == 0) {
            JConfig.log().logVerboseDebug("Length is still zero!");
          }
          for (j = 0; j < dfa2.length; j++) {
            JConfig.log()
                .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName());
            JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType());
          }
        } else {
          JConfig.log().logVerboseDebug("Flavahs supported: none!\n");
        }
      }
    }

    if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
      dumpFlavorsOld(t);

    dtf = testAllFlavors(t);
    if (dtf != null) {
      JConfig.log().logVerboseDebug("Accepting!");
      acceptDrop(dtde);

      dropData = getTransferData(t);
      dtde.dropComplete(true);
      dtde.getDropTargetContext().dropComplete(true);
      if (dropData != null) {
        if (handler != null) {
          handler.receiveDropString(dropData);
        }
      }
    } else {
      JConfig.log().logVerboseDebug("Rejecting!");
      dtde.rejectDrop();
      handler.receiveDropString(dropData);
    }
  }