JAL-1830 dropped reference counts for mappings, instead remove mapping
[jalview.git] / src / jalview / gui / AlignFrame.java
index d2e247f..afa6847 100644 (file)
@@ -37,6 +37,7 @@ import jalview.api.SplitContainerI;
 import jalview.api.ViewStyleI;
 import jalview.api.analysis.ScoreModelI;
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.commands.CommandI;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
@@ -335,7 +336,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   void init()
   {
-    progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+    if (!Jalview.isHeadlessMode())
+    {
+      progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+    }
 
     avc = new jalview.controller.AlignViewController(this, viewport,
             alignPanel);
@@ -1135,8 +1139,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         warningMessage("Cannot save file " + fileName + " using format "
                 + format, "Alignment output format not supported");
-        saveAs_actionPerformed(null);
-        // JBPNote need to have a raise_gui flag here
+        if (!Jalview.isHeadlessMode())
+        {
+          saveAs_actionPerformed(null);
+        }
         return false;
       }
 
@@ -1245,7 +1251,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   }
 
-  public static AlignmentExportData getAlignmentForExport(String exportFomat,
+  public static AlignmentExportData getAlignmentForExport(String exportFormat,
           AlignViewportI viewport)
   {
     AlignmentI alignmentToExport = null;
@@ -1262,7 +1268,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
     AlignExportSettings settings = new AlignExportSettings(hasHiddenSeqs,
-            viewport.hasHiddenColumns(), exportFomat);
+            viewport.hasHiddenColumns(), exportFormat);
     settings.isExportAnnotations();
 
     if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
@@ -1285,7 +1291,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return ed;
   }
 
-  private static int[] getStartEnd(int[] aligmentStartEnd,
+  public static int[] getStartEnd(int[] aligmentStartEnd,
           List<int[]> hiddenCols)
   {
     int startPos = aligmentStartEnd[0];
@@ -1297,7 +1303,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     for (int[] hiddenCol : hiddenCols)
     {
       // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
-
       lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
       higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
     }
@@ -1492,6 +1497,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       if (closeAllTabs)
       {
+        /*
+         * this will raise an INTERNAL_FRAME_CLOSED event and this method will
+         * be called recursively, with the frame now in 'closed' state
+         */
         this.setClosed(true);
       }
     } catch (Exception ex)
@@ -1822,9 +1831,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               viewport.getSelectionGroup().getEndRes() + groupAdjustment);
     }
 
+    /*
+     * just extend the last slide command if compatible; but not if in
+     * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
+     */
     boolean appendHistoryItem = false;
     Deque<CommandI> historyList = viewport.getHistoryList();
-    if (historyList != null
+    boolean inSplitFrame = getSplitViewContainer() != null;
+    if (!inSplitFrame && historyList != null
             && historyList.size() > 0
             && historyList.peek() instanceof SlideSequencesCommand)
     {
@@ -2739,12 +2753,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     /*
-     * Views share the same edits, undo and redo stacks, mappings.
+     * Views share the same edits undo and redo stacks
      */
     newap.av.setHistoryList(viewport.getHistoryList());
     newap.av.setRedoList(viewport.getRedoList());
-    newap.av.getAlignment().setCodonFrames(
-            viewport.getAlignment().getCodonFrames());
+
+    /*
+     * Views share the same mappings; need to deregister any new mappings
+     * created by copyAlignPanel, and register the new reference to the shared
+     * mappings
+     */
+    newap.av.replaceMappings(viewport.getAlignment());
 
     newap.av.viewName = getNewViewName(viewTitle);
 
@@ -4850,7 +4869,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
             // temporary flag until SplitFrame is released
             boolean asSplitFrame = Cache.getDefault(
-                    Preferences.ENABLE_SPLIT_FRAME, false);
+                    Preferences.ENABLE_SPLIT_FRAME, true);
             if (asSplitFrame)
             {
               /*
@@ -4868,7 +4887,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 al.getCodonFrames().addAll(cf);
                 final StructureSelectionManager ssm = StructureSelectionManager
                         .getStructureSelectionManager(Desktop.instance);
-                ssm.addMappings(cf);
+                ssm.registerMappings(cf);
               }
               else
               {
@@ -4958,10 +4977,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "Exception during translation. Please report this !", ex);
       final String msg = MessageManager
               .getString("label.error_when_translating_sequences_submit_bug_report");
-      final String title = MessageManager
+      final String errorTitle = MessageManager
               .getString("label.implementation_error")
               + MessageManager.getString("translation_failed");
-      JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+      JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
               JOptionPane.ERROR_MESSAGE);
       return;
     }
@@ -4969,9 +4988,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       final String msg = MessageManager
               .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
-      final String title = MessageManager
+      final String errorTitle = MessageManager
               .getString("label.translation_failed");
-      JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+      JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
               JOptionPane.WARNING_MESSAGE);
     }
     else
@@ -4982,11 +5001,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "label.translation_of_params", new Object[]
               { this.getTitle() });
       af.setTitle(newTitle);
-      if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
+      if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
         final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-        viewport.openSplitFrame(af, new Alignment(seqs),
-                al.getCodonFrames());
+        viewport.openSplitFrame(af, new Alignment(seqs));
       }
       else
       {
@@ -6078,7 +6096,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       sf.setComplementVisible(this, show);
     }
   }
-
 }
 
 class PrintThread extends Thread