Sequence colour in viewport
[jalview.git] / src / jalview / gui / AlignViewport.java
index 36f69a5..b275611 100755 (executable)
@@ -109,6 +109,9 @@ public class AlignViewport
 
     boolean gatherViewsHere = false;
 
+    Stack historyList = new Stack();
+    Stack redoList = new Stack();
+
     /**
      * Creates a new AlignViewport object.
      *
@@ -231,6 +234,8 @@ public class AlignViewport
                 globalColourScheme.setConsensus(hconsensus);
             }
         }
+
+        wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
     }
 
 
@@ -264,10 +269,16 @@ public class AlignViewport
       {
         try
         {
-          while (updatingConservation)
+          updatingConservation = true;
+
+          while (UPDATING_CONSERVATION)
           {
             try
             {
+              if (ap != null)
+              {
+                ap.repaint();
+              }
               Thread.sleep(200);
             }
             catch (Exception ex)
@@ -276,7 +287,7 @@ public class AlignViewport
             }
           }
 
-          updatingConservation = true;
+          UPDATING_CONSERVATION = true;
 
 
           int alWidth = alignment.getWidth();
@@ -387,11 +398,14 @@ public class AlignViewport
 
         }
 
+        UPDATING_CONSERVATION = false;
+        updatingConservation = false;
+
         if(ap!=null)
         {
           ap.repaint();
         }
-        updatingConservation = false;
+
       }
     }
 
@@ -402,9 +416,13 @@ public class AlignViewport
 
     boolean consUpdateNeeded = false;
 
-    static boolean updatingConsensus = false;
+    static boolean UPDATING_CONSENSUS = false;
+
+    static boolean UPDATING_CONSERVATION = false;
 
-    static boolean updatingConservation = false;
+    boolean updatingConsensus = false;
+
+    boolean updatingConservation = false;
 
     /**
      * DOCUMENT ME!
@@ -437,10 +455,16 @@ public class AlignViewport
       }
       public void run()
       {
-        while (updatingConsensus)
+        updatingConsensus = true;
+        while (UPDATING_CONSENSUS)
         {
           try
           {
+            if (ap != null)
+            {
+              ap.repaint();
+            }
+
             Thread.sleep(200);
           }
           catch (Exception ex)
@@ -449,7 +473,8 @@ public class AlignViewport
           }
         }
 
-        updatingConsensus = true;
+
+        UPDATING_CONSENSUS = true;
 
         try
         {
@@ -497,6 +522,8 @@ public class AlignViewport
         }
         catch (OutOfMemoryError error)
         {
+          alignment.deleteAnnotation(consensus);
+
           consensus = null;
           hconsensus = null;
           javax.swing.SwingUtilities.invokeLater(new Runnable()
@@ -515,14 +542,13 @@ public class AlignViewport
           System.out.println("Consensus calculation: " + error);
           System.gc();
         }
+        UPDATING_CONSENSUS = false;
+        updatingConsensus = false;
 
         if (ap != null)
         {
           ap.repaint();
         }
-
-
-        updatingConsensus = false;
       }
     }
     /**
@@ -543,6 +569,7 @@ public class AlignViewport
             seqs.append(consensus.annotations[i].displayCharacter);
         }
       }
+
       SequenceI sq = new Sequence("Consensus", seqs.toString());
       sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
       return sq;
@@ -1509,10 +1536,25 @@ public class AlignViewport
           updateConservation(ap);
         }
 
+        //Reset endRes of groups if beyond alignment width
+        int alWidth = alignment.getWidth();
+        Vector groups = alignment.getGroups();
+        if(groups!=null)
+        {
+          for(int i=0; i<groups.size(); i++)
+          {
+            SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
+            if(sg.getEndRes()>alWidth)
+              sg.setEndRes(alWidth-1);
+          }
+        }
+
+        if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
+          selectionGroup.setEndRes(alWidth-1);
+
         resetAllColourSchemes();
 
         alignment.adjustSequenceAnnotations();
-
     }