JAL-2794 PaintRefresher support, Aptx node selection now shown on align
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Thu, 9 Nov 2017 16:12:00 +0000 (16:12 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Thu, 9 Nov 2017 16:12:00 +0000 (16:12 +0000)
src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java
src/jalview/ext/archaeopteryx/JalviewAptxBinding.java

index 9b654f0..aaf7ffb 100644 (file)
@@ -57,7 +57,8 @@ public final class ArchaeopteryxInit
     MainFrame aptxApp = createBoundAptxFrame(aptxTrees,
             calculatedTree.getAvport());
     bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
-            aptxTreeBuilder.getAlignmentBoundNodes());
+            aptxTreeBuilder.getAlignmentBoundNodes(),
+            aptxTreeBuilder.getNodesBoundAlignment());
     return bindFrameToJalview(aptxApp);
 
   }
@@ -76,10 +77,11 @@ public final class ArchaeopteryxInit
 
   private static void bindNodesToJalviewSequences(MainFrame aptxApp,
           AlignmentViewport jalviewAlignViewport,
-          Map<SequenceI, PhylogenyNode> alignMappedToNodes)
+          Map<SequenceI, PhylogenyNode> alignMappedToNodes,
+          Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
   {
     new JalviewAptxBinding(aptxApp, jalviewAlignViewport,
-            alignMappedToNodes);
+            alignMappedToNodes, nodesMappedToAlign);
   }
 
 
index c2b48ab..a3bff2d 100644 (file)
@@ -4,6 +4,7 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.PaintRefresher;
 import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.viewmodel.AlignmentViewport;
@@ -25,19 +26,23 @@ public class JalviewAptxBinding implements JalviewTreeViewerBindingI
 
   StructureSelectionManager ssm;
 
-  Map<SequenceI, PhylogenyNode> sequencesBelongingToNodes;
+  Map<SequenceI, PhylogenyNode> sequencesBoundToNodes;
 
+  Map<PhylogenyNode, SequenceI> nodesBoundToSequences;
 
   public JalviewAptxBinding(MainFrame archaeopteryx,
           AlignmentViewport jalviewAlignmentViewport,
-          Map<SequenceI, PhylogenyNode> alignMappedToNodes)
+          Map<SequenceI, PhylogenyNode> alignMappedToNodes,
+          Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
   {
     parentAvport = jalviewAlignmentViewport;
-    sequencesBelongingToNodes = alignMappedToNodes;
+    sequencesBoundToNodes = alignMappedToNodes;
+    nodesBoundToSequences = nodesMappedToAlign;
     treeView = archaeopteryx.getMainPanel().getCurrentTreePanel();
     ssm = parentAvport.getStructureSelectionManager();
     ssm.addSelectionListener(this);
     treeView.addMouseListener(this);
+    PaintRefresher.Register(treeView, parentAvport.getSequenceSetId());
   }
 
   @Override
@@ -88,11 +93,14 @@ public class JalviewAptxBinding implements JalviewTreeViewerBindingI
 
       for (SequenceI sequence : seqsel.getSequences())
       {
-        PhylogenyNode matchingNode = sequencesBelongingToNodes.get(sequence);
-        treeView.getFoundNodes0().add(matchingNode.getId());
+        PhylogenyNode matchingNode = sequencesBoundToNodes.get(sequence);
+        if (matchingNode != null)
+        {
+          treeView.getFoundNodes0().add(matchingNode.getId());
+        }
 
       }
-      treeView.repaint();
+      PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
 
     }
 
@@ -105,22 +113,59 @@ public class JalviewAptxBinding implements JalviewTreeViewerBindingI
     final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
     if (node != null && node.isExternal())
     {
+      SequenceI matchingSequence = nodesBoundToSequences.get(node);
 
       if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) // shift is pressed
       // (so multiple nodes
       // can be selected)
       {
 
-        System.out.println(treeView.getFoundNodes0().toString());
       }
+      else
+      {
+        parentAvport.setSelectionGroup(null); // reset selection if shift isn't
+                                              // pressed
+      }
+
+      treeSelectionChanged(matchingSequence);
+      parentAvport.sendSelection(); // not actually needed?
+
+      PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
     }
 
-  }
+    }
+
+  /**
+   * Refactored from TreeCanvas
+   * 
+   * @param sequence
+   */
+  public void treeSelectionChanged(SequenceI sequence)
+  {
+    SequenceGroup selected = parentAvport.getSelectionGroup();
 
+    if (selected == null)
+    {
+      selected = new SequenceGroup();
+      parentAvport.setSelectionGroup(selected);
+    }
 
+    selected.setEndRes(parentAvport.getAlignment().getWidth() - 1);
+    selected.addOrRemove(sequence, true);
+
+  }
 
+  public AlignmentViewport getParentAvport()
+  {
+    return parentAvport;
+  }
 
+  public void setParentAvport(AlignmentViewport parentAvport)
+  {
+    this.parentAvport = parentAvport;
   }
 
+}
+