JAL-1674 update both status bars when mousing over linked sequences
[jalview.git] / src / jalview / gui / AlignViewport.java
index feeb694..8fc10d7 100644 (file)
@@ -67,10 +67,7 @@ import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Rectangle;
-import java.io.File;
-import java.util.ArrayDeque;
 import java.util.ArrayList;
-import java.util.Deque;
 import java.util.Hashtable;
 import java.util.Set;
 import java.util.Vector;
@@ -85,7 +82,7 @@ import javax.swing.JOptionPane;
  * @version $Revision: 1.141 $
  */
 public class AlignViewport extends AlignmentViewport implements
-        SelectionSource, VamsasSource, AlignViewportI, CommandListener
+        SelectionSource, AlignViewportI, CommandListener
 {
   int startRes;
 
@@ -106,15 +103,11 @@ public class AlignViewport extends AlignmentViewport implements
 
   boolean antiAlias = false;
 
-  Rectangle explodedPosition;
+  private Rectangle explodedGeometry;
 
   String viewName;
 
-  boolean gatherViewsHere = false;
-
-  private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
-
-  private Deque<CommandI> redoList = new ArrayDeque<CommandI>();
+  private boolean gatherViewsHere = false;
 
   private AnnotationColumnChooser annotationColumnSelectionState;
   /**
@@ -762,6 +755,10 @@ public class AlignViewport extends AlignmentViewport implements
     }
   }
 
+  /**
+   * Returns the (Desktop) instance of the StructureSelectionManager
+   */
+  @Override
   public StructureSelectionManager getStructureSelectionManager()
   {
     return StructureSelectionManager
@@ -891,8 +888,8 @@ public class AlignViewport extends AlignmentViewport implements
           StructureSelectionManager ssm, VamsasSource source)
   {
     /*
-     * ...work in progress... do nothing unless we are a 'complement' of the
-     * source May replace this with direct calls not via SSM.
+     * Do nothing unless we are a 'complement' of the source. May replace this
+     * with direct calls not via SSM.
      */
     if (source instanceof AlignViewportI
             && ((AlignViewportI) source).getCodingComplement() == this)
@@ -914,76 +911,6 @@ public class AlignViewport extends AlignmentViewport implements
     }
   }
 
-  @Override
-  public VamsasSource getVamsasSource()
-  {
-    return this;
-  }
-
-  /**
-   * Add one command to the command history list.
-   * 
-   * @param command
-   */
-  public void addToHistoryList(CommandI command)
-  {
-    if (this.historyList != null)
-    {
-      this.historyList.push(command);
-      broadcastCommand(command, false);
-    }
-  }
-
-  protected void broadcastCommand(CommandI command, boolean undo)
-  {
-    getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
-  }
-
-  /**
-   * Add one command to the command redo list.
-   * 
-   * @param command
-   */
-  public void addToRedoList(CommandI command)
-  {
-    if (this.redoList != null)
-    {
-      this.redoList.push(command);
-    }
-    broadcastCommand(command, true);
-  }
-
-  /**
-   * Clear the command redo list.
-   */
-  public void clearRedoList()
-  {
-    if (this.redoList != null)
-    {
-      this.redoList.clear();
-    }
-  }
-
-  public void setHistoryList(Deque<CommandI> list)
-  {
-    this.historyList = list;
-  }
-
-  public Deque<CommandI> getHistoryList()
-  {
-    return this.historyList;
-  }
-
-  public void setRedoList(Deque<CommandI> list)
-  {
-    this.redoList = list;
-  }
-
-  public Deque<CommandI> getRedoList()
-  {
-    return this.redoList;
-  }
-
   /**
    * Add the sequences from the given alignment to this viewport. Optionally,
    * may give the user the option to open a new frame, or split panel, with cDNA
@@ -1103,8 +1030,6 @@ public class AlignViewport extends AlignmentViewport implements
      * added to the protein alignment.
      */
     MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, cdna);
-    final StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
     if (mapped != MappingResult.Mapped)
     {
       /*
@@ -1128,57 +1053,72 @@ public class AlignViewport extends AlignmentViewport implements
 
     if (openSplitPane)
     {
-      // TODO: move this kind of constructor stuff to a factory/controller
-      // method ?
-      /*
-       * Open in split pane. DNA sequence above, protein below.
-       */
-      AlignFrame copyMe = new AlignFrame(thisAlignment,
-              AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
-      copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
-      final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
-              : newAlignFrame;
-      final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
-              : copyMe;
-      protein = proteinFrame.viewport.getAlignment();
-
-      cdnaFrame.setVisible(true);
-      proteinFrame.setVisible(true);
-      String sep = String.valueOf(File.separatorChar);
-      String proteinShortName = proteinFrame.getTitle().substring(
-              proteinFrame.getTitle().lastIndexOf(sep) + 1);
-      String dnaShortName = cdnaFrame.getTitle().substring(
-              cdnaFrame.getTitle().lastIndexOf(sep) + 1);
-      String linkedTitle = MessageManager.formatMessage(
-              "label.linked_view_title", dnaShortName, proteinShortName);
-      JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
-      Desktop.addInternalFrame(splitFrame, linkedTitle,
-              AlignFrame.DEFAULT_WIDTH,
-              AlignFrame.DEFAULT_HEIGHT);
-
-      /*
-       * Set the frames to listen for each other's edit and sort commands.
-       */
-      ssm.addCommandListener(cdnaFrame.getViewport());
-      ssm.addCommandListener(proteinFrame.getViewport());
-
-      /*
-       * 'Coding complement' (dna/protein) views will mirror each others' edits,
-       * selections, sorting etc as decided from time to time by the relevant
-       * authorities.
-       */
-      proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
+      protein = openSplitFrame(newAlignFrame, thisAlignment);
     }
 
     /*
      * Register the mappings (held on the protein alignment) with the
      * StructureSelectionManager (for mouseover linking).
      */
+    final StructureSelectionManager ssm = StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance);
     ssm.addMappings(protein.getCodonFrames());
 
     return true;
   }
 
+  /**
+   * Helper method to open a new SplitFrame holding linked dna and protein
+   * alignments.
+   * 
+   * @param newAlignFrame
+   *          containing a new alignment to be shown
+   * @param existingAlignment
+   *          an existing alignment to be copied for display in the split frame
+   * @return the protein alignment in the split frame
+   */
+  protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
+          AlignmentI existingAlignment)
+  {
+    // TODO: move this to a factory/controller method ?
+    /*
+     * Open in split pane. DNA sequence above, protein below.
+     */
+    AlignFrame copyMe = new AlignFrame(existingAlignment,
+            AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+    copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
+
+    AlignmentI al = newAlignFrame.viewport.getAlignment();
+    final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
+            : newAlignFrame;
+    final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
+            : copyMe;
+    AlignmentI protein = proteinFrame.viewport.getAlignment();
+
+    cdnaFrame.setVisible(true);
+    proteinFrame.setVisible(true);
+    String linkedTitle = MessageManager
+            .getString("label.linked_view_title");
+    JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
+    Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
+
+    /*
+     * Set the frames to listen for each other's edit and sort commands.
+     */
+    final StructureSelectionManager ssm = StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance);
+    ssm.addCommandListener(cdnaFrame.getViewport());
+    ssm.addCommandListener(proteinFrame.getViewport());
+
+    /*
+     * 'Coding complement' (dna/protein) views will mirror each others' edits,
+     * selections, sorting etc as decided from time to time by the relevant
+     * authorities.
+     */
+    proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
+    return protein;
+  }
+
   public AnnotationColumnChooser getAnnotationColumnSelectionState()
   {
     return annotationColumnSelectionState;
@@ -1204,4 +1144,24 @@ public class AlignViewport extends AlignmentViewport implements
       getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
     }
   }
+
+  public Rectangle getExplodedGeometry()
+  {
+    return explodedGeometry;
+  }
+
+  public void setExplodedGeometry(Rectangle explodedPosition)
+  {
+    this.explodedGeometry = explodedPosition;
+  }
+
+  public boolean isGatherViewsHere()
+  {
+    return gatherViewsHere;
+  }
+
+  public void setGatherViewsHere(boolean gatherViewsHere)
+  {
+    this.gatherViewsHere = gatherViewsHere;
+  }
 }