From bcdd5075a79c46e725d8190e2d82311debf64218 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Tue, 5 Dec 2017 03:29:43 +0000 Subject: [PATCH] JAL-2838 Aptx frames now appear in the alignment sorting menu --- src/jalview/ext/archaeopteryx/AptxInit.java | 16 ++++++- src/jalview/ext/archaeopteryx/JalviewBinding.java | 18 ++++++-- src/jalview/gui/AlignFrame.java | 50 ++++++++++++++++++++- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index b9a7ae2..d76214e 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -15,6 +15,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashMap; import java.util.Map; import org.forester.archaeopteryx.AptxUtil; @@ -65,6 +66,8 @@ public final class AptxInit private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG .getTaxonomyExtraction(); + private static Map activeAptx = new HashMap<>(); + public static MainFrame createInstanceFromCalculation( @@ -131,7 +134,7 @@ public final class AptxInit // } Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, treeFile); MainFrame[] aptxFrames = new MainFrame[trees.length]; - String treeTitle = treeFile.getName(); + for (int i = 0; i < trees.length; i++) { @@ -141,6 +144,8 @@ public final class AptxInit { PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, ""); } + String treeTitle = treeFile.getName() + "[" + i + "]"; + tree.setName(treeTitle); aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle); } @@ -496,8 +501,11 @@ public final class AptxInit final Map alignMappedToNodes, final Map nodesMappedToAlign) { - return new JalviewBinding(aptxApp, jalviewAlignViewport, + JalviewBinding treeBinding = new JalviewBinding(aptxApp, + jalviewAlignViewport, alignMappedToNodes, nodesMappedToAlign); + activeAptx.put(aptxApp, treeBinding); + return treeBinding; } @@ -517,6 +525,10 @@ public final class AptxInit } + public static Map getAllAptxFrames() + { + return activeAptx; + } } diff --git a/src/jalview/ext/archaeopteryx/JalviewBinding.java b/src/jalview/ext/archaeopteryx/JalviewBinding.java index 84f4347..61171b3 100644 --- a/src/jalview/ext/archaeopteryx/JalviewBinding.java +++ b/src/jalview/ext/archaeopteryx/JalviewBinding.java @@ -35,6 +35,8 @@ import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; import org.forester.archaeopteryx.MainFrame; import org.forester.phylogeny.Phylogeny; @@ -73,6 +75,8 @@ public final class JalviewBinding private int nrTreeGroups = 0; + private boolean applyToAllViews = false; + /** * * @param archaeopteryx @@ -115,10 +119,19 @@ public final class JalviewBinding ssm.addSelectionListener(this); treeView.addMouseListener(this); PaintRefresher.Register(treeView, parentAvport.getSequenceSetId()); - associatedPanels = PaintRefresher .getAssociatedPanels(parentAvport.getSequenceSetId()); + archaeopteryx.addInternalFrameListener(new InternalFrameAdapter() + { + + @Override + public void internalFrameClosed(InternalFrameEvent e) + { + AptxInit.getAllAptxFrames().remove(archaeopteryx); + } + + }); treeTabs.addChangeListener(new ChangeListener() { @@ -280,9 +293,6 @@ public final class JalviewBinding // of tree { - // int panelHeight = treeView.getHeight(); - // g.drawLine(x, 0, x, panelHeight); - float threshold = (x - rootX) / (furthestNodeX - rootX); List foundNodes = getNodesAboveThreshold(threshold, tree.getRoot()); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 5f26925..afe7ce5 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -61,6 +61,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.ext.archaeopteryx.AptxInit; +import jalview.ext.archaeopteryx.JalviewBinding; import jalview.ext.forester.io.SupportedTreeFileFilter; import jalview.ext.forester.io.TreeParser; import jalview.gui.ColourMenuHelper.ColourChangeListener; @@ -137,6 +138,7 @@ import java.util.Deque; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; @@ -152,6 +154,8 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; +import org.forester.archaeopteryx.MainFrame; + /** * DOCUMENT ME! * @@ -3739,6 +3743,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + /** * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a * TreePanel with an appropriate jalview.analysis.AlignmentSorter @@ -3754,15 +3759,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, List comps = PaintRefresher.components .get(viewport.getSequenceSetId()); List treePanels = new ArrayList<>(); + + Map aptxFrames = AptxInit.getAllAptxFrames(); + for (Component comp : comps) { + // old treepanels if (comp instanceof TreePanel) { treePanels.add((TreePanel) comp); } + } - if (treePanels.size() < 1) + if (treePanels.isEmpty() && aptxFrames.isEmpty()) { sortByTreeMenu.setVisible(false); return; @@ -3770,6 +3780,43 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sortByTreeMenu.setVisible(true); + for (Map.Entry aptxFrameWithBinding : aptxFrames + .entrySet()) + { + MainFrame aptxFrame = aptxFrameWithBinding.getKey(); + JalviewBinding binding = aptxFrameWithBinding.getValue(); + + // future support for multiple tabs + // for (org.forester.archaeopteryx.TreePanel aptxTree : aptxFrame + // .getMainPanel().getTreePanels()) + { + final JMenuItem item = new JMenuItem( + aptxFrame.getMainPanel().getCurrentTreePanel() + .getPhylogeny().getName()); + + item.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + // tp.sortByTree_actionPerformed(); + // addHistoryItem(tp.sortAlignmentIn(alignPanel)); + } + + }); + sortByTreeMenu.add(item); + } + + + + } + + + + + + // old treepanels for (final TreePanel tp : treePanels) { final JMenuItem item = new JMenuItem(tp.getTitle()); @@ -3778,7 +3825,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void actionPerformed(ActionEvent e) { - // adapt to Aptx tp.sortByTree_actionPerformed(); addHistoryItem(tp.sortAlignmentIn(alignPanel)); -- 1.7.10.2