From 163acbff0a52f00ca79bd5eec693009738d1b370 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Mon, 18 Dec 2017 15:08:51 +0000 Subject: [PATCH] JAL-1953 redundant tree interface instantiation removed --- forester | 2 +- src/jalview/ext/archaeopteryx/AptxFrame.java | 22 ++++- src/jalview/ext/archaeopteryx/AptxInit.java | 96 ++++++++++++++-------- src/jalview/ext/archaeopteryx/AptxTreePanel.java | 11 ++- src/jalview/ext/archaeopteryx/Tree.java | 2 +- src/jalview/ext/treeviewer/ExternalTreeI.java | 3 +- 6 files changed, 95 insertions(+), 41 deletions(-) diff --git a/forester b/forester index 1706dee..3d5864a 160000 --- a/forester +++ b/forester @@ -1 +1 @@ -Subproject commit 1706deea223bc1a30d170596192d726b6847b7eb +Subproject commit 3d5864a39739960c126f2ab5585162fd52d1f47d diff --git a/src/jalview/ext/archaeopteryx/AptxFrame.java b/src/jalview/ext/archaeopteryx/AptxFrame.java index e7a1517..c517ed3 100644 --- a/src/jalview/ext/archaeopteryx/AptxFrame.java +++ b/src/jalview/ext/archaeopteryx/AptxFrame.java @@ -32,7 +32,10 @@ import javax.swing.JRootPane; import javax.swing.JSeparator; import javax.swing.event.InternalFrameListener; +import org.forester.archaeopteryx.Archaeopteryx; +import org.forester.archaeopteryx.Configuration; import org.forester.archaeopteryx.MainFrame; +import org.forester.phylogeny.Phylogeny; import org.jibble.epsgraphics.EpsGraphics2D; public class AptxFrame implements ExternalTreeFrame @@ -43,8 +46,20 @@ public class AptxFrame implements ExternalTreeFrame private ExternalTreeControlsI aptxControls; + + public AptxFrame(Phylogeny tree, Configuration aptxConfig, + String treeTitle) + { + this(Archaeopteryx.createApplication(tree, + aptxConfig, + treeTitle)); + + } + + public AptxFrame(MainFrame aptx) { + aptxFrame = aptx; aptxPanel = new AptxTreePanel( aptxFrame.getMainPanel().getCurrentTreePanel()); @@ -53,15 +68,16 @@ public class AptxFrame implements ExternalTreeFrame adaptAptxGui(aptxFrame); } + /** * Hides certain redundant Archaeopteryx GUI elements such as the menu items * for reading in trees and adds extra items related to Jalview such as the - * tree sorting item. + * tree sorting menu item. * * * @param aptxFrame */ - private void adaptAptxGui(MainFrame aptxFrame) + protected void adaptAptxGui(MainFrame aptxFrame) { JMenuBar frameBar = aptxFrame.getJMenuBar(); boolean epsAdded = false; @@ -151,7 +167,7 @@ public class AptxFrame implements ExternalTreeFrame } } - aptxFrame.validate(); + // aptxFrame.validate(); } public void epsTree_actionPerformed(ActionEvent e) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index d0fb9fe..f7ec0ad 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -87,6 +87,7 @@ public final class AptxInit return aptxApp; } + /** * Refactored from Archaeopteryx.main * @@ -155,8 +156,7 @@ public final class AptxInit } String treeTitle = treeFile.getName() + "[" + i + "]"; aptxPhylogeny.setName(treeTitle); - Tree aptxTree = new Tree(aptxPhylogeny); - aptxFrames[i] = createAptxFrame(aptxTree, viewport, treeTitle); + aptxFrames[i] = createAptxFrame(aptxPhylogeny, viewport, treeTitle); } if (Desktop.instance != null) @@ -187,8 +187,7 @@ public final class AptxInit for (int i = 0; i < trees.length; i++) { Phylogeny aptxTree = trees[i]; - Tree jalviewTree = new Tree(aptxTree); - aptxFrames[i] = createAptxFrame(jalviewTree, viewport, treeTitle); + aptxFrames[i] = createAptxFrame(aptxTree, viewport, treeTitle); } if (Desktop.instance != null) @@ -214,6 +213,7 @@ public final class AptxInit URL url = null; Phylogeny[] trees = null; + ExternalTreeFrame[] aptxFrames = null; if ((identifier != null) && (identifier.trim().length() > 0)) { @@ -317,6 +317,7 @@ public final class AptxInit // _main_frame.getMainPanel().setWaitCursor(); // } trees = ForesterUtil.readPhylogeniesFromUrl(url, parser); + aptxFrames = new ExternalTreeFrame[trees.length]; } catch (final MalformedURLException e) { exception = true; @@ -358,6 +359,7 @@ public final class AptxInit } if ((trees != null) && (trees.length > 0)) { + int i = 0; for (final Phylogeny aptxTree : trees) { if (!aptxTree.isEmpty()) @@ -402,15 +404,14 @@ public final class AptxInit // _main_frame.getConfiguration(), // new File(url.getFile()).getName(), url.toString()); - Tree jalviewTree = new Tree(aptxTree); - ExternalTreeFrame aptxApp = createAptxFrame(jalviewTree, + ExternalTreeFrame aptxApp = createAptxFrame(aptxTree, viewport, url.getFile()); String my_name_for_file = ""; - if (!ForesterUtil.isEmpty(jalviewTree.getTreeName())) + if (!ForesterUtil.isEmpty(aptxTree.getName())) { - my_name_for_file = new String(jalviewTree.getTreeName()) + my_name_for_file = new String(aptxTree.getName()) .replaceAll(" ", "_"); } else if (aptxTree.getIdentifier() != null) @@ -434,6 +435,7 @@ public final class AptxInit aptxApp.getTreeControls().displayEntireTree(); aptxApp.checkMultipleTrees(); + aptxFrames[i++] = aptxApp; } } } @@ -468,40 +470,46 @@ public final class AptxInit { Desktop.instance.stopLoading(); } - return null; + return aptxFrames; } - - - public static ExternalTreeFrame createAptxFrame( - final ExternalTreeI aptxTree, - final AlignmentViewport jalviewAlignport, String treeTitle) + public static ExternalTreeFrame createAptxFrame(ExternalTreeI aptxTree, + AlignmentViewport jalviewAlignport, String treeTitle) { - if (APTX_CONFIG == null || APTX_CONFIG.isCouldReadConfigFile() == false) - { - int keepGoing = JvOptionPane.showConfirmDialog(Desktop.desktop, - MessageManager.getString("label.aptx_config_not_found"), - MessageManager.formatMessage("label.couldnt_locate", - new String[] - { "_aptx_jalview_configuration_file" }), - JvOptionPane.YES_NO_CANCEL_OPTION); + validateConfig(APTX_CONFIG); + ExternalTreeFrame aptxApp = aptxTree + .createTreeViewerFromTree(treeTitle); + ExternalTreeI jalviewTree = aptxApp.getTree(); + ExternalLoadedTreeAssociationI bindAptxNodes = new LoadedTreeSequenceAssociation( + jalviewAlignport.getAlignment().getSequencesArray(), + jalviewTree); + bindAptxNodes.associateLeavesToSequences(); - if (keepGoing == JvOptionPane.CANCEL_OPTION - || keepGoing == JvOptionPane.CLOSED_OPTION - || keepGoing == JvOptionPane.NO_OPTION) - { - return null; - } + bindNodesToJalviewSequences(aptxApp, jalviewAlignport, + bindAptxNodes.getAlignmentWithNodes(), + bindAptxNodes.getNodesWithAlignment()); + bindTreeViewFrameToJalview(aptxApp); - } - ExternalTreeFrame aptxApp = aptxTree.createInstanceFromTree(treeTitle); + // adaptAptxGui(aptxApp); //moved to AptxFrame + return aptxApp; + } + + protected static ExternalTreeFrame createAptxFrame( + final Phylogeny aptxTree, + final AlignmentViewport jalviewAlignport, String treeTitle) + { + validateConfig(APTX_CONFIG); + ExternalTreeFrame aptxApp = new AptxFrame(aptxTree, APTX_CONFIG, + treeTitle); + ExternalTreeI jalviewTree = aptxApp.getTree(); ExternalLoadedTreeAssociationI bindAptxNodes = new LoadedTreeSequenceAssociation( - jalviewAlignport.getAlignment().getSequencesArray(), aptxTree); + jalviewAlignport.getAlignment().getSequencesArray(), + jalviewTree); bindAptxNodes.associateLeavesToSequences(); bindNodesToJalviewSequences(aptxApp, jalviewAlignport, @@ -514,7 +522,7 @@ public final class AptxInit } - public static ExternalTreeViewerBindingI bindNodesToJalviewSequences( + protected static ExternalTreeViewerBindingI bindNodesToJalviewSequences( final ExternalTreeFrame aptxApp, final AlignmentViewport jalviewAlignViewport, final Map alignMappedToNodes, @@ -528,7 +536,7 @@ public final class AptxInit } - public static ExternalTreeFrame bindTreeViewFrameToJalview( + protected static ExternalTreeFrame bindTreeViewFrameToJalview( final ExternalTreeFrame aptxApp) { int width = 400; @@ -550,6 +558,28 @@ public final class AptxInit } + private static boolean validateConfig(Configuration aptxConfig) + { + if (aptxConfig == null || aptxConfig.isCouldReadConfigFile() == false) + { + int keepGoing = JvOptionPane.showConfirmDialog(Desktop.desktop, + MessageManager.getString("label.aptx_config_not_found"), + MessageManager.formatMessage("label.couldnt_locate", + new String[] + { "_aptx_jalview_configuration_file" }), + JvOptionPane.YES_NO_CANCEL_OPTION); + + if (keepGoing == JvOptionPane.CANCEL_OPTION + || keepGoing == JvOptionPane.CLOSED_OPTION + || keepGoing == JvOptionPane.NO_OPTION) + { + return false; + } + + } + return true; + } + public static Map getAllAptxFrames() diff --git a/src/jalview/ext/archaeopteryx/AptxTreePanel.java b/src/jalview/ext/archaeopteryx/AptxTreePanel.java index 620d95b..f811c3b 100644 --- a/src/jalview/ext/archaeopteryx/AptxTreePanel.java +++ b/src/jalview/ext/archaeopteryx/AptxTreePanel.java @@ -19,7 +19,7 @@ public class AptxTreePanel implements ExternalTreePanel { private final org.forester.archaeopteryx.TreePanel treeView; - private final Tree tree; + private final ExternalTreeI tree; private String sequenceSetId; @@ -30,6 +30,15 @@ public class AptxTreePanel implements ExternalTreePanel tree = new Tree(treeView.getPhylogeny()); } + protected AptxTreePanel( + org.forester.archaeopteryx.TreePanel aptxTreePanel, + ExternalTreeI aptxTree) + { + treeView = aptxTreePanel; + tree = aptxTree; + + } + @Override public void setTreeFile(File file) { diff --git a/src/jalview/ext/archaeopteryx/Tree.java b/src/jalview/ext/archaeopteryx/Tree.java index e9bfb9b..93091b7 100644 --- a/src/jalview/ext/archaeopteryx/Tree.java +++ b/src/jalview/ext/archaeopteryx/Tree.java @@ -139,7 +139,7 @@ public class Tree implements ExternalTreeI } @Override - public ExternalTreeFrame createInstanceFromTree(String instanceTitle) + public ExternalTreeFrame createTreeViewerFromTree(String instanceTitle) { return new AptxFrame(Archaeopteryx.createApplication(tree, AptxInit.APTX_CONFIG, diff --git a/src/jalview/ext/treeviewer/ExternalTreeI.java b/src/jalview/ext/treeviewer/ExternalTreeI.java index 3f28043..820995f 100644 --- a/src/jalview/ext/treeviewer/ExternalTreeI.java +++ b/src/jalview/ext/treeviewer/ExternalTreeI.java @@ -32,7 +32,6 @@ public interface ExternalTreeI public Iterator iterateInPostOrder(); - public ExternalTreeFrame createInstanceFromTree(String instanceTitle); - + ExternalTreeFrame createTreeViewerFromTree(String instanceTitle); } -- 1.7.10.2