From 62f2ed464010270830afcfe954647a51dfb5114b Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Fri, 24 Nov 2017 18:00:50 +0000 Subject: [PATCH] JAL-2799 all tabs now get mouse listeners and Jalview switches tree view --- src/jalview/ext/archaeopteryx/JalviewBinding.java | 56 ++++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/JalviewBinding.java b/src/jalview/ext/archaeopteryx/JalviewBinding.java index dae01f1..7a0668d 100644 --- a/src/jalview/ext/archaeopteryx/JalviewBinding.java +++ b/src/jalview/ext/archaeopteryx/JalviewBinding.java @@ -39,9 +39,11 @@ import org.forester.phylogeny.PhylogenyNode; public final class JalviewBinding implements ExternalTreeViewerBindingI { - private org.forester.archaeopteryx.TreePanel treeView; + private final MainFrame aptxFrame; - private AlignmentViewport parentAvport; + private org.forester.archaeopteryx.TreePanel currentTreeView; + + private final AlignmentViewport parentAvport; private JTabbedPane treeTabs; @@ -72,19 +74,30 @@ public final class JalviewBinding final Map nodesMappedToAlign) { // deal with/prohibit null values here as that will cause problems + aptxFrame = archaeopteryx; parentAvport = jalviewAlignmentViewport; sequencesBoundToNodes = alignMappedToNodes; nodesBoundToSequences = nodesMappedToAlign; - treeView = archaeopteryx.getMainPanel().getCurrentTreePanel(); - treeTabs = archaeopteryx.getMainPanel().getTabbedPane(); + treeTabs = aptxFrame.getMainPanel().getTabbedPane(); ssm = parentAvport.getStructureSelectionManager(); // archaeopteryx.getMainPanel().getControlPanel().setColorBranches(true); ssm.addSelectionListener(this); - treeView.addMouseListener(this); - PaintRefresher.Register(treeView, parentAvport.getSequenceSetId()); + + int tabCount = treeTabs.getTabCount(); + + for (int i = 0; i < tabCount; i++) + { + // roundabout way to select each tree because getComponentAt(i) requires + // casting to TreePanel which doesn't work + treeTabs.setSelectedIndex(i); + currentTreeView = aptxFrame.getMainPanel().getCurrentTreePanel(); + currentTreeView.addMouseListener(this); + PaintRefresher.Register(currentTreeView, + parentAvport.getSequenceSetId()); + } treeTabs.addChangeListener(new ChangeListener() @@ -106,9 +119,9 @@ public final class JalviewBinding */ public void run() { + currentTreeView = aptxFrame.getMainPanel() + .getCurrentTreePanel(); parentAvport.sendSelection(); - // PaintRefresher.Refresh(treeView, - // parentAvport.getSequenceSetId()); } }); @@ -135,13 +148,16 @@ public final class JalviewBinding */ public void run() { - final PhylogenyNode node = treeView.findNode(e.getX(), e.getY()); + + final PhylogenyNode node = currentTreeView.findNode(e.getX(), + e.getY()); if (node != null) { if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) // clear previous // selection if shift // IS NOT pressed { + parentAvport.setSelectionGroup(null); } @@ -189,7 +205,7 @@ public final class JalviewBinding if (source == parentAvport) // check if source is alignment from where the // tree originates { - treeView.setFoundNodes0( + currentTreeView.setFoundNodes0( new HashSet(seqsel.getSequences().size())); for (SequenceI selectedSequence : seqsel.getSequences()) @@ -197,11 +213,11 @@ public final class JalviewBinding PhylogenyNode matchingNode = sequencesBoundToNodes.get(selectedSequence); if (matchingNode != null) { - treeView.getFoundNodes0().add(matchingNode.getId()); + currentTreeView.getFoundNodes0().add(matchingNode.getId()); } } - treeView.repaint(); + aptxFrame.repaint(); } @@ -214,16 +230,16 @@ public final class JalviewBinding public void partitionTree(final MouseEvent e) { int x = e.getX(); - int lineLength = treeView.getHeight(); + int lineLength = currentTreeView.getHeight(); - Phylogeny tree = treeView.getPhylogeny(); + Phylogeny tree = currentTreeView.getPhylogeny(); double treeHeight = tree.calculateHeight(true); if (treeHeight != 0) { - int viewWidth = treeView.getWidth(); + int viewWidth = currentTreeView.getWidth(); // treeView.validate(); @@ -267,7 +283,7 @@ public final class JalviewBinding if (matchingSequence != null) { long nodeId = nodeToMatch.getId(); - addOrRemoveInSet(treeView.getFoundNodes0(), nodeId); + addOrRemoveInSet(currentTreeView.getFoundNodes0(), nodeId); treeSelectionChanged(matchingSequence); parentAvport.sendSelection(); @@ -289,7 +305,7 @@ public final class JalviewBinding if (matchingSequence != null) { long nodeId = childNode.getId(); - addOrRemoveInSet(treeView.getFoundNodes0(), nodeId); + addOrRemoveInSet(currentTreeView.getFoundNodes0(), nodeId); treeSelectionChanged(matchingSequence); @@ -424,11 +440,13 @@ public final class JalviewBinding return parentAvport; } - public void setParentAvport(final AlignmentViewport parentAvport) + public org.forester.archaeopteryx.TreePanel getTreeView() { - this.parentAvport = parentAvport; + return currentTreeView; } + } + -- 1.7.10.2