Sequence colour in viewport
[jalview.git] / src / jalview / gui / AlignViewport.java
index efce038..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,6 +269,27 @@ public class AlignViewport
       {
         try
         {
+          updatingConservation = true;
+
+          while (UPDATING_CONSERVATION)
+          {
+            try
+            {
+              if (ap != null)
+              {
+                ap.repaint();
+              }
+              Thread.sleep(200);
+            }
+            catch (Exception ex)
+            {
+              ex.printStackTrace();
+            }
+          }
+
+          UPDATING_CONSERVATION = true;
+
+
           int alWidth = alignment.getWidth();
           if(alWidth<0)
             return;
@@ -372,21 +398,28 @@ public class AlignViewport
 
         }
 
+        UPDATING_CONSERVATION = false;
+        updatingConservation = false;
+
         if(ap!=null)
         {
           ap.repaint();
         }
-        updatingConservation = false;
+
       }
     }
 
 
-    static ConservationThread conservationThread;
+    ConservationThread conservationThread;
 
-    static ConsensusThread consensusThread;
+    ConsensusThread consensusThread;
 
     boolean consUpdateNeeded = false;
 
+    static boolean UPDATING_CONSENSUS = false;
+
+    static boolean UPDATING_CONSERVATION = false;
+
     boolean updatingConsensus = false;
 
     boolean updatingConservation = false;
@@ -399,21 +432,8 @@ public class AlignViewport
       if (alignment.isNucleotide() || conservation==null)
         return;
 
-      updatingConservation = true;
-    // javax.swing.SwingUtilities.invokeLater(new Runnable()      {        public void run()  {
-          while (conservationThread != null && conservationThread.isAlive())
-          {
-            try
-            {
-           //   Thread.sleep(100);
-              ap.repaint();
-            }
-            catch (Exception ex)
-            {}
-          }
-          conservationThread = new ConservationThread(ap);
-          conservationThread.start();
-      //  }      });
+      conservationThread = new ConservationThread(ap);
+      conservationThread.start();
     }
 
     /**
@@ -421,22 +441,8 @@ public class AlignViewport
      */
     public void updateConsensus(final AlignmentPanel ap)
     {
-      updatingConsensus = true;
-
-     // javax.swing.SwingUtilities.invokeLater(new Runnable()      {        public void run()   {
-          while (consensusThread != null && consensusThread.isAlive())
-          {
-            try
-            {
-          //    Thread.sleep(100);
-              ap.repaint();
-            }
-            catch (Exception ex)
-            {}
-          }
-          consensusThread = new ConsensusThread(ap);
-          consensusThread.start();
-      //  }      });
+      consensusThread = new ConsensusThread(ap);
+      consensusThread.start();
     }
 
 
@@ -449,6 +455,27 @@ public class AlignViewport
       }
       public void run()
       {
+        updatingConsensus = true;
+        while (UPDATING_CONSENSUS)
+        {
+          try
+          {
+            if (ap != null)
+            {
+              ap.repaint();
+            }
+
+            Thread.sleep(200);
+          }
+          catch (Exception ex)
+          {
+            ex.printStackTrace();
+          }
+        }
+
+
+        UPDATING_CONSENSUS = true;
+
         try
         {
           int aWidth = alignment.getWidth();
@@ -495,6 +522,8 @@ public class AlignViewport
         }
         catch (OutOfMemoryError error)
         {
+          alignment.deleteAnnotation(consensus);
+
           consensus = null;
           hconsensus = null;
           javax.swing.SwingUtilities.invokeLater(new Runnable()
@@ -513,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;
       }
     }
     /**
@@ -541,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;
@@ -1507,6 +1536,22 @@ 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();