JAL-2799 fixed selections not carrying over to tabs with invokeLater
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 22 Nov 2017 10:52:10 +0000 (10:52 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 22 Nov 2017 10:52:10 +0000 (10:52 +0000)
src/jalview/ext/archaeopteryx/JalviewBinding.java

index ee349b6..deadfe4 100644 (file)
@@ -17,6 +17,11 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyNode;
@@ -36,6 +41,8 @@ public final class JalviewBinding
 
   private AlignmentViewport parentAvport;
 
+  private JTabbedPane treeTabs;
+
   private final StructureSelectionManager ssm;
 
   private Map<SequenceI, PhylogenyNode> sequencesBoundToNodes;
@@ -66,12 +73,46 @@ public final class JalviewBinding
     parentAvport = jalviewAlignmentViewport;
     sequencesBoundToNodes = alignMappedToNodes;
     nodesBoundToSequences = nodesMappedToAlign;
+
     treeView = archaeopteryx.getMainPanel().getCurrentTreePanel();
+    treeTabs = archaeopteryx.getMainPanel().getTabbedPane();
     ssm = parentAvport.getStructureSelectionManager();
+
+   // archaeopteryx.getMainPanel().getControlPanel().setColorBranches(true);
+    
     ssm.addSelectionListener(this);
     treeView.addMouseListener(this);
     PaintRefresher.Register(treeView, parentAvport.getSequenceSetId());
 
+
+    treeTabs.addChangeListener(new ChangeListener()
+    {
+
+      @Override
+      public void stateChanged(ChangeEvent e)
+      {
+
+        SwingUtilities.invokeLater(new Runnable()
+        {
+
+          @Override
+          /**
+           * Resend the selection to the tree view when tabs get switched, this
+           * has to be buried in invokeLater as Forester first resets the tree
+           * view on switching tabs, without invokeLater this would get called
+           * before Forester resets which would nullify the selection
+           */
+          public void run()
+          {
+            parentAvport.sendSelection();
+
+          }
+        });
+
+      }
+      
+    });
+
   }
 
   @Override
@@ -183,6 +224,7 @@ public final class JalviewBinding
 
     for (PhylogenyNode childNode : childNodes)
     {
+      // childNode.getBranchData().setBranchColor(new BranchColor(Color.BLUE));
 
       SequenceI matchingSequence = nodesBoundToSequences.get(childNode);
       if (matchingSequence != null)
@@ -191,7 +233,6 @@ public final class JalviewBinding
 
       }
     }
-
     parentAvport.sendSelection();
     PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
   }
@@ -227,79 +268,6 @@ public final class JalviewBinding
   {
     this.parentAvport = parentAvport;
   }
-  // av.setCurrentTree(tree);
-  //
-  // /*
-  // * isPopupTrigger is set for mousePressed (Mac)
-  // * or mouseReleased (Windows)
-  // */
-  // if (e.isPopupTrigger())
-  // {
-  // if (highlightNode != null)
-  // {
-  // chooseSubtreeColour();
-  // }
-  // return;
-  // }
-  //
-  // /*
-  // * defer right-click handling on Windows to
-  // * mouseClicked; note isRightMouseButton
-  // * also matches Cmd-click on Mac which should do
-  // * nothing here
-  // */
-  // if (SwingUtilities.isRightMouseButton(e))
-  // {
-  // return;
-  // }
-  //
-  // int x = e.getX();
-  // int y = e.getY();
-  //
-  // Object ob = findElement(x, y);
-  //
-  // if (ob instanceof SequenceI)
-  // {
-  // treeSelectionChanged((Sequence) ob);
-  // PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
-  // repaint();
-  // av.sendSelection();
-  // return;
-  // }
-  // else if (!(ob instanceof SequenceNode))
-  // {
-  // // Find threshold
-  // if (tree.getMaxHeight() != 0)
-  // {
-  // threshold = (float) (x - offx)
-  // / (float) (getWidth() - labelLength - (2 * offx));
-  //
-  // List<SequenceNode> groups = tree.groupNodes(threshold);
-  // setColor(tree.getTopNode(), Color.black);
-  //
-  // AlignmentPanel[] aps = getAssociatedPanels();
-  //
-  // // TODO push calls below into a single AlignViewportI method?
-  // // see also AlignViewController.deleteGroups
-  // for (int a = 0; a < aps.length; a++)
-  // {
-  // aps[a].av.setSelectionGroup(null);
-  // aps[a].av.getAlignment().deleteAllGroups();
-  // aps[a].av.clearSequenceColours();
-  // if (aps[a].av.getCodingComplement() != null)
-  // {
-  // aps[a].av.getCodingComplement().setSelectionGroup(null);
-  // aps[a].av.getCodingComplement().getAlignment()
-  // .deleteAllGroups();
-  // aps[a].av.getCodingComplement().clearSequenceColours();
-  // }
-  // }
-  // colourGroups(groups);
-  // }
-  //
-  // PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
-  // repaint();
-  // }
 }