JAL-2602 check for null or empty description when copying consensus
[jalview.git] / src / jalview / gui / AlignViewport.java
index d87d947..288f261 100644 (file)
@@ -22,7 +22,7 @@ package jalview.gui;
 
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.analysis.NJTree;
+import jalview.analysis.TreeModel;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureColourI;
@@ -34,6 +34,7 @@ import jalview.commands.CommandI;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
@@ -52,12 +53,12 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
-import jalview.viewmodel.ViewportRanges;
 import jalview.ws.params.AutoCalcSetting;
 
 import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Font;
+import java.awt.FontMetrics;
 import java.awt.Rectangle;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -77,7 +78,7 @@ public class AlignViewport extends AlignmentViewport implements
 {
   Font font;
 
-  NJTree currentTree = null;
+  TreeModel currentTree = null;
 
   boolean cursorMode = false;
 
@@ -106,7 +107,7 @@ public class AlignViewport extends AlignmentViewport implements
    */
   public AlignViewport(AlignmentI al)
   {
-    setAlignment(al);
+    super(al);
     init();
   }
 
@@ -124,6 +125,7 @@ public class AlignViewport extends AlignmentViewport implements
 
   public AlignViewport(AlignmentI al, String seqsetid, String viewid)
   {
+    super(al);
     sequenceSetID = seqsetid;
     viewId = viewid;
     // TODO remove these once 2.4.VAMSAS release finished
@@ -136,8 +138,8 @@ public class AlignViewport extends AlignmentViewport implements
     {
       Cache.log.debug("Setting viewport's view id : " + viewId);
     }
-    setAlignment(al);
     init();
+
   }
 
   /**
@@ -150,7 +152,7 @@ public class AlignViewport extends AlignmentViewport implements
    */
   public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
   {
-    setAlignment(al);
+    super(al);
     if (hiddenColumns != null)
     {
       al.setHiddenColumns(hiddenColumns);
@@ -185,6 +187,7 @@ public class AlignViewport extends AlignmentViewport implements
   public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
           String seqsetid, String viewid)
   {
+    super(al);
     sequenceSetID = seqsetid;
     viewId = viewid;
     // TODO remove these once 2.4.VAMSAS release finished
@@ -197,7 +200,7 @@ public class AlignViewport extends AlignmentViewport implements
     {
       Cache.log.debug("Setting viewport's view id : " + viewId);
     }
-    setAlignment(al);
+
     if (hiddenColumns != null)
     {
       al.setHiddenColumns(hiddenColumns);
@@ -239,7 +242,6 @@ public class AlignViewport extends AlignmentViewport implements
 
   void init()
   {
-    ranges = new ViewportRanges(this.alignment);
     applyViewProperties();
 
     String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
@@ -280,6 +282,8 @@ public class AlignViewport extends AlignmentViewport implements
               false);
       showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
       showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
+
+      showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
     }
     initAutoAnnotation();
     String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
@@ -327,15 +331,18 @@ public class AlignViewport extends AlignmentViewport implements
     StringBuffer seqs = new StringBuffer();
     for (int i = 0; i < consensus.annotations.length; i++)
     {
-      if (consensus.annotations[i] != null)
+      Annotation annotation = consensus.annotations[i];
+      if (annotation != null)
       {
-        if (consensus.annotations[i].description.charAt(0) == '[')
+        String description = annotation.description;
+        if (description != null && description.startsWith("["))
         {
-          seqs.append(consensus.annotations[i].description.charAt(1));
+          // consensus is a tie - just pick the first one
+          seqs.append(description.charAt(1));
         }
         else
         {
-          seqs.append(consensus.annotations[i].displayCharacter);
+          seqs.append(annotation.displayCharacter);
         }
       }
     }
@@ -349,23 +356,19 @@ public class AlignViewport extends AlignmentViewport implements
   boolean validCharWidth;
 
   /**
-   * update view settings with the given font. You may need to call
-   * alignPanel.fontChanged to update the layout geometry
-   * 
-   * @param setGrid
-   *          when true, charWidth/height is set according to font mentrics
+   * {@inheritDoc}
    */
+  @Override
   public void setFont(Font f, boolean setGrid)
   {
     font = f;
 
     Container c = new Container();
 
-    java.awt.FontMetrics fm = c.getFontMetrics(font);
-    int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
-            .getCharHeight();
     if (setGrid)
     {
+      FontMetrics fm = c.getFontMetrics(font);
+      int ww = fm.charWidth('M');
       setCharHeight(fm.getHeight());
       setCharWidth(ww);
     }
@@ -492,7 +495,7 @@ public class AlignViewport extends AlignmentViewport implements
    * @param tree
    *          DOCUMENT ME!
    */
-  public void setCurrentTree(NJTree tree)
+  public void setCurrentTree(TreeModel tree)
   {
     currentTree = tree;
   }
@@ -502,7 +505,7 @@ public class AlignViewport extends AlignmentViewport implements
    * 
    * @return DOCUMENT ME!
    */
-  public NJTree getCurrentTree()
+  public TreeModel getCurrentTree()
   {
     return currentTree;
   }
@@ -1050,8 +1053,9 @@ public class AlignViewport extends AlignmentViewport implements
       // TODO would like next line without cast but needs more refactoring...
       final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
               .getAlignPanel();
-      complementPanel.setDontScrollComplement(true);
+      complementPanel.setToScrollComplementPanel(false);
       complementPanel.scrollToCentre(sr, verticalOffset);
+      complementPanel.setToScrollComplementPanel(true);
     }
   }