refactored invertColumnSelection as an object method
[jalview.git] / src / jalview / gui / AlignViewport.java
index 88a6e37..afdfd69 100755 (executable)
@@ -29,6 +29,7 @@ import jalview.bin.*;
 import jalview.datamodel.*;
 
 import jalview.schemes.*;
+import jalview.structure.StructureSelectionManager;
 
 /**
  * DOCUMENT ME!
@@ -300,7 +301,7 @@ public class AlignViewport
             {
               if (ap != null)
               {
-              ap.paintAlignment(true);
+                ap.paintAlignment(false);
               }
               Thread.sleep(200);
             }
@@ -496,7 +497,7 @@ public class AlignViewport
           {
             if (ap != null)
             {
-            ap.paintAlignment(true);
+            ap.paintAlignment(false);
             }
 
             Thread.sleep(200);
@@ -916,7 +917,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 +1453,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,11 +1462,11 @@ public class AlignViewport
     }
 
     /**
-     * This method returns an array of new SequenceI objects 
+     * 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 String[]
+     * @return selection as new sequenceI objects
      */
     public SequenceI[] getSelectionAsNewSequence()
     {
@@ -1479,9 +1475,10 @@ 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]); // construct new sequence
+          sequences[i] = new Sequence(sequences[i], annots); // construct new sequence with subset of visible annotation
         }
     }
       else
@@ -1491,6 +1488,7 @@ 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
@@ -1861,6 +1859,38 @@ 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;
+    }
 }