JAL-4134 only build tree when showing it in the tree viewer..
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index e002999..e3cc36e 100755 (executable)
@@ -41,6 +41,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.concurrent.Callable;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenuItem;
@@ -56,6 +57,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.ContactMatrixI;
+import jalview.datamodel.GroupSet;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
@@ -422,30 +424,60 @@ public class AnnotationLabels extends JPanel
         consclipbrd.addActionListener(this);
         pop.add(consclipbrd);
       }
-       if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP
-              && PAEContactMatrix.PAEMATRIX
-                      .equals(aa[selectedRow].getCalcId()))
+      if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP)
       {
-        final PAEContactMatrix cm = (PAEContactMatrix) av
-                .getContactMatrix(aa[selectedRow]);
-        if (cm.getNewick()!=null && cm.getNewick().length()>0)
+        
+        final ContactMatrixI cm = av.getContactMatrix(aa[selectedRow]);
+        if (cm != null)
         {
-          item = new JMenuItem("Show Tree for Matrix");
-          item.addActionListener(new ActionListener()
-          {
+          pop.addSeparator();
 
-            @Override
-            public void actionPerformed(ActionEvent e)
+          if (cm.hasTree())
+          {
+            item = new JMenuItem("Show Tree for Matrix");
+            item.addActionListener(new ActionListener()
             {
 
-                ap.alignFrame.showContactMapTree(aa[selectedRow],cm);
+              @Override
+              public void actionPerformed(ActionEvent e)
+              {
 
-            }
-          });
-          pop.addSeparator();
-          pop.add(item);
-        }
+                ap.alignFrame.showContactMapTree(aa[selectedRow], cm);
 
+              }
+            });
+            pop.add(item);
+          }
+          else
+          {
+            item = new JMenuItem("Calculate Tree for Matrix");
+            item.addActionListener(new ActionListener()
+            {
+              // TODO - refactor to analysis background thread
+              @Override
+              public void actionPerformed(ActionEvent e)
+              {
+                new Thread(new Runnable()
+                {
+                  @Override
+                  public void run()
+                  {
+                    AlignmentAnnotation alan = aa[selectedRow];
+                    cm.setGroupSet(GroupSet.makeGroups(cm, 5f, true));
+                    ap.alignFrame.showContactMapTree(alan, cm);
+                  }
+                }).start();
+              }
+            });
+            pop.add(item);
+
+          }
+          // Show/Hide group shading on matrix view
+          // Set/adjust threshold for grouping ?
+          // colour alignment by this [type]
+          // select/hide columns by this row
+          
+        }
       }
     }
     pop.show(this, evt.getX(), evt.getY());
@@ -1123,7 +1155,8 @@ public class AnnotationLabels extends JPanel
         }
         olY = y;
         // look ahead to next annotation
-        for (nexAA=i+1; nexAA<aa.length && !aa[nexAA].visible; nexAA++)
+        for (nexAA = i + 1; nexAA < aa.length
+                && !aa[nexAA].visible; nexAA++)
           ;
         y += aa[i].height;
         if (clip)
@@ -1273,7 +1306,8 @@ public class AnnotationLabels extends JPanel
         {
           if (vertBar)
           {
-            g.drawLine(width-3, y + offset-fontHeight, width-3, (int)(y - 1.5*aa[i].height-offset-fontHeight));
+            g.drawLine(width - 3, y + offset - fontHeight, width - 3,
+                    (int) (y - 1.5 * aa[i].height - offset - fontHeight));
             // g.drawLine(20, y + offset, x - 20, y + offset);
 
           }