JAL-1641 Further refactoring of JSON export option, introduction of Viewport to the...
[jalview.git] / src / jalview / appletgui / AlignViewport.java
index b0e29da..ef17215 100644 (file)
  */
 package jalview.appletgui;
 
-import java.awt.Font;
-
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
 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 +39,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);
@@ -64,6 +58,8 @@ public class AlignViewport extends AlignmentViewport implements
 
   private AnnotationColumnChooser annotationColumnSelectionState;
 
+  private FeatureRenderer featureRenderer;
+
   public void finalize()
   {
     applet = null;
@@ -103,7 +99,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 +122,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 "
@@ -170,9 +166,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);
@@ -262,64 +258,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;
@@ -376,13 +314,6 @@ public class AlignViewport extends AlignmentViewport implements
     return centreColumnLabels;
   }
 
-  public boolean followHighlight = true;
-
-  public boolean getFollowHighlight()
-  {
-    return followHighlight;
-  }
-
   public boolean followSelection = true;
 
   /**
@@ -514,4 +445,42 @@ 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);
+    }
+  }
+
+  @Override
+  public FeatureRenderer getFeatureRenderer()
+  {
+    return featureRenderer;
+  }
+
+  @Override
+  public void setFeatureRenderer(FeatureRenderer featureRenderer)
+  {
+    this.featureRenderer = featureRenderer;
+
+  }
+
 }