JAL-969 javadoc and mark interface overrides for clarity
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 0c8afaa..a48c910 100644 (file)
  */
 package jalview.viewmodel;
 
-import jalview.analysis.AAFrequency;
 import jalview.analysis.Conservation;
 import jalview.api.AlignCalcManagerI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.api.FeaturesDisplayedI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
@@ -35,7 +35,6 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.Blosum62ColourScheme;
-import jalview.schemes.ClustalxColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.schemes.ResidueProperties;
@@ -447,7 +446,9 @@ public abstract class AlignmentViewport implements AlignViewportI
           AlignmentAnnotation alignmentAnnotation)
   {
     if (!alignmentAnnotation.autoCalculated)
+    {
       return false;
+    }
     if (calculator.workingInvolvedWith(alignmentAnnotation))
     {
       // System.err.println("grey out ("+alignmentAnnotation.label+")");
@@ -648,9 +649,14 @@ public abstract class AlignmentViewport implements AlignViewportI
     return colSel;
   }
 
+  @Override
   public void setColumnSelection(ColumnSelection colSel)
   {
     this.colSel = colSel;
+    if (colSel != null)
+    {
+      updateHiddenColumns();
+    }
   }
 
   /**
@@ -674,7 +680,7 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   public void updateHiddenColumns()
   {
-    hasHiddenColumns = colSel.getHiddenColumns() != null;
+    hasHiddenColumns = colSel.hasHiddenColumns();
   }
 
   protected boolean hasHiddenRows = false;
@@ -696,6 +702,7 @@ public abstract class AlignmentViewport implements AlignViewportI
     sequenceSetID = new String(newid);
   }
 
+  @Override
   public String getSequenceSetId()
   {
     if (sequenceSetID == null)
@@ -899,11 +906,12 @@ public abstract class AlignmentViewport implements AlignViewportI
         selectionGroup = new SequenceGroup();
         selectionGroup.setEndRes(alignment.getWidth() - 1);
       }
-      Vector tmp = alignment.getHiddenSequences().showAll(
+      List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
               hiddenRepSequences);
-      for (int t = 0; t < tmp.size(); t++)
+      for (SequenceI seq : tmp)
       {
-        selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
+        selectionGroup.addSequence(seq, false);
+        setSequenceAnnotationsVisible(seq, true);
       }
 
       hasHiddenRows = false;
@@ -918,7 +926,8 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   public void showSequence(int index)
   {
-    Vector tmp = alignment.getHiddenSequences().showSequence(index,
+    List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
+            index,
             hiddenRepSequences);
     if (tmp.size() > 0)
     {
@@ -928,9 +937,10 @@ public abstract class AlignmentViewport implements AlignViewportI
         selectionGroup.setEndRes(alignment.getWidth() - 1);
       }
 
-      for (int t = 0; t < tmp.size(); t++)
+      for (SequenceI seq : tmp)
       {
-        selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
+        selectionGroup.addSequence(seq, false);
+        setSequenceAnnotationsVisible(seq, true);
       }
       // JBPNote: refactor: only update flag if we modified visiblity (used to
       // do this regardless)
@@ -964,12 +974,30 @@ public abstract class AlignmentViewport implements AlignViewportI
       for (int i = 0; i < seq.length; i++)
       {
         alignment.getHiddenSequences().hideSequence(seq[i]);
+        setSequenceAnnotationsVisible(seq[i], false);
       }
       hasHiddenRows = true;
       firePropertyChange("alignment", null, alignment.getSequences());
     }
   }
 
+  /**
+   * Set visibility for any annotations for the given sequence.
+   * 
+   * @param sequenceI
+   */
+  protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
+          boolean visible)
+  {
+    for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
+    {
+      if (ann.sequenceRef == sequenceI)
+      {
+        ann.visible = visible;
+      }
+    }
+  }
+
   public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
   {
     int sSize = sg.getSize();
@@ -1008,8 +1036,8 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   public boolean isHiddenRepSequence(SequenceI seq)
   {
-    return hiddenRepSequences != null
-            && hiddenRepSequences.containsKey(seq);
+    return alignment.getSeqrep()==seq || (hiddenRepSequences != null
+            && hiddenRepSequences.containsKey(seq));
   }
 
   public SequenceGroup getRepresentedSequences(SequenceI seq)
@@ -1018,32 +1046,24 @@ public abstract class AlignmentViewport implements AlignViewportI
             : hiddenRepSequences.get(seq));
   }
 
+  @Override
   public int adjustForHiddenSeqs(int alignmentIndex)
   {
     return alignment.getHiddenSequences().adjustForHiddenSeqs(
             alignmentIndex);
   }
 
-  // Selection manipulation
-  /**
-   * broadcast selection to any interested parties
-   */
+  @Override
   public abstract void sendSelection();
 
+  @Override
   public void invertColumnSelection()
   {
     colSel.invertColumnSelection(0, alignment.getWidth());
   }
 
-  /**
-   * This method returns an array of new SequenceI objects derived from the
-   * whole alignment or just the current selection with start and end points
-   * adjusted
-   * 
-   * @note if you need references to the actual SequenceI objects in the
-   *       alignment or currently selected then use getSequenceSelection()
-   * @return selection as new sequenceI objects
-   */
+
+  @Override
   public SequenceI[] getSelectionAsNewSequence()
   {
     SequenceI[] sequences;
@@ -1072,12 +1092,7 @@ public abstract class AlignmentViewport implements AlignViewportI
     return sequences;
   }
 
-  /**
-   * get the currently selected sequence objects or all the sequences in the
-   * alignment.
-   * 
-   * @return array of references to sequence objects
-   */
+
   @Override
   public SequenceI[] getSequenceSelection()
   {
@@ -1093,14 +1108,7 @@ public abstract class AlignmentViewport implements AlignViewportI
     return sequences;
   }
 
-  /**
-   * This method returns the visible alignment as text, as seen on the GUI, ie
-   * if columns are hidden they will not be returned in the result. Use this for
-   * calculating trees, PCA, redundancy etc on views which contain hidden
-   * columns.
-   * 
-   * @return String[]
-   */
+
   @Override
   public jalview.datamodel.CigarArray getViewAsCigars(
           boolean selectedRegionOnly)
@@ -1110,14 +1118,7 @@ public abstract class AlignmentViewport implements AlignViewportI
             (selectedRegionOnly ? selectionGroup : null));
   }
 
-  /**
-   * return a compact representation of the current alignment selection to pass
-   * to an analysis function
-   * 
-   * @param selectedOnly
-   *          boolean true to just return the selected view
-   * @return AlignmentView
-   */
+
   @Override
   public jalview.datamodel.AlignmentView getAlignmentView(
           boolean selectedOnly)
@@ -1125,18 +1126,7 @@ public abstract class AlignmentViewport implements AlignViewportI
     return getAlignmentView(selectedOnly, false);
   }
 
-  /**
-   * return a compact representation of the current alignment selection to pass
-   * to an analysis function
-   * 
-   * @param selectedOnly
-   *          boolean true to just return the selected view
-   * @param markGroups
-   *          boolean true to annotate the alignment view with groups on the
-   *          alignment (and intersecting with selected region if selectedOnly
-   *          is true)
-   * @return AlignmentView
-   */
+
   @Override
   public jalview.datamodel.AlignmentView getAlignmentView(
           boolean selectedOnly, boolean markGroups)
@@ -1145,14 +1135,7 @@ public abstract class AlignmentViewport implements AlignViewportI
             hasHiddenColumns, selectedOnly, markGroups);
   }
 
-  /**
-   * This method returns the visible alignment as text, as seen on the GUI, ie
-   * if columns are hidden they will not be returned in the result. Use this for
-   * calculating trees, PCA, redundancy etc on views which contain hidden
-   * columns.
-   * 
-   * @return String[]
-   */
+
   @Override
   public String[] getViewAsString(boolean selectedRegionOnly)
   {
@@ -1190,15 +1173,8 @@ public abstract class AlignmentViewport implements AlignViewportI
     return selection;
   }
 
-  /**
-   * return visible region boundaries within given column range
-   * 
-   * @param min
-   *          first column (inclusive, from 0)
-   * @param max
-   *          last column (exclusive)
-   * @return int[][] range of {start,end} visible positions
-   */
+
+  @Override
   public int[][] getVisibleRegionBoundaries(int min, int max)
   {
     Vector regions = new Vector();
@@ -1243,18 +1219,37 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   }
 
-  /**
-   * @return the padGaps
-   */
+  @Override
+  public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
+  {
+    ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+    AlignmentAnnotation[] aa;
+    if ((aa=alignment.getAlignmentAnnotation())!=null)
+    {
+      for (AlignmentAnnotation annot:aa)
+      {
+        AlignmentAnnotation clone = new AlignmentAnnotation(annot);
+        if (selectedOnly && selectionGroup!=null)
+        {
+          colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
+        } else {
+          colSel.makeVisibleAnnotation(clone);
+        }
+        ala.add(clone);
+      }
+    }
+    return ala;
+  }
+
+
+  @Override
   public boolean isPadGaps()
   {
     return padGaps;
   }
 
-  /**
-   * @param padGaps
-   *          the padGaps to set
-   */
+
+  @Override
   public void setPadGaps(boolean padGaps)
   {
     this.padGaps = padGaps;
@@ -1266,6 +1261,7 @@ public abstract class AlignmentViewport implements AlignViewportI
    * 
    * @param ap
    */
+  @Override
   public void alignmentChanged(AlignmentViewPanel ap)
   {
     if (isPadGaps())
@@ -1427,6 +1423,7 @@ public abstract class AlignmentViewport implements AlignViewportI
    * 
    * @see jalview.api.AlignViewportI#calcPanelHeight()
    */
+  @Override
   public int calcPanelHeight()
   {
     // setHeight of panels
@@ -1558,6 +1555,36 @@ public abstract class AlignmentViewport implements AlignViewportI
     }
     oldrfs.clear();
   }
+  /**
+   * show the reference sequence in the alignment view
+   */
+  private boolean displayReferenceSeq=false;
+  /**
+   * colour according to the reference sequence defined on the alignment
+   */
+  private boolean colourByReferenceSeq=false;
+
+  @Override
+  public boolean isDisplayReferenceSeq()
+  {
+    return alignment.hasSeqrep() && displayReferenceSeq;
+  }
+
+  @Override
+  public void setDisplayReferenceSeq(boolean displayReferenceSeq)
+  {
+    this.displayReferenceSeq = displayReferenceSeq;
+  }
+
+  public boolean isColourByReferenceSeq()
+  {
+    return alignment.hasSeqrep() && colourByReferenceSeq;
+  }
+
+  public void setColourByReferenceSeq(boolean colourByReferenceSeq)
+  {
+    this.colourByReferenceSeq = colourByReferenceSeq;
+  }
 
   @Override
   public Color getSequenceColour(SequenceI seq)
@@ -1616,4 +1643,90 @@ public abstract class AlignmentViewport implements AlignViewportI
   {
     sequenceColours = null;
   };
+
+  FeaturesDisplayedI featuresDisplayed = null;
+
+  @Override
+  public FeaturesDisplayedI getFeaturesDisplayed()
+  {
+    return featuresDisplayed;
+  }
+
+  @Override
+  public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
+  {
+    featuresDisplayed = featuresDisplayedI;
+  }
+
+  @Override
+  public boolean areFeaturesDisplayed()
+  {
+    return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
+  }
+
+  /**
+   * display setting for showing/hiding sequence features on alignment view
+   */
+  boolean showSequenceFeatures = false;
+
+  /**
+   * set the flag
+   * 
+   * @param b
+   *          features are displayed if true
+   */
+  @Override
+  public void setShowSequenceFeatures(boolean b)
+  {
+    showSequenceFeatures = b;
+  }
+  @Override
+  public boolean isShowSequenceFeatures()
+  {
+    return showSequenceFeatures;
+  }
+
+  boolean showSeqFeaturesHeight;
+
+  @Override
+  public void setShowSequenceFeaturesHeight(boolean selected)
+  {
+    showSeqFeaturesHeight = selected;
+  }
+
+  @Override
+  public boolean isShowSequenceFeaturesHeight()
+  {
+    return showSeqFeaturesHeight;
+  }
+
+  private boolean showAnnotation = true;
+
+  private boolean rightAlignIds = false;
+
+
+  @Override
+  public void setShowAnnotation(boolean b)
+  {
+    showAnnotation = b;
+  }
+
+  @Override
+  public boolean isShowAnnotation()
+  {
+    return showAnnotation;
+  }
+
+  @Override
+  public boolean isRightAlignIds()
+  {
+    return rightAlignIds;
+  }
+
+  @Override
+  public void setRightAlignIds(boolean rightAlignIds)
+  {
+    this.rightAlignIds = rightAlignIds;
+  }
+
 }