JAL-1925 update source version in license
[jalview.git] / src / jalview / appletgui / AlignViewport.java
index 2d38008..729096b 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.appletgui;
 
-import java.awt.Font;
-
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
 import jalview.bin.JalviewLite;
 import jalview.commands.CommandI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SearchResults;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
@@ -39,17 +38,11 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.viewmodel.AlignmentViewport;
 
+import java.awt.Font;
+
 public class AlignViewport extends AlignmentViewport implements
-        AlignViewportI, SelectionSource, VamsasSource, CommandListener
+        SelectionSource, VamsasSource, CommandListener
 {
-  int startRes;
-
-  int endRes;
-
-  int startSeq;
-
-  int endSeq;
-
   boolean cursorMode = false;
 
   Font font = new Font("SansSerif", Font.PLAIN, 10);
@@ -103,7 +96,7 @@ public class AlignViewport extends AlignmentViewport implements
                           + widthScale + "). Ignoring.");
           widthScale = 1;
         }
-        if (applet.debug)
+        if (JalviewLite.debug)
         {
           System.err
                   .println("Alignment character width scaling factor is now "
@@ -126,7 +119,7 @@ public class AlignViewport extends AlignmentViewport implements
                           + heightScale + "). Ignoring.");
           heightScale = 1;
         }
-        if (applet.debug)
+        if (JalviewLite.debug)
         {
           System.err
                   .println("Alignment character height scaling factor is now "
@@ -157,6 +150,9 @@ public class AlignViewport extends AlignmentViewport implements
       setShowUnconserved(applet.getDefaultParameter("showUnconserved",
               getShowUnconserved()));
 
+      setScaleProteinAsCdna(applet.getDefaultParameter(
+              "scaleProteinAsCdna", isScaleProteinAsCdna()));
+
       String param = applet.getParameter("upperCase");
       if (param != null)
       {
@@ -167,9 +163,9 @@ public class AlignViewport extends AlignmentViewport implements
       }
       sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
 
-      followHighlight = applet.getDefaultParameter("automaticScrolling",
-              followHighlight);
-      followSelection = followHighlight;
+      setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
+              isFollowHighlight()));
+      followSelection = isFollowHighlight();
 
       showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
               showSequenceLogo);
@@ -191,8 +187,13 @@ public class AlignViewport extends AlignmentViewport implements
 
     if (applet != null)
     {
-      String colour = applet.getParameter("defaultColour");
-
+      String colour = al.isNucleotide() ? applet
+              .getParameter("defaultColourNuc") : applet
+              .getParameter("defaultColourProt");
+      if (colour == null)
+      {
+        colour = applet.getParameter("defaultColour");
+      }
       if (colour == null)
       {
         colour = applet.getParameter("userDefinedColour");
@@ -259,64 +260,6 @@ public class AlignViewport extends AlignmentViewport implements
     return sq;
   }
 
-  public int getStartRes()
-  {
-    return startRes;
-  }
-
-  public int getEndRes()
-  {
-    return endRes;
-  }
-
-  public int getStartSeq()
-  {
-    return startSeq;
-  }
-
-  public void setStartRes(int res)
-  {
-    this.startRes = res;
-  }
-
-  public void setStartSeq(int seq)
-  {
-    this.startSeq = seq;
-  }
-
-  public void setEndRes(int res)
-  {
-    if (res > alignment.getWidth() - 1)
-    {
-      // log.System.out.println(" Corrected res from " + res + " to maximum " +
-      // (alignment.getWidth()-1));
-      res = alignment.getWidth() - 1;
-    }
-    if (res < 0)
-    {
-      res = 0;
-    }
-    this.endRes = res;
-  }
-
-  public void setEndSeq(int seq)
-  {
-    if (seq > alignment.getHeight())
-    {
-      seq = alignment.getHeight();
-    }
-    if (seq < 0)
-    {
-      seq = 0;
-    }
-    this.endSeq = seq;
-  }
-
-  public int getEndSeq()
-  {
-    return endSeq;
-  }
-
   java.awt.Frame nullFrame;
 
   protected FeatureSettings featureSettings = null;
@@ -349,7 +292,6 @@ public class AlignViewport extends AlignmentViewport implements
     return font;
   }
 
-
   public void resetSeqLimits(int height)
   {
     setEndSeq(height / getCharHeight());
@@ -365,7 +307,6 @@ public class AlignViewport extends AlignmentViewport implements
     return currentTree;
   }
 
-
   boolean centreColumnLabels;
 
   public boolean getCentreColumnLabels()
@@ -373,13 +314,6 @@ public class AlignViewport extends AlignmentViewport implements
     return centreColumnLabels;
   }
 
-  public boolean followHighlight = true;
-
-  public boolean getFollowHighlight()
-  {
-    return followHighlight;
-  }
-
   public boolean followSelection = true;
 
   /**
@@ -394,8 +328,8 @@ public class AlignViewport extends AlignmentViewport implements
   public void sendSelection()
   {
     getStructureSelectionManager().sendSelection(
-                    new SequenceGroup(getSelectionGroup()),
-                    new ColumnSelection(getColumnSelection()), this);
+            new SequenceGroup(getSelectionGroup()),
+            new ColumnSelection(getColumnSelection()), this);
   }
 
   /**
@@ -511,4 +445,29 @@ public class AlignViewport extends AlignmentViewport implements
     return this;
   }
 
+  /**
+   * If this viewport has a (Protein/cDNA) complement, then scroll the
+   * complementary alignment to match this one.
+   */
+  public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
+  {
+    if (complementPanel == null)
+    {
+      return;
+    }
+
+    /*
+     * Populate a SearchResults object with the mapped location to scroll to. If
+     * there is no complement, or it is not following highlights, or no mapping
+     * is found, the result will be empty.
+     */
+    SearchResults sr = new SearchResults();
+    int seqOffset = findComplementScrollTarget(sr);
+    if (!sr.isEmpty())
+    {
+      complementPanel.setFollowingComplementScroll(true);
+      complementPanel.scrollToCentre(sr, seqOffset);
+    }
+  }
+
 }