JAL-4331 construct and pass on overview title before asking desktop to open the window…
[jalview.git] / src / jalview / gui / AlignFrame.java
index 7b310b1..c49626b 100644 (file)
@@ -49,6 +49,7 @@ import java.beans.PropertyChangeEvent;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.ArrayList;
@@ -59,7 +60,6 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Locale;
 import java.util.Vector;
-import java.util.concurrent.Callable;
 
 import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
@@ -95,6 +95,7 @@ import jalview.api.analysis.SimilarityParamsI;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.bin.Jalview;
+import jalview.bin.groovy.JalviewObjectI;
 import jalview.commands.CommandI;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
@@ -112,6 +113,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentOrder;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.ContactMatrixI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SeqCigar;
@@ -140,6 +142,7 @@ import jalview.io.JnetAnnotationMaker;
 import jalview.io.NewickFile;
 import jalview.io.ScoreMatrixFile;
 import jalview.io.TCoffeeScoreFile;
+import jalview.io.exceptions.ImageOutputException;
 import jalview.io.vcf.VCFLoader;
 import jalview.jbgui.GAlignFrame;
 import jalview.project.Jalview2XML;
@@ -151,6 +154,7 @@ import jalview.util.HttpUtils;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
+import jalview.util.imagemaker.BitmapImageSizing;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
@@ -500,7 +504,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       @Override
       public void focusGained(FocusEvent e)
       {
-        Jalview.setCurrentAlignFrame(AlignFrame.this);
+        Jalview.getInstance().setCurrentAlignFrame(AlignFrame.this);
       }
     });
 
@@ -621,12 +625,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         // if (viewport.cursorMode)
         // {
         // alignPanel.seqPanel.insertNucAtCursor(false,"A");
-        // //System.out.println("A");
+        // //jalview.bin.Console.outPrintln("A");
         // }
         // break;
         /*
          * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
-         * System.out.println("closing bracket"); } break;
+         * jalview.bin.Console.outPrintln("closing bracket"); } break;
          */
         case KeyEvent.VK_DELETE:
         case KeyEvent.VK_BACK_SPACE:
@@ -827,7 +831,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               @Override
               public void propertyChange(PropertyChangeEvent evt)
               {
-                // // System.out.println("Discoverer property change.");
+                // // jalview.bin.Console.outPrintln("Discoverer property
+                // change.");
                 // if (evt.getPropertyName().equals("services"))
                 {
                   SwingUtilities.invokeLater(new Runnable()
@@ -836,7 +841,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     @Override
                     public void run()
                     {
-                      System.err.println(
+                      jalview.bin.Console.errPrintln(
                               "Rebuild WS Menu for service change");
                       BuildWebServiceMenu();
                     }
@@ -851,7 +856,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       public void internalFrameClosed(
               javax.swing.event.InternalFrameEvent evt)
       {
-        // System.out.println("deregistering discoverer listener");
+        // jalview.bin.Console.outPrintln("deregistering discoverer listener");
         Desktop.instance.removeJalviewPropertyChangeListener("services",
                 thisListener);
         closeMenuItem_actionPerformed(true);
@@ -980,7 +985,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void setProgressBar(String message, long id)
   {
-    if (!Platform.isHeadless())
+    if (!Platform.isHeadless() && progressBar != null)
       progressBar.setProgressBar(message, id);
   }
 
@@ -988,7 +993,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void registerHandler(final long id,
           final IProgressIndicatorHandler handler)
   {
-    progressBar.registerHandler(id, handler);
+    if (progressBar != null)
+      progressBar.registerHandler(id, handler);
   }
 
   /**
@@ -998,7 +1004,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public boolean operationInProgress()
   {
-    return progressBar.operationInProgress();
+    return progressBar == null ? false : progressBar.operationInProgress();
   }
 
   /**
@@ -1247,8 +1253,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void saveAlignment(String file, FileFormatI format)
   {
+    saveAlignment(file, format, false, false);
+  }
+
+  public void saveAlignment(String file, FileFormatI format, boolean stdout,
+          boolean forceBackup)
+  {
     lastSaveSuccessful = true;
-    lastFilenameSaved = file;
+    if (!stdout)
+    {
+      lastFilenameSaved = file;
+    }
     lastFormatSaved = format;
 
     if (FileFormat.Jalview.equals(format))
@@ -1259,6 +1274,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         shortName = shortName
                 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
       }
+      // TODO deal with stdout=true
       lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
               shortName);
 
@@ -1276,11 +1292,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
-    Callable<Void> cancelAction = () -> {
+    Runnable cancelAction = () -> {
       lastSaveSuccessful = false;
-      return null;
     };
-    Callable<Void> outputAction = () -> {
+    Runnable outputAction = () -> {
       // todo defer this to inside formatSequences (or later)
       AlignmentExportData exportData = viewport.getAlignExportData(options);
       String output = new FormatAdapter(alignPanel, options)
@@ -1295,7 +1310,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       else
       {
         // create backupfiles object and get new temp filename destination
-        boolean doBackup = BackupFiles.getEnabled();
+        boolean doBackup = forceBackup
+                || (BackupFiles.getEnabled() && !stdout);
         BackupFiles backupfiles = null;
         if (doBackup)
         {
@@ -1307,7 +1323,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           String tempFilePath = doBackup ? backupfiles.getTempFilePath()
                   : file;
           Console.trace("ALIGNFRAME setting PrintWriter");
-          PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
+          PrintWriter out = stdout
+                  ? new PrintWriter(new OutputStreamWriter(System.out))
+                  : new PrintWriter(new FileWriter(tempFilePath));
 
           if (backupfiles != null)
           {
@@ -1316,13 +1334,28 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
 
           out.print(output);
-          Console.trace("ALIGNFRAME about to close file");
-          out.close();
-          Console.trace("ALIGNFRAME closed file");
-          AlignFrame.this.setTitle(file);
-          statusBar.setText(MessageManager.formatMessage(
-                  "label.successfully_saved_to_file_in_format", new Object[]
-                  { fileName, format.getName() }));
+          out.flush();
+          if (!stdout)
+          {
+            Console.trace("ALIGNFRAME about to close file");
+            out.close();
+            Console.trace("ALIGNFRAME closed file");
+          }
+          AlignFrame.this.setTitle(stdout ? "STDOUT" : file);
+          if (stdout)
+          {
+            statusBar.setText(MessageManager.formatMessage(
+                    "label.successfully_printed_to_stdout_in_format",
+                    new Object[]
+                    { format.getName() }));
+          }
+          else
+          {
+            statusBar.setText(MessageManager.formatMessage(
+                    "label.successfully_saved_to_file_in_format",
+                    new Object[]
+                    { fileName, format.getName() }));
+          }
           lastSaveSuccessful = true;
         } catch (IOException e)
         {
@@ -1358,7 +1391,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           AlignFrame.this.getViewport().setSavedUpToDate(true);
         }
       }
-      return null;
     };
 
     /*
@@ -1376,7 +1408,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       try
       {
-        outputAction.call();
+        outputAction.run();
       } catch (Exception e)
       {
         // TODO Auto-generated catch block
@@ -1398,7 +1430,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     FileFormatI fileFormat = FileFormats.getInstance()
             .forName(fileFormatName);
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
-    Callable<Void> outputAction = () -> {
+    Runnable outputAction = () -> {
       // todo defer this to inside formatSequences (or later)
       AlignmentExportData exportData = viewport.getAlignExportData(options);
       CutAndPasteTransfer cap = new CutAndPasteTransfer();
@@ -1420,7 +1452,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 oom);
         cap.dispose();
       }
-      return null;
     };
 
     /*
@@ -1437,7 +1468,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       try
       {
-        outputAction.call();
+        outputAction.run();
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -1455,19 +1486,75 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void htmlMenuItem_actionPerformed(ActionEvent e)
   {
     HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
-    htmlSVG.exportHTML(null);
+    try
+    {
+      htmlSVG.exportHTML(null);
+    } catch (ImageOutputException x)
+    {
+      // report problem to console and raise dialog
+    }
   }
 
   @Override
   public void bioJSMenuItem_actionPerformed(ActionEvent e)
   {
     BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
-    bjs.exportHTML(null);
+    try
+    {
+      bjs.exportHTML(null);
+    } catch (ImageOutputException x)
+    {
+      // report problem to console and raise dialog
+    }
   }
 
   public void createImageMap(File file, String image)
   {
-    alignPanel.makePNGImageMap(file, image);
+    try
+    {
+      alignPanel.makePNGImageMap(file, image);
+    } catch (ImageOutputException x)
+    {
+      // report problem to console and raise dialog
+    }
+  }
+
+  @Override
+  public void createPNG_actionPerformed(ActionEvent e)
+  {
+    try
+    {
+      createPNG(null);
+    } catch (ImageOutputException ioex)
+    {
+      // raise dialog, and report via console
+    }
+  }
+
+  @Override
+  public void createEPS_actionPerformed(ActionEvent e)
+  {
+    try
+    {
+      createEPS(null);
+    } catch (ImageOutputException ioex)
+    {
+      // raise dialog, and report via console
+    }
+
+  }
+
+  @Override
+  public void createSVG_actionPerformed(ActionEvent e)
+  {
+    try
+    {
+      createSVG(null);
+    } catch (ImageOutputException ioex)
+    {
+      // raise dialog, and report via console
+    }
+
   }
 
   /**
@@ -1476,10 +1563,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param f
    */
-  @Override
-  public void createPNG(File f)
+  public void createPNG(File f) throws ImageOutputException
+  {
+    createPNG(f, null, BitmapImageSizing.defaultBitmapImageSizing());
+  }
+
+  public void createPNG(File f, String renderer, BitmapImageSizing userBis)
+          throws ImageOutputException
   {
-    alignPanel.makeAlignmentImage(TYPE.PNG, f);
+    alignPanel.makeAlignmentImage(TYPE.PNG, f, renderer, userBis);
   }
 
   /**
@@ -1488,10 +1580,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param f
    */
-  @Override
-  public void createEPS(File f)
+  public void createEPS(File f) throws ImageOutputException
   {
-    alignPanel.makeAlignmentImage(TYPE.EPS, f);
+    createEPS(f, null);
+  }
+
+  public void createEPS(File f, String renderer) throws ImageOutputException
+  {
+    alignPanel.makeAlignmentImage(TYPE.EPS, f, renderer);
   }
 
   /**
@@ -1500,10 +1596,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param f
    */
-  @Override
-  public void createSVG(File f)
+  public void createSVG(File f) throws ImageOutputException
   {
-    alignPanel.makeAlignmentImage(TYPE.SVG, f);
+    createSVG(f, null);
+  }
+
+  public void createSVG(File f, String renderer) throws ImageOutputException
+  {
+    alignPanel.makeAlignmentImage(TYPE.SVG, f, renderer);
   }
 
   @Override
@@ -1553,7 +1653,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       String choice = chooser.getSelectedFile().getPath();
       Cache.setProperty("LAST_DIRECTORY", choice);
       loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
-      return null;
     });
 
     chooser.showOpenDialog(this);
@@ -1573,6 +1672,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       closeAllTabs = true;
     }
 
+    Desktop.closeModal(this);
+
     try
     {
       if (alignPanels != null)
@@ -1602,6 +1703,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           featureSettings.close();
           featureSettings = null;
         }
+
         /*
          * this will raise an INTERNAL_FRAME_CLOSED event and this method will
          * be called recursively, with the frame now in 'closed' state
@@ -1695,7 +1797,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @return alignment objects for all views
    */
-  AlignmentI[] getViewAlignments()
+  public AlignmentI[] getViewAlignments()
   {
     if (alignPanels != null)
     {
@@ -2285,10 +2387,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         .intValue();
               }
             }
-            alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
-            // was
-            // duplicated
-            // earlier
+            // annotation was duplicated earlier
+            alignment.addAnnotation(sequences[i].getAnnotation()[a]);
+            // take care of contact matrix too
+            ContactMatrixI cm = sequences[i]
+                    .getContactMatrixFor(sequences[i].getAnnotation()[a]);
+            if (cm != null)
+            {
+              alignment.addContactListFor(sequences[i].getAnnotation()[a],
+                      cm);
+            }
+
             alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
                     a);
           }
@@ -2396,7 +2505,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     } catch (Exception ex)
     {
       ex.printStackTrace();
-      System.out.println("Exception whilst pasting: " + ex);
+      jalview.bin.Console.outPrintln("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     }
 
@@ -2444,7 +2553,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     } catch (Exception ex)
     {
       ex.printStackTrace();
-      System.out.println("Exception whilst pasting: " + ex);
+      jalview.bin.Console.outPrintln("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     } catch (OutOfMemoryError oom)
     {
@@ -2475,7 +2584,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       return;
     }
 
-    Callable okAction = () -> {
+    Runnable okAction = () -> {
       SequenceI[] cut = sg.getSequences()
               .toArray(new SequenceI[sg.getSize()]);
 
@@ -2499,7 +2608,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
         }
       }
-      return null;
     };
 
     /*
@@ -2525,7 +2633,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       try
       {
-        okAction.call();
+        okAction.run();
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -2635,6 +2743,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     viewport.invertColumnSelection();
     alignPanel.paintAlignment(true, false);
+    PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
     viewport.sendSelection();
   }
 
@@ -3080,11 +3189,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void wrapMenuItem_actionPerformed(ActionEvent e)
   {
-    scaleAbove.setVisible(wrapMenuItem.isSelected());
-    scaleLeft.setVisible(wrapMenuItem.isSelected());
-    scaleRight.setVisible(wrapMenuItem.isSelected());
-    viewport.setWrapAlignment(wrapMenuItem.isSelected());
+    setWrapFormat(wrapMenuItem.isSelected(), false);
+  }
+
+  public void setWrapFormat(boolean b, boolean setMenuItem)
+  {
+    scaleAbove.setVisible(b);
+    scaleLeft.setVisible(b);
+    scaleRight.setVisible(b);
+    viewport.setWrapAlignment(b);
     alignPanel.updateLayout();
+    if (setMenuItem)
+    {
+      wrapMenuItem.setSelected(b);
+    }
   }
 
   @Override
@@ -3422,7 +3540,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     JInternalFrame frame = new JInternalFrame();
-
+    frame.setFrameIcon(null);
     frame.getContentPane().add(new JScrollPane(pane));
 
     Desktop.addInternalFrame(frame, MessageManager
@@ -3438,8 +3556,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void overviewMenuItem_actionPerformed(ActionEvent e)
   {
-    boolean showHiddenRegions = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
-                false);
+    boolean showHiddenRegions = Cache
+            .getDefault(Preferences.SHOW_OV_HIDDEN_AT_START, false);
     openOverviewPanel(showHiddenRegions);
   }
 
@@ -3450,14 +3568,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       return alignPanel.overviewPanel;
     }
     JInternalFrame frame = new JInternalFrame();
-    final OverviewPanel overview = new OverviewPanel(alignPanel, frame, showHidden);
-    frame.setContentPane(overview);
-    Desktop.addInternalFrame(frame, "", true, frame.getWidth(), frame.getHeight(),
-            true, true);
     frame.setFrameIcon(null);
+    final OverviewPanel overview = new OverviewPanel(alignPanel, frame,
+            showHidden);
+    frame.setContentPane(overview);
+
+    alignPanel.setOverviewPanel(overview);
+    alignPanel.setOverviewTitle(this);
+
+    Desktop.addInternalFrame(frame, overview.getTitle(), true,
+            frame.getWidth(), frame.getHeight(), true, true);
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
-    final AlignmentPanel thePanel = this.alignPanel; 
+    final AlignmentPanel thePanel = this.alignPanel;
     frame.addInternalFrameListener(
             new javax.swing.event.InternalFrameAdapter()
             {
@@ -3474,9 +3597,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       frame.addKeyListener(getKeyListeners()[0]);
     }
 
-    alignPanel.setOverviewPanel(overview);
-    alignPanel.setOverviewTitle(this);
-    
     return overview;
   }
 
@@ -3728,6 +3848,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     else
     {
       JInternalFrame frame = new JInternalFrame();
+      frame.setFrameIcon(null);
       frame.setContentPane(new PairwiseAlignPanel(viewport));
       Desktop.addInternalFrame(frame,
               MessageManager.getString("action.pairwise_alignment"), 600,
@@ -4115,7 +4236,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         .getString("label.possible_problem_with_tree_file"),
                 JvOptionPane.WARNING_MESSAGE);
       }
-      return null;
     });
     chooser.showOpenDialog(this);
   }
@@ -4181,6 +4301,57 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return tp;
   }
 
+  public void showContactMapTree(AlignmentAnnotation aa, ContactMatrixI cm)
+  {
+    int x = 4, y = 5;
+    int w = 400, h = 500;
+
+    try
+    {
+      NewickFile fin = new NewickFile(
+              new FileParse(cm.getNewick(), DataSourceType.PASTE));
+      String title = aa.label + " " + cm.getTreeMethod() + " tree"
+              + (aa.sequenceRef != null
+                      ? (" for " + aa.sequenceRef.getDisplayId(false))
+                      : "");
+
+      showColumnWiseTree(fin, aa, title, w, h, x, y);
+    } catch (Throwable xx)
+    {
+      Console.error("Unexpected exception showing tree for contact matrix",
+              xx);
+    }
+  }
+
+  public TreePanel showColumnWiseTree(NewickFile nf, AlignmentAnnotation aa,
+          String treeTitle, int w, int h, int x, int y)
+  {
+    try
+    {
+      nf.parse();
+      if (nf.getTree() == null)
+      {
+        return null;
+      }
+      TreePanel tp = new TreePanel(alignPanel, nf, aa, treeTitle);
+
+      tp.setSize(w, h);
+
+      if (x > 0 && y > 0)
+      {
+        tp.setLocation(x, y);
+      }
+
+      Desktop.addInternalFrame(tp, treeTitle, w, h);
+      return tp;
+    } catch (Throwable xx)
+    {
+      Console.error("Unexpected exception showing tree for contact matrix",
+              xx);
+    }
+    return null;
+  }
+
   private boolean buildingMenu = false;
 
   /**
@@ -4193,7 +4364,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       try
       {
-        System.err.println("Waiting for building menu to finish.");
+        jalview.bin.Console
+                .errPrintln("Waiting for building menu to finish.");
         Thread.sleep(10);
       } catch (Exception e)
       {
@@ -4209,7 +4381,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         final List<JMenuItem> legacyItems = new ArrayList<>();
         try
         {
-          // System.err.println("Building ws menu again "
+          // jalview.bin.Console.errPrintln("Building ws menu again "
           // + Thread.currentThread());
           // TODO: add support for context dependent disabling of services based
           // on
@@ -4647,7 +4819,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<Object> filesnotmatched = new ArrayList<>();
+            ArrayList<Object[]> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
               // BH 2018
@@ -4693,9 +4865,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   }
                   mtch = idm.findAllIdMatches(pdbfn);
                 }
+                FileFormatI type = null;
                 if (mtch != null)
                 {
-                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4711,7 +4883,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 // File wasn't named like one of the sequences or wasn't a PDB
                 // file.
-                filesnotmatched.add(file);
+                filesnotmatched.add(new Object[] { file, protocol, type });
               }
             }
             int assocfiles = 0;
@@ -4747,7 +4919,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                                     Desktop.instance);
                     if (pe != null)
                     {
-                      System.err.println("Associated file : "
+                      jalview.bin.Console.errPrintln("Associated file : "
                               + (fm[0].toString()) + " with "
                               + toassoc.getDisplayId(true));
                       assocfiles++;
@@ -4765,7 +4937,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                  */
                 for (Object[] o : filesmatched)
                 {
-                  filesnotmatched.add(o[0]);
+                  filesnotmatched.add(new Object[] { o[0], o[1] });
                 }
               }
             }
@@ -4787,9 +4959,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (Object fn : filesnotmatched)
+              for (Object[] fn : filesnotmatched)
               {
-                loadJalviewDataFile(fn, null, null, null);
+                loadJalviewDataFile(fn[0], (DataSourceType) fn[1],
+                        (FileFormatI) fn[2], null);
               }
 
             }
@@ -4885,7 +5058,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             format = new IdentifyFile().identify(file, sourceType);
           }
-          if (FileFormat.ScoreMatrix == format)
+          if (FileFormat.FeatureSettings == format)
+          {
+            if (featureSettings != null)
+            {
+              featureSettings.load(file, sourceType);
+            }
+            else
+            {
+              FeatureSettings.loadFeatureSettingsFile(getFeatureRenderer(),
+                      fileObject, sourceType);
+            }
+          }
+          else if (FileFormat.ScoreMatrix == format)
           {
             ScoreMatrixFile sm = new ScoreMatrixFile(
                     new FileParse(file, sourceType));
@@ -4974,7 +5159,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
        * to add view name "Original" if necessary
        */
       alignPanel.setOverviewTitle(this);
-      
+
       /*
        * switch panels and set Overview title (if there is one
        * because it was opened automatically)
@@ -5645,7 +5830,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    *          update non-sequence-related annotations
    */
   @Override
-  protected void setAnnotationsVisibility(boolean visible,
+  public void setAnnotationsVisibility(boolean visible,
           boolean forSequences, boolean forAlignment)
   {
     AlignmentAnnotation[] anns = alignPanel.getAlignment()
@@ -5671,6 +5856,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     }
     alignPanel.validateAnnotationDimensions(true);
+    // TODO this triggers relayout of annotation panel - otherwise annotation
+    // label height is different to panel height
+    alignPanel.fontChanged();
     alignPanel.alignmentChanged();
   }
 
@@ -5780,7 +5968,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               viewport.getAlignment()));
     } catch (Exception ex)
     {
-      System.err.println(ex.getMessage());
+      jalview.bin.Console.errPrintln(ex.getMessage());
       return;
     }
   }
@@ -5793,16 +5981,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void runGroovy_actionPerformed()
   {
-    Jalview.setCurrentAlignFrame(this);
-    groovy.ui.Console console = Desktop.getGroovyConsole();
+    Jalview.getInstance().setCurrentAlignFrame(this);
+    groovy.console.ui.Console console = Desktop.getGroovyConsole();
     if (console != null)
     {
       try
       {
+        console.setVariable(JalviewObjectI.currentAlFrameName, this);
         console.runScript();
       } catch (Exception ex)
       {
-        System.err.println((ex.toString()));
+        jalview.bin.Console.errPrintln((ex.toString()));
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                 MessageManager.getString("label.couldnt_run_groovy_script"),
                 MessageManager.getString("label.groovy_support_failed"),
@@ -5811,7 +6000,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     else
     {
-      System.err.println("Can't run Groovy script as console not found");
+      jalview.bin.Console
+              .errPrintln("Can't run Groovy script as console not found");
     }
   }
 
@@ -5911,7 +6101,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       Cache.setProperty("LAST_DIRECTORY", choice);
       SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
       new VCFLoader(choice).loadVCF(seqs, us);
-      return null;
     });
     chooser.showOpenDialog(null);
 
@@ -5930,6 +6119,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     return lastFeatureSettingsBounds;
   }
+
 }
 
 class PrintThread extends Thread