JAL-845 set top and bottom seq id widths the same
[jalview.git] / src / jalview / gui / SplitFrame.java
index ab4596e..e441371 100644 (file)
@@ -1,13 +1,13 @@
 package jalview.gui;
 
+import jalview.api.ViewStyleI;
+import jalview.datamodel.AlignmentI;
 import jalview.jbgui.GAlignFrame;
 import jalview.jbgui.GSplitFrame;
 import jalview.structure.StructureSelectionManager;
+import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Component;
-import java.awt.MouseInfo;
-import java.awt.Point;
-import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -25,6 +25,18 @@ import javax.swing.KeyStroke;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
+/**
+ * An internal frame on the desktop that hosts a horizontally split view of
+ * linked DNA and Protein alignments. Additional views can be created in linked
+ * pairs, expanded to separate split frames, or regathered into a single frame.
+ * <p>
+ * (Some) operations on each alignment are automatically mirrored on the other.
+ * These include mouseover (highlighting), sequence and column selection,
+ * sequence ordering and sorting, and grouping, colouring and sorting by tree.
+ * 
+ * @author gmcarstairs
+ *
+ */
 public class SplitFrame extends GSplitFrame
 {
   private static final long serialVersionUID = 1L;
@@ -42,6 +54,8 @@ public class SplitFrame extends GSplitFrame
   {
     setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 20);
 
+    adjustLayout();
+
     addCloseFrameListener();
     
     addKeyListener();
@@ -50,6 +64,39 @@ public class SplitFrame extends GSplitFrame
   }
 
   /**
+   * Do any tweaking and twerking of the layout wanted.
+   */
+  private void adjustLayout()
+  {
+    /*
+     * Ensure sequence ids are the same width for good alignment.
+     */
+    int w1 = ((AlignFrame) getTopFrame()).getViewport().getIdWidth();
+    int w2 = ((AlignFrame) getBottomFrame()).getViewport().getIdWidth();
+    int w3 = Math.max(w1, w2);
+    ((AlignFrame) getTopFrame()).getViewport().setIdWidth(w3);
+    ((AlignFrame) getBottomFrame()).getViewport().setIdWidth(w3);
+
+    /*
+     * Set the character width for protein to 3 times that for dna.
+     */
+    final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
+    final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
+    final AlignmentI topAlignment = topViewport.getAlignment();
+    final AlignmentI bottomAlignment = bottomViewport.getAlignment();
+    AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
+            : (bottomAlignment.isNucleotide() ? bottomViewport : null);
+    AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
+            : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
+    if (protein != null && cdna != null)
+    {
+      ViewStyleI vs = cdna.getViewStyle();
+      vs.setCharWidth(3 * vs.getCharWidth());
+      protein.setViewStyle(vs);
+    }
+  }
+
+  /**
    * Add a listener to tidy up when the frame is closed.
    */
   protected void addCloseFrameListener()
@@ -165,33 +212,6 @@ public class SplitFrame extends GSplitFrame
   }
 
   /**
-   * Returns the split pane component the mouse is in, or null if neither.
-   * 
-   * @return
-   */
-  protected GAlignFrame getFrameAtMouse()
-  {
-    Point loc = MouseInfo.getPointerInfo().getLocation();
-    
-    if (isIn(loc, getTopFrame()))
-    {
-      return getTopFrame();
-    }
-    else if (isIn(loc, getBottomFrame()))
-    {
-      return getBottomFrame();
-    }
-    return null;
-  }
-
-  private boolean isIn(Point loc, JComponent comp)
-  {
-    Point p = comp.getLocationOnScreen();
-    Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
-    return r.contains(loc);
-  }
-
-  /**
    * Set key bindings (recommended for Swing over key accelerators).
    */
   private void addKeyBindings()
@@ -324,10 +344,13 @@ public class SplitFrame extends GSplitFrame
    * Note this is _not_ multiple tabs, each hosting a split pane view, rather it
    * is a single split pane with each split holding multiple tabs which are
    * linked in pairs.
+   * <p>
+   * TODO implement instead with a tabbed holder in the SplitView, each tab
+   * holding a single JSplitPane. Would avoid a duplicated tab, at the cost of
+   * some additional coding.
    */
   protected void newView_actionPerformed()
   {
-    System.out.println("newView " + this.hashCode());
     AlignFrame topFrame = (AlignFrame) getTopFrame();
     AlignFrame bottomFrame = (AlignFrame) getBottomFrame();