update author list in license for (JAL-826)
[jalview.git] / src / jalview / appletgui / TreeCanvas.java
index 4e15fd3..06b92ca 100755 (executable)
@@ -1,20 +1,19 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
  * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
  * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  */
 package jalview.appletgui;
 
@@ -65,9 +64,11 @@ public class TreeCanvas extends Panel implements MouseListener,
 
   SequenceNode highlightNode;
 
-  public TreeCanvas(AlignViewport av, ScrollPane scroller)
+  AlignmentPanel ap; 
+  public TreeCanvas(AlignmentPanel ap, ScrollPane scroller)
   {
-    this.av = av;
+    this.ap = ap;
+    this.av = ap.av;
     font = av.getFont();
     scrollPane = scroller;
     addMouseListener(this);
@@ -185,8 +186,7 @@ public class TreeCanvas extends Panel implements MouseListener,
       }
 
       String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node
-              .getName())
-              : node.getName();
+              .getName()) : node.getName();
       FontMetrics fm = g.getFontMetrics(font);
       int charWidth = fm.stringWidth(name) + 3;
       int charHeight = fm.getHeight();
@@ -424,9 +424,8 @@ public class TreeCanvas extends Panel implements MouseListener,
     setSize(new Dimension(width, height));
 
     g.setFont(font);
-
     draw(g, width, height);
-
+    validate();
   }
 
   public void draw(Graphics g, int width, int height)
@@ -437,9 +436,9 @@ public class TreeCanvas extends Panel implements MouseListener,
     g.fillRect(0, 0, width, height);
 
     labelLength = g.getFontMetrics(font).stringWidth(longestName) + 20; // 20
-                                                                        // allows
-                                                                        // for
-                                                                        // scrollbar
+    // allows
+    // for
+    // scrollbar
 
     float wscale = (float) (width - labelLength - offx * 2)
             / tree.getMaxHeight();
@@ -511,6 +510,7 @@ public class TreeCanvas extends Panel implements MouseListener,
 
       PaintRefresher.Refresh(this, av.getSequenceSetId());
       repaint();
+      av.sendSelection();
     }
   }
 
@@ -553,6 +553,7 @@ public class TreeCanvas extends Panel implements MouseListener,
       treeSelectionChanged((Sequence) ob);
       PaintRefresher.Refresh(this, av.getSequenceSetId());
       repaint();
+      av.sendSelection();
       return;
     }
     else if (!(ob instanceof SequenceNode))
@@ -587,12 +588,12 @@ public class TreeCanvas extends Panel implements MouseListener,
     for (int i = 0; i < tree.getGroups().size(); i++)
     {
 
-      Color col = new Color((int) (Math.random() * 255), (int) (Math
-              .random() * 255), (int) (Math.random() * 255));
+      Color col = new Color((int) (Math.random() * 255),
+              (int) (Math.random() * 255), (int) (Math.random() * 255));
       setColor((SequenceNode) tree.getGroups().elementAt(i), col.brighter());
 
-      Vector l = tree.findLeaves((SequenceNode) tree.getGroups().elementAt(
-              i), new Vector());
+      Vector l = tree.findLeaves(
+              (SequenceNode) tree.getGroups().elementAt(i), new Vector());
 
       Vector sequences = new Vector();
       for (int j = 0; j < l.size(); j++)
@@ -611,8 +612,9 @@ public class TreeCanvas extends Panel implements MouseListener,
       {
         if (av.getGlobalColourScheme() instanceof UserColourScheme)
         {
-          cs = new UserColourScheme(((UserColourScheme) av
-                  .getGlobalColourScheme()).getColours());
+          cs = new UserColourScheme(
+                  ((UserColourScheme) av.getGlobalColourScheme())
+                          .getColours());
 
         }
         else
@@ -621,9 +623,12 @@ public class TreeCanvas extends Panel implements MouseListener,
                   .getWidth(), ColourSchemeProperty.getColourName(av
                   .getGlobalColourScheme()));
         }
-
-        cs.setThreshold(av.getGlobalColourScheme().getThreshold(), av
-                .getIgnoreGapsConsensus());
+        // cs is null if shading is an annotationColourGradient
+        if (cs!=null)
+        {
+          cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
+                  av.getIgnoreGapsConsensus());
+        }
       }
 
       SequenceGroup sg = new SequenceGroup(sequences, "", cs, true, true,
@@ -635,8 +640,8 @@ public class TreeCanvas extends Panel implements MouseListener,
               && av.getGlobalColourScheme().conservationApplied())
       {
         Conservation c = new Conservation("Group",
-                ResidueProperties.propHash, 3, sg.getSequences(null), sg
-                        .getStartRes(), sg.getEndRes());
+                ResidueProperties.propHash, 3, sg.getSequences(null),
+                sg.getStartRes(), sg.getEndRes());
 
         c.calculate();
         c.verdict(false, av.ConsPercGaps);
@@ -649,7 +654,8 @@ public class TreeCanvas extends Panel implements MouseListener,
       av.alignment.addGroup(sg);
 
     }
-
+    ap.updateAnnotation();
+    
   }
 
   public void setShowDistances(boolean state)