Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DragAndDrop.java
1 package ij.plugin;
2 import ij.*;
3 import ij.io.*;
4 import java.io.*;
5 import java.awt.datatransfer.*;
6 import java.awt.dnd.*;
7 import java.util.List;
8 import java.util.Iterator;
9 
12 public class DragAndDrop implements PlugIn, DropTargetListener {
13  protected static ImageJ ij = null; // the "ImageJ" frame
14  private static boolean enableDND = true;
15  protected DataFlavor dFlavor;
16 
17  public void run(String arg) {
18  String vers = System.getProperty("java.version");
19  if (vers.compareTo("1.3.1") < 0)
20  return;
21  ij = IJ.getInstance();
22  ij.setDropTarget(null);
23  DropTarget dropTarget = new DropTarget(ij, this);
24  }
25 
26  public void drop(DropTargetDropEvent dtde) {
27  dtde.acceptDrop(DnDConstants.ACTION_COPY);
28  try {
29  Transferable t = dtde.getTransferable();
30  if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
31  Object data = t.getTransferData(DataFlavor.javaFileListFlavor);
32  Iterator iterator = ((List)data).iterator();
33  while(iterator.hasNext()) {
34  File file = (File)iterator.next();
35  new Opener().open(file.getAbsolutePath());
36  }
37  }
38  }
39  catch(Exception e) {
40  dtde.dropComplete(false);
41  return;
42  }
43  dtde.dropComplete(true);
44  }
45 
46  public void dragEnter(DropTargetDragEvent dtde) {
47  dtde.acceptDrag(DnDConstants.ACTION_COPY);
48  }
49 
50  public void dragOver(DropTargetDragEvent e) {}
51  public void dragExit(DropTargetEvent e) {}
52  public void dropActionChanged(DropTargetDragEvent e) {}
53 }
54 
55 
56