JAL-1152 with sticky annotation sort order that updates as sequences are
[jalview.git] / src / jalview / gui / AlignViewport.java
index a1e184f..6969513 100644 (file)
@@ -1,19 +1,22 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 /*
  * Jalview - A Sequence Alignment Editor and Viewer
  */
 package jalview.gui;
 
-import java.util.*;
-
-import java.awt.*;
-
-import jalview.analysis.*;
-import jalview.api.AlignCalcManagerI;
+import jalview.analysis.AnnotationSorter.SortOrder;
+import jalview.analysis.NJTree;
 import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
-import jalview.api.OOMHandlerI;
-
-import jalview.bin.*;
-
-import jalview.datamodel.*;
-
-import jalview.schemes.*;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
 import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.viewmodel.AlignmentViewport;
-import jalview.workers.AlignCalcManager;
-import jalview.workers.ConsensusThread;
-import jalview.workers.ConservationThread;
-import jalview.workers.StrucConsensusThread;
-import jalview.ws.jws2.dm.AAConsSettings;
 import jalview.ws.params.AutoCalcSetting;
 
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Stack;
+import java.util.Vector;
+
 /**
  * DOCUMENT ME!
  * 
  * @author $author$
  * @version $Revision: 1.141 $
  */
-public class AlignViewport extends AlignmentViewport implements SelectionSource, VamsasSource, AlignViewportI
+public class AlignViewport extends AlignmentViewport implements
+        SelectionSource, VamsasSource, AlignViewportI
 {
   int startRes;
 
@@ -93,6 +100,8 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
 
   boolean showAnnotation = true;
 
+  SortOrder sortAnnotationsBy = null;
+
   int charHeight;
 
   int charWidth;
@@ -105,7 +114,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
 
   boolean seqNameItalics;
 
-
   NJTree currentTree = null;
 
   boolean scaleAboveWrapped = false;
@@ -136,8 +144,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
 
   Stack redoList = new Stack();
 
-  Hashtable sequenceColours;
-
   int thresholdTextColour = 0;
 
   Color textColour = Color.black;
@@ -319,17 +325,18 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     {
       if (!alignment.isNucleotide())
       {
-        showConservation=Cache.getDefault("SHOW_CONSERVATION", true);
-        showQuality=Cache.getDefault("SHOW_QUALITY", true);
+        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
+        showQuality = Cache.getDefault("SHOW_QUALITY", true);
         showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
                 false);
-      } 
+      }
       showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
               true);
       showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
-      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO", false);
+      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
+              false);
       showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
-      showConsensus=Cache.getDefault("SHOW_IDENTITY", true);
+      showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
       consensus = new AlignmentAnnotation("Consensus", "PID",
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       consensus.hasText = true;
@@ -354,12 +361,14 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
       }
     }
 
-    wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
-    showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
+    wrapAlignment = Cache.getDefault("WRAP_ALIGNMENT", false);
+    showUnconserved = Cache.getDefault("SHOW_UNCONSERVED",
             false);
-    sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
-    followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
+    sortByTree = Cache.getDefault("SORT_BY_TREE", false);
+    followSelection = Cache.getDefault("FOLLOW_SELECTIONS",
             true);
+    sortAnnotationsBy = SortOrder.valueOf(Cache.getDefault(
+            "SORT_ANNOTATIONS", SortOrder.SEQUENCE_AND_TYPE.name()));
   }
 
   /**
@@ -649,7 +658,7 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
               Desktop.instance).removeMappings(alignment.getCodonFrames());
     }
     this.alignment = align;
-    if (alignment!=null && alignment.getCodonFrames() != null)
+    if (alignment != null && alignment.getCodonFrames() != null)
     {
       StructureSelectionManager.getStructureSelectionManager(
               Desktop.instance).addMappings(alignment.getCodonFrames());
@@ -911,7 +920,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     scaleRightWrapped = b;
   }
 
-
   public void setDataset(boolean b)
   {
     isDataset = b;
@@ -922,8 +930,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     return isDataset;
   }
 
-
-
   public boolean getShowHiddenMarkers()
   {
     return showHiddenMarkers;
@@ -934,35 +940,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     showHiddenMarkers = show;
   }
 
-  public Color getSequenceColour(SequenceI seq)
-  {
-    if (sequenceColours == null || !sequenceColours.containsKey(seq))
-    {
-      return Color.white;
-    }
-    else
-    {
-      return (Color) sequenceColours.get(seq);
-    }
-  }
-
-  public void setSequenceColour(SequenceI seq, Color col)
-  {
-    if (sequenceColours == null)
-    {
-      sequenceColours = new Hashtable();
-    }
-
-    if (col == null)
-    {
-      sequenceColours.remove(seq);
-    }
-    else
-    {
-      sequenceColours.put(seq, col);
-    }
-  }
-
   /**
    * returns the visible column regions of the alignment
    * 
@@ -997,8 +974,10 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
   {
     // TODO: JAL-1126
     if (historyList == null || redoList == null)
+    {
       return new long[]
       { -1, -1 };
+    }
     return new long[]
     { historyList.hashCode(), this.redoList.hashCode() };
   }
@@ -1044,24 +1023,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     centreColumnLabels = centrecolumnlabels;
   }
 
-  public void updateSequenceIdColours()
-  {
-    if (sequenceColours == null)
-    {
-      sequenceColours = new Hashtable();
-    }
-    for (SequenceGroup sg:alignment.getGroups())
-    {
-      if (sg.idColour != null)
-      {
-        for (SequenceI s:sg.getSequences(getHiddenRepSequences()))
-        {
-          sequenceColours.put(s, sg.idColour);
-        }
-      }
-    }
-  }
-
   /**
    * enable or disable the display of Database Cross References in the sequence
    * ID tooltip
@@ -1253,7 +1214,9 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
         Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
                 .getPDBId();
         if (pdbs == null)
+        {
           continue;
+        }
         SequenceI sq;
         for (int p = 0; p < pdbs.size(); p++)
         {
@@ -1261,7 +1224,9 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
           if (p1.getId().equals(pdb.getId()))
           {
             if (!seqs.contains(sq = alignment.getSequenceAt(i)))
+            {
               seqs.add(sq);
+            }
 
             continue;
           }
@@ -1272,7 +1237,6 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
   }
 
-  
   public boolean isNormaliseSequenceLogo()
   {
     return normaliseSequenceLogo;
@@ -1283,26 +1247,42 @@ public class AlignViewport extends AlignmentViewport implements SelectionSource,
     normaliseSequenceLogo = state;
   }
 
-
   /**
    * 
-   * @return true if alignment characters should be displayed 
+   * @return true if alignment characters should be displayed
    */
   public boolean isValidCharWidth()
   {
     return validCharWidth;
   }
-  private Hashtable<String, AutoCalcSetting> calcIdParams=new Hashtable<String, AutoCalcSetting>();
+
+  private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
+
   public AutoCalcSetting getCalcIdSettingsFor(String calcId)
   {
     return calcIdParams.get(calcId);
   }
 
-  public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings, boolean needsUpdate)
+  public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
+          boolean needsUpdate)
   {
     calcIdParams.put(calcId, settings);
-    // TODO: create a restart list to trigger any calculations that need to be restarted after load
+    // TODO: create a restart list to trigger any calculations that need to be
+    // restarted after load
     // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
+    if (needsUpdate)
+    {
+      Cache.log.debug("trigger update for " + calcId);
+    }
+  }
+
+  protected SortOrder getSortAnnotationsBy()
+  {
+    return sortAnnotationsBy;
+  }
+
+  protected void setSortAnnotationsBy(SortOrder sortAnnotationsBy)
+  {
+    this.sortAnnotationsBy = sortAnnotationsBy;
   }
-  
 }