Sequence label colour stored for each sequence group
[jalview.git] / src / jalview / gui / AlignViewport.java
index 5c93dc5..f798671 100755 (executable)
@@ -29,6 +29,7 @@ import jalview.bin.*;
 import jalview.datamodel.*;
 
 import jalview.schemes.*;
+import jalview.structure.StructureSelectionManager;
 
 /**
  * DOCUMENT ME!
@@ -166,7 +167,7 @@ public class AlignViewport
       showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
 
       rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
-
+      centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
       autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
 
       padGaps = Cache.getDefault("PAD_GAPS", true);
@@ -222,7 +223,7 @@ public class AlignViewport
                                                 0f,
                                                 11f,
                                                 AlignmentAnnotation.BAR_GRAPH);
-              quality.hasText = false;
+              quality.hasText = true;
               quality.autoCalculated=true;
 
               alignment.addAnnotation(quality);
@@ -300,7 +301,7 @@ public class AlignViewport
             {
               if (ap != null)
               {
-              ap.paintAlignment(true);
+                ap.paintAlignment(false);
               }
               Thread.sleep(200);
             }
@@ -455,9 +456,14 @@ public class AlignViewport
     boolean updatingConsensus = false;
 
     boolean updatingConservation = false;
+    /**
+     * centre columnar annotation labels in displayed alignment annotation
+     * TODO: add to jalviewXML and annotation display settings
+     */
+    boolean centreColumnLabels=false;
 
     /**
-     * DOCUMENT ME!
+     * trigger update of conservation annotation
      */
     public void updateConservation(final AlignmentPanel ap)
     {
@@ -471,7 +477,7 @@ public class AlignViewport
     }
 
     /**
-     * DOCUMENT ME!
+     * trigger update of consensus annotation
      */
     public void updateConsensus(final AlignmentPanel ap)
     {
@@ -496,7 +502,7 @@ public class AlignViewport
           {
             if (ap != null)
             {
-            ap.paintAlignment(true);
+            ap.paintAlignment(false);
             }
 
             Thread.sleep(200);
@@ -512,7 +518,7 @@ public class AlignViewport
 
         try
         {
-          int aWidth = alignment.getWidth();
+          int aWidth = (alignment!=null) ? alignment.getWidth() : 0; // null pointer possibility here.
           if(aWidth<0)
         {
             return;
@@ -916,7 +922,15 @@ public class AlignViewport
      */
     public void setAlignment(AlignmentI align)
     {
+      if (alignment!=null && alignment.getCodonFrames()!=null)
+      {
+        StructureSelectionManager.getStructureSelectionManager().removeMappings(alignment.getCodonFrames());
+      }
         this.alignment = align;
+        if (alignment.getCodonFrames()!=null)
+        {
+          StructureSelectionManager.getStructureSelectionManager().addMappings(alignment.getCodonFrames());
+        }
     }
 
     /**
@@ -1444,20 +1458,7 @@ public class AlignViewport
 
     public void invertColumnSelection()
     {
-      for(int i=0; i<alignment.getWidth(); i++)
-      {
-        if(colSel.contains(i))
-      {
-          colSel.removeElement(i);
-      }
-        else
-        {
-          if (!hasHiddenColumns || colSel.isVisible(i))
-          {
-            colSel.addElement(i);
-          }
-        }
-      }
+      colSel.invertColumnSelection(0,alignment.getWidth());
     }
 
     public int adjustForHiddenSeqs(int alignmentIndex)
@@ -1466,9 +1467,11 @@ public class AlignViewport
     }
 
     /**
-     * This method returns the a new SequenceI [] with
-     * the selection sequence and start and end points adjusted
-     * @return String[]
+     * 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
      */
     public SequenceI[] getSelectionAsNewSequence()
     {
@@ -1477,6 +1480,11 @@ public class AlignViewport
       if (selectionGroup == null)
     {
         sequences = alignment.getSequencesArray();
+        AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
+        for (int i=0; i<sequences.length; i++)
+        {
+          sequences[i] = new Sequence(sequences[i], annots); // construct new sequence with subset of visible annotation
+        }
     }
       else
     {
@@ -1485,7 +1493,24 @@ public class AlignViewport
 
       return sequences;
     }
-
+    
+    /**
+     * get the currently selected sequence objects or all the sequences in the alignment.
+     * @return array of references to sequence objects
+     */
+    public SequenceI[] getSequenceSelection()
+    {
+      SequenceI[] sequences;
+      if (selectionGroup==null)
+      {
+        sequences = alignment.getSequencesArray();
+      }
+      else
+      {
+        sequences = selectionGroup.getSequencesInOrder(alignment);
+      }
+      return sequences;
+    }
     /**
      * This method returns the visible alignment as text, as
      * seen on the GUI, ie if columns are hidden they will not
@@ -1839,6 +1864,67 @@ public class AlignViewport
       viscontigs = colSel.getVisibleContigs(start, end);
       return viscontigs;
     }
-
-
+    /**
+     * get hash of undo and redo list for the alignment
+     * @return long[] { historyList.hashCode, redoList.hashCode };
+     */
+    public long[] getUndoRedoHash()
+    {
+      if (historyList==null || redoList==null)
+        return new long[] { -1, -1};
+      return new long[] { historyList.hashCode(), this.redoList.hashCode() };
+    }
+    /**
+     * test if a particular set of hashcodes are different to the hashcodes for the undo and redo list.
+     * @param undoredo the stored set of hashcodes as returned by getUndoRedoHash
+     * @return true if the hashcodes differ (ie the alignment has been edited) or the stored hashcode array differs in size
+     */
+    public boolean isUndoRedoHashModified(long[] undoredo)
+    {
+      if (undoredo==null)
+      {
+        return true;
+      }
+      long[] cstate = getUndoRedoHash();
+      if (cstate.length!=undoredo.length)
+      {  return true; }
+      
+      for (int i=0; i<cstate.length; i++)
+      {
+        if (cstate[i]!=undoredo[i])
+        {
+          return true;
+        }
+      }
+      return false;
+    }
+    
+    public boolean getCentreColumnLabels()
+    {
+      return centreColumnLabels;
+    }
+    public void setCentreColumnLabels(boolean centrecolumnlabels)
+    {
+      centreColumnLabels =  centrecolumnlabels;
+    }
+    public void updateSequenceIdColours()
+    {
+      Vector groups = alignment.getGroups();
+      if (sequenceColours==null)
+      {
+        sequenceColours = new Hashtable();
+      }
+      for (int ig=0,igSize=groups.size(); ig<igSize; ig++)
+      {
+        SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
+        if (sg.idColour!=null)
+        {
+          Vector sqs = sg.getSequences(hiddenRepSequences);
+          for (int s=0,sSize=sqs.size();s<sSize;s++)
+          {
+            sequenceColours.put(sqs.elementAt(s), sg.idColour);
+          } 
+        }
+      }
+    }
 }