Reset colour schemes and alignmentChanged moved to viewport
authoramwaterhouse <Andrew Waterhouse>
Fri, 27 Oct 2006 16:15:41 +0000 (16:15 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 27 Oct 2006 16:15:41 +0000 (16:15 +0000)
src/jalview/gui/AlignViewport.java

index c0e9dc9..efce038 100755 (executable)
@@ -109,13 +109,6 @@ public class AlignViewport
 
     boolean gatherViewsHere = false;
 
-
-    public AlignViewport(AlignmentI al, boolean dataset)
-    {
-      isDataset = dataset;
-      setAlignment(al);
-      init();
-    }
     /**
      * Creates a new AlignViewport object.
      *
@@ -155,7 +148,7 @@ public class AlignViewport
 
       autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
 
-      padGaps = Cache.getDefault("PAD_GAPS", false);
+      padGaps = Cache.getDefault("PAD_GAPS", true);
 
        String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
        String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
@@ -174,7 +167,6 @@ public class AlignViewport
 
        setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
 
-
        alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
 
 
@@ -221,7 +213,6 @@ public class AlignViewport
            {
              alignment.addAnnotation(consensus);
            }
-
         }
 
         if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
@@ -289,7 +280,6 @@ public class AlignViewport
             cons.findQuality();
           }
 
-
           String sequence = cons.getConsSequence().getSequence();
           float minR;
           float minG;
@@ -391,9 +381,9 @@ public class AlignViewport
     }
 
 
-    ConservationThread conservationThread;
+    static ConservationThread conservationThread;
 
-    ConsensusThread consensusThread;
+    static ConsensusThread consensusThread;
 
     boolean consUpdateNeeded = false;
 
@@ -404,42 +394,49 @@ public class AlignViewport
     /**
      * DOCUMENT ME!
      */
-    public void updateConservation(AlignmentPanel ap)
+    public void updateConservation(final AlignmentPanel ap)
     {
-      if (alignment.isNucleotide())
+      if (alignment.isNucleotide() || conservation==null)
         return;
 
       updatingConservation = true;
-
-      if (conservationThread == null || !conservationThread.isAlive())
-      {
-        conservationThread = new ConservationThread(ap);
-        conservationThread.start();
-      }
-      else
-      {
-        consUpdateNeeded = true;
-        System.out.println("come back later");
-      }
+    // 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();
+      //  }      });
     }
 
     /**
      * DOCUMENT ME!
      */
-    public void updateConsensus(AlignmentPanel ap)
+    public void updateConsensus(final AlignmentPanel ap)
     {
       updatingConsensus = true;
 
-      if (consensusThread == null || !consensusThread.isAlive())
-      {
-        consensusThread = new ConsensusThread(ap);
-        consensusThread.start();
-      }
-      else
-      {
-        consUpdateNeeded = true;
-        System.out.println("come back later");
-      }
+     // 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();
+      //  }      });
     }
 
 
@@ -1499,4 +1496,63 @@ public class AlignViewport
       return sequenceSetID;
     }
 
+    public void alignmentChanged(AlignmentPanel ap)
+    {
+        if (padGaps)
+          alignment.padGaps();
+
+        if (hconsensus != null && autoCalculateConsensus)
+        {
+          updateConsensus(ap);
+          updateConservation(ap);
+        }
+
+        resetAllColourSchemes();
+
+        alignment.adjustSequenceAnnotations();
+    }
+
+
+    void resetAllColourSchemes()
+    {
+      ColourSchemeI cs = globalColourScheme;
+      if(cs!=null)
+      {
+        if (cs instanceof ClustalxColourScheme)
+        {
+          ( (ClustalxColourScheme) cs).
+              resetClustalX(alignment.getSequences(),
+                            alignment.getWidth());
+        }
+
+        cs.setConsensus(hconsensus);
+        if (cs.conservationApplied())
+        {
+          Alignment al = (Alignment) alignment;
+          Conservation c = new Conservation("All",
+                                            ResidueProperties.propHash, 3,
+                                            al.getSequences(), 0,
+                                            al.getWidth() - 1);
+          c.calculate();
+          c.verdict(false, ConsPercGaps);
+
+          cs.setConservation(c);
+        }
+      }
+
+      int s, sSize = alignment.getGroups().size();
+      for(s=0; s<sSize; s++)
+      {
+        SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
+        if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
+        {
+          ((ClustalxColourScheme)sg.cs).resetClustalX(
+              sg.getSequences(true), sg.getWidth());
+        }
+        sg.recalcConservation();
+      }
+    }
+
+
+
 }