Merge remote-tracking branch 'origin/merge/JAL-845_JAL-1640' into
[jalview.git] / src / jalview / gui / AlignViewport.java
index 6ea8df1..6208597 100644 (file)
@@ -60,7 +60,6 @@ import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.util.MessageManager;
-import jalview.util.StringUtils;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.AutoCalcSetting;
 
@@ -107,11 +106,11 @@ public class AlignViewport extends AlignmentViewport implements
 
   boolean antiAlias = false;
 
-  Rectangle explodedPosition;
+  private Rectangle explodedGeometry;
 
   String viewName;
 
-  boolean gatherViewsHere = false;
+  private boolean gatherViewsHere = false;
 
   private Deque<CommandI> historyList = new ArrayDeque<CommandI>();
 
@@ -276,7 +275,7 @@ public class AlignViewport extends AlignmentViewport implements
       style = 2;
     }
 
-    setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
+    setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
 
     alignment
             .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
@@ -467,12 +466,13 @@ public class AlignViewport extends AlignmentViewport implements
   boolean validCharWidth;
 
   /**
-   * DOCUMENT ME!
+   * update view settings with the given font. You may need to call
+   * alignPanel.fontChanged to update the layout geometry
    * 
-   * @param f
-   *          DOCUMENT ME!
+   * @param setGrid
+   *          when true, charWidth/height is set according to font mentrics
    */
-  public void setFont(Font f)
+  public void setFont(Font f, boolean setGrid)
   {
     font = f;
 
@@ -481,13 +481,9 @@ public class AlignViewport extends AlignmentViewport implements
     java.awt.FontMetrics fm = c.getFontMetrics(font);
     int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
             .getCharHeight();
-    // only update width/height if the new font won't fit
-    if (h < fm.getHeight())
+    if (setGrid)
     {
       setCharHeight(fm.getHeight());
-    }
-    if (w < ww)
-    {
       setCharWidth(ww);
     }
     viewStyle.setFontName(font.getName());
@@ -502,7 +498,7 @@ public class AlignViewport extends AlignmentViewport implements
   {
     super.setViewStyle(settingsForView);
     setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
-            viewStyle.getFontSize()));
+            viewStyle.getFontSize()), false);
 
   }
   /**
@@ -1000,6 +996,10 @@ public class AlignViewport extends AlignmentViewport implements
   {
     // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
 
+    // JBPComment: title is a largely redundant parameter at the moment
+    // JBPComment: this really should be an 'insert/pre/append' controller
+    // JBPComment: but the DNA/Protein check makes it a bit more complex
+
     // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
     // this comment:
     // TODO: create undo object for this JAL-1101
@@ -1010,6 +1010,7 @@ public class AlignViewport extends AlignmentViewport implements
      */
     if (getAlignment().isNucleotide() != al.isNucleotide())
     {
+      // TODO: JAL-845 try a bit harder to link up imported sequences
       final Set<String> sequenceNames = getAlignment().getSequenceNames();
       sequenceNames.retainAll(al.getSequenceNames());
       if (!sequenceNames.isEmpty()) // at least one sequence name in both
@@ -1020,6 +1021,8 @@ public class AlignViewport extends AlignmentViewport implements
         }
       }
     }
+    // TODO: JAL-407 regardless of above - identical sequences (based on ID and
+    // provenance) should share the same dataset sequence
 
     for (int i = 0; i < al.getHeight(); i++)
     {
@@ -1027,6 +1030,8 @@ public class AlignViewport extends AlignmentViewport implements
     }
     // TODO this call was done by SequenceFetcher but not FileLoader or
     // CutAndPasteTransfer. Is it needed?
+    // JBPComment: this repositions the view to show the new sequences
+    // JBPComment: so it is needed for UX
     setEndSeq(getAlignment().getHeight());
     firePropertyChange("alignment", null, getAlignment().getSequences());
   }
@@ -1123,6 +1128,8 @@ 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.
        */
@@ -1138,16 +1145,14 @@ public class AlignViewport extends AlignmentViewport implements
       cdnaFrame.setVisible(true);
       proteinFrame.setVisible(true);
       String sep = String.valueOf(File.separatorChar);
-      String proteinShortName = StringUtils.getLastToken(
-              proteinFrame.getTitle(), sep);
-      String dnaShortName = StringUtils.getLastToken(cdnaFrame.getTitle(),
-              sep);
+      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);
+      Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
 
       /*
        * Set the frames to listen for each other's edit and sort commands.
@@ -1197,4 +1202,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;
+  }
 }