drag and drop files into jalview
authoramwaterhouse <Andrew Waterhouse>
Tue, 22 Mar 2005 12:18:16 +0000 (12:18 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 22 Mar 2005 12:18:16 +0000 (12:18 +0000)
src/jalview/gui/Desktop.java

index 8928acc..336cdd3 100755 (executable)
@@ -16,9 +16,13 @@ import jalview.schemes.*;
 import javax.swing.*;\r
 import java.awt.*;\r
 import java.awt.event.*;\r
+import java.awt.dnd.*;\r
+import javax.swing.*;\r
+import java.awt.datatransfer.*;\r
+import java.io.*;\r
 \r
 \r
-public class Desktop extends jalview.jbgui.GDesktop\r
+public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener\r
 {\r
   public static JDesktopPane desktop;\r
   static int openFrameCount = 0;\r
@@ -76,9 +80,9 @@ public void windowClosing(WindowEvent evt)
  jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");\r
 }\r
 });\r
-      setVisible(true);\r
+setVisible(true);\r
 \r
-/////////Add a splashscreen on startup\r
+this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));\r
 \r
 \r
    /////////Add a splashscreen on startup\r
@@ -144,7 +148,30 @@ public void windowClosing(WindowEvent evt)
    windowMenu.add(menuItem);\r
  }\r
 \r
+ public void dragEnter(DropTargetDragEvent evt){}\r
+ public void dragExit(DropTargetEvent evt){}\r
+ public void dragOver(DropTargetDragEvent evt){}\r
+ public void dropActionChanged(DropTargetDragEvent evt){}\r
+ public void drop(DropTargetDropEvent evt)\r
+{\r
+   Transferable t = evt.getTransferable();\r
+   if(!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))\r
+     return;\r
 \r
+   evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
+   try{\r
+     java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);\r
+\r
+     for (int i = 0; i < files.size(); i++)\r
+     {\r
+       String file = files.get(i).toString();\r
+       String protocol = "File";\r
+       String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
+       LoadFile(file, protocol, format);\r
+     }\r
+\r
+   }catch(Exception ex){ex.printStackTrace();}\r
+  }\r
 \r
  public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
  {\r
@@ -170,7 +197,7 @@ public void windowClosing(WindowEvent evt)
    if (FormatProperties.contains(format))\r
        sequences = FormatAdapter.read(file, protocol, format);\r
 \r
-   if (sequences != null)\r
+   if (sequences != null && sequences.length>0)\r
    {\r
      AlignFrame af = new AlignFrame(new Alignment(sequences));\r
      addInternalFrame(af, file, 700, 500);\r
@@ -196,7 +223,6 @@ public void windowClosing(WindowEvent evt)
 \r
    String format = IdentifyFile.Identify(url, "URL");\r
 \r
-   System.out.println(format +" format");\r
    if (format.equals("URL NOT FOUND"))\r
    {\r
      JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,\r
@@ -261,7 +287,8 @@ public void windowClosing(WindowEvent evt)
                                          "JalView 2005 version " + jalview.bin.Cache.VERSION+"; last updated: "+jalview.bin.Cache.BUILD_DATE\r
                                        +"\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."\r
                                        +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."\r
-                                       +"\nIf  you use JalView, please cite:  \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
+                                       +"\nIf  you use JalView, please cite:  Bioinformatics,  2004 12;426-7."\r
+                                       +"\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
                                          "About Jalview",\r
                                          JOptionPane.INFORMATION_MESSAGE);\r
  }\r