Merge remote-tracking branch 'origin/develop' into
[jalview.git] / src / jalview / appletgui / AlignViewport.java
index 2d38008..61621ae 100644 (file)
  */
 package jalview.appletgui;
 
-import java.awt.Font;
-
 import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureSettingsModelI;
 import jalview.bin.JalviewLite;
 import jalview.commands.CommandI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.renderer.ResidueShader;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.UserColourScheme;
-import jalview.structure.CommandListener;
 import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.ViewportRanges;
+
+import java.awt.Font;
 
 public class AlignViewport extends AlignmentViewport implements
-        AlignViewportI, SelectionSource, VamsasSource, CommandListener
+        SelectionSource
 {
-  int startRes;
-
-  int endRes;
-
-  int startSeq;
-
-  int endSeq;
-
   boolean cursorMode = false;
 
   Font font = new Font("SansSerif", Font.PLAIN, 10);
@@ -64,6 +61,7 @@ public class AlignViewport extends AlignmentViewport implements
 
   private AnnotationColumnChooser annotationColumnSelectionState;
 
+  @Override
   public void finalize()
   {
     applet = null;
@@ -78,12 +76,10 @@ public class AlignViewport extends AlignmentViewport implements
     calculator = new jalview.workers.AlignCalcManager();
     this.applet = applet;
     alignment = al;
+    ranges = new ViewportRanges(this.alignment);
     // we always pad gaps
     this.setPadGaps(true);
-    this.startRes = 0;
-    this.endRes = al.getWidth() - 1;
-    this.startSeq = 0;
-    this.endSeq = al.getHeight() - 1;
+
     if (applet != null)
     {
       // get the width and height scaling factors if they were specified
@@ -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 "
@@ -154,9 +150,15 @@ public class AlignViewport extends AlignmentViewport implements
       showConsensus = applet.getDefaultParameter("showConsensus",
               showConsensus);
 
+      showOccupancy = applet.getDefaultParameter("showOccupancy",
+              showOccupancy);
+
       setShowUnconserved(applet.getDefaultParameter("showUnconserved",
               getShowUnconserved()));
 
+      setScaleProteinAsCdna(applet.getDefaultParameter(
+              "scaleProteinAsCdna", isScaleProteinAsCdna()));
+
       String param = applet.getParameter("upperCase");
       if (param != null)
       {
@@ -167,9 +169,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 +193,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");
@@ -204,18 +211,19 @@ public class AlignViewport extends AlignmentViewport implements
 
       if (colour != null)
       {
-        globalColourScheme = ColourSchemeProperty.getColour(alignment,
-                colour);
-        if (globalColourScheme != null)
+        residueShading = new ResidueShader(
+                ColourSchemeProperty.getColourScheme(alignment, colour));
+        if (residueShading != null)
         {
-          globalColourScheme.setConsensus(hconsensus);
+          residueShading.setConsensus(hconsensus);
         }
       }
 
       if (applet.getParameter("userDefinedColour") != null)
       {
-        ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
-                .getParameter("userDefinedColour"));
+        residueShading = new ResidueShader(
+                new UserColourScheme(
+                        applet.getParameter("userDefinedColour")));
       }
     }
     initAutoAnnotation();
@@ -259,64 +267,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,10 +299,9 @@ public class AlignViewport extends AlignmentViewport implements
     return font;
   }
 
-
   public void resetSeqLimits(int height)
   {
-    setEndSeq(height / getCharHeight());
+    ranges.setEndSeq(height / getCharHeight());
   }
 
   public void setCurrentTree(NJTree tree)
@@ -365,7 +314,6 @@ public class AlignViewport extends AlignmentViewport implements
     return currentTree;
   }
 
-
   boolean centreColumnLabels;
 
   public boolean getCentreColumnLabels()
@@ -373,13 +321,6 @@ public class AlignViewport extends AlignmentViewport implements
     return centreColumnLabels;
   }
 
-  public boolean followHighlight = true;
-
-  public boolean getFollowHighlight()
-  {
-    return followHighlight;
-  }
-
   public boolean followSelection = true;
 
   /**
@@ -391,11 +332,13 @@ public class AlignViewport extends AlignmentViewport implements
     return followSelection;
   }
 
+  @Override
   public void sendSelection()
   {
     getStructureSelectionManager().sendSelection(
-                    new SequenceGroup(getSelectionGroup()),
-                    new ColumnSelection(getColumnSelection()), this);
+            new SequenceGroup(getSelectionGroup()),
+            new ColumnSelection(getColumnSelection()),
+            new HiddenColumns(getAlignment().getHiddenColumns()), this);
   }
 
   /**
@@ -411,39 +354,7 @@ public class AlignViewport extends AlignmentViewport implements
             .getStructureSelectionManager(applet);
   }
 
-  /**
-   * synthesize a column selection if none exists so it covers the given
-   * selection group. if wholewidth is false, no column selection is made if the
-   * selection group covers the whole alignment width.
-   * 
-   * @param sg
-   * @param wholewidth
-   */
-  public void expandColSelection(SequenceGroup sg, boolean wholewidth)
-  {
-    int sgs, sge;
-    if (sg != null
-            && (sgs = sg.getStartRes()) >= 0
-            && sg.getStartRes() <= (sge = sg.getEndRes())
-            && (colSel == null || colSel.getSelected() == null || colSel
-                    .getSelected().size() == 0))
-    {
-      if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
-      {
-        // do nothing
-        return;
-      }
-      if (colSel == null)
-      {
-        colSel = new ColumnSelection();
-      }
-      for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
-      {
-        colSel.addElement(cspos);
-      }
-    }
-  }
-
+  @Override
   public boolean isNormaliseSequenceLogo()
   {
     return normaliseSequenceLogo;
@@ -458,6 +369,7 @@ public class AlignViewport extends AlignmentViewport implements
    * 
    * @return true if alignment characters should be displayed
    */
+  @Override
   public boolean isValidCharWidth()
   {
     return validCharWidth;
@@ -511,4 +423,43 @@ 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.
+     */
+    SearchResultsI sr = new SearchResults();
+    int seqOffset = findComplementScrollTarget(sr);
+    if (!sr.isEmpty())
+    {
+      complementPanel.setFollowingComplementScroll(true);
+      complementPanel.scrollToCentre(sr, seqOffset);
+    }
+  }
+
+  /**
+   * Applies the supplied feature settings descriptor to currently known
+   * features. This supports an 'initial configuration' of feature colouring
+   * based on a preset or user favourite. This may then be modified in the usual
+   * way using the Feature Settings dialogue.
+   * 
+   * @param featureSettings
+   */
+  @Override
+  public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
+  {
+    // TODO implement for applet
+  }
+
 }