JAL-3032 DND enabled; additional io changes for File vs. String
[jalview.git] / src / jalview / gui / AlignFrame.java
index a27b495..2587866 100644 (file)
@@ -81,6 +81,7 @@ import jalview.io.JnetAnnotationMaker;
 import jalview.io.NewickFile;
 import jalview.io.ScoreMatrixFile;
 import jalview.io.TCoffeeScoreFile;
+import jalview.io.vcf.VCFLoader;
 import jalview.jbgui.GAlignFrame;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
@@ -121,6 +122,7 @@ import java.awt.event.MouseEvent;
 import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
@@ -135,6 +137,7 @@ import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JEditorPane;
+import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
@@ -149,7 +152,8 @@ import javax.swing.SwingUtilities;
  * @version $Revision$
  */
 public class AlignFrame extends GAlignFrame implements DropTargetListener,
-        IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
+        IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener,
+        PropertyChangeListener
 {
 
   public static final int DEFAULT_WIDTH = 700;
@@ -323,6 +327,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     init();
   }
 
+  @Override
+  public void propertyChange(PropertyChangeEvent evt)
+  {
+    Desktop.getDesktop().propertyChange(evt);
+  }
+
   /**
    * initalise the alignframe from the underlying viewport data and the
    * configurations
@@ -377,7 +387,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (Desktop.desktop != null)
     {
       this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
+      /**
+       * BH 2018 ignore service listeners
+       * 
+       * @j2sNative
+       * 
+       */
+      {
       addServiceListeners();
+      }
       setGUINucleotide();
     }
 
@@ -839,6 +857,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     AlignmentI al = getViewport().getAlignment();
     boolean nucleotide = al.isNucleotide();
 
+    loadVcf.setVisible(nucleotide);
     showTranslation.setVisible(nucleotide);
     showReverse.setVisible(nucleotide);
     showReverseComplement.setVisible(nucleotide);
@@ -1111,6 +1130,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     int value = chooser.showSaveDialog(this);
 
+
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
       currentFileFormat = chooser.getSelectedFormat();
@@ -1390,13 +1410,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void exportFeatures_actionPerformed(ActionEvent e)
   {
-    new AnnotationExporter().exportFeatures(alignPanel);
+    new AnnotationExporter(alignPanel).exportFeatures();
   }
 
   @Override
   public void exportAnnotations_actionPerformed(ActionEvent e)
   {
-    new AnnotationExporter().exportAnnotations(alignPanel);
+    new AnnotationExporter(alignPanel).exportAnnotations();
   }
 
   @Override
@@ -1411,14 +1431,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setToolTipText(
             MessageManager.getString("label.load_jalview_annotations"));
 
-    int value = chooser.showOpenDialog(null);
+    Desktop.getDesktop().dialogData = new Object[] { "SelectedFile",
+        new Runnable()
+        {
+
+          @Override
+          public void run()
+          {
+            Object[] data = Desktop.getDesktop().dialogData;
+            int value = ((Integer) data[0]).intValue();
+
+            if (value == JFileChooser.APPROVE_OPTION)
+            {
+              JalviewFileChooser chooser = (JalviewFileChooser) data[2];
+              String choice = chooser.getSelectedFile().getPath();
+              jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+              loadJalviewDataFile(choice, null, null, null);
+            }
+          }
+
+        }, chooser };
+
+    chooser.showOpenDialog(null);
+
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-      loadJalviewDataFile(choice, null, null, null);
-    }
 
   }
 
@@ -1826,7 +1862,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void copy_actionPerformed(ActionEvent e)
   {
-    System.gc();
     if (viewport.getSelectionGroup() == null)
     {
       return;
@@ -4250,7 +4285,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
           final String source)
   {
-    new Thread(CrossRefAction.showProductsFor(sel, _odna, source, this))
+    new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
             .start();
   }
 
@@ -4324,13 +4359,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Try to load a features file onto the alignment.
    * 
    * @param file
-   *          contents or path to retrieve file
+   *          contents or path to retrieve file or a File object
    * @param sourceType
    *          access mode of file (see jalview.io.AlignFile)
    * @return true if features file was parsed correctly.
    */
-  public boolean parseFeaturesFile(String file, DataSourceType sourceType)
+  public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
   {
+    // BH 2018 
     return avc.parseFeaturesFile(file, sourceType,
             Cache.getDefault("RELAXEDSEQIDMATCHING", false));
 
@@ -4377,8 +4413,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // Java's Transferable for native dnd
     evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
     Transferable t = evt.getTransferable();
+    
+    
     final AlignFrame thisaf = this;
-    final List<String> files = new ArrayList<>();
+    final List<Object> files = new ArrayList<>();
     List<DataSourceType> protocols = new ArrayList<>();
 
     try
@@ -4406,20 +4444,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<String> filesnotmatched = new ArrayList<>();
+            ArrayList<Object> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
-              String file = files.get(i).toString();
+              // BH 2018 
+              Object file = files.get(i);
+              String fileName = file.toString();
               String pdbfn = "";
-              DataSourceType protocol = FormatAdapter.checkProtocol(file);
+              DataSourceType protocol = (file instanceof File ? DataSourceType.FILE : FormatAdapter.checkProtocol(fileName));
               if (protocol == DataSourceType.FILE)
               {
-                File fl = new File(file);
+                File fl = (file instanceof File ? (File) file : new File(fileName));
                 pdbfn = fl.getName();
               }
               else if (protocol == DataSourceType.URL)
               {
-                URL url = new URL(file);
+                URL url = new URL(fileName);
                 pdbfn = url.getFile();
               }
               if (pdbfn.length() > 0)
@@ -4441,7 +4481,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 if (mtch != null)
                 {
-                  FileFormatI type = null;
+                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4532,7 +4572,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (String fn : filesnotmatched)
+              for (Object fn : filesnotmatched)
               {
                 loadJalviewDataFile(fn, null, null, null);
               }
@@ -4559,9 +4599,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param file
    *          either a filename or a URL string.
    */
-  public void loadJalviewDataFile(String file, DataSourceType sourceType,
+  public void loadJalviewDataFile(Object file, DataSourceType sourceType,
           FileFormatI format, SequenceI assocSeq)
   {
+    // BH 2018 was String file
     try
     {
       if (sourceType == null)
@@ -5588,6 +5629,28 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       new CalculationChooser(AlignFrame.this);
     }
   }
+
+  @Override
+  protected void loadVcf_actionPerformed()
+  {
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            Cache.getProperty("LAST_DIRECTORY"));
+    chooser.setFileView(new JalviewFileView());
+    chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
+    chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
+
+    int value = chooser.showOpenDialog(null);
+
+    if (value == JalviewFileChooser.APPROVE_OPTION)
+    {
+      String choice = chooser.getSelectedFile().getPath();
+      Cache.setProperty("LAST_DIRECTORY", choice);
+      SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
+      new VCFLoader(choice).loadVCF(seqs, this);
+    }
+
+  }
+
 }
 
 class PrintThread extends Thread