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