From f7c1fd8a0f220e1e896414b1aa905bd30138c26a Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Mon, 18 Dec 2017 18:30:14 +0000 Subject: [PATCH] JAL-1953 moved now-generic methods outside of Aptx package --- src/jalview/ext/archaeopteryx/AptxFrame.java | 3 +- src/jalview/ext/archaeopteryx/AptxInit.java | 62 +++------------------ src/jalview/ext/archaeopteryx/JalviewBinding.java | 5 +- src/jalview/ext/treeviewer/TreeViewerUtils.java | 57 +++++++++++++++++++ src/jalview/gui/AlignFrame.java | 5 +- 5 files changed, 72 insertions(+), 60 deletions(-) create mode 100644 src/jalview/ext/treeviewer/TreeViewerUtils.java diff --git a/src/jalview/ext/archaeopteryx/AptxFrame.java b/src/jalview/ext/archaeopteryx/AptxFrame.java index e050425..6cecd28 100644 --- a/src/jalview/ext/archaeopteryx/AptxFrame.java +++ b/src/jalview/ext/archaeopteryx/AptxFrame.java @@ -5,6 +5,7 @@ import jalview.ext.treeviewer.TreeControlsI; import jalview.ext.treeviewer.TreeFrameI; import jalview.ext.treeviewer.TreeI; import jalview.ext.treeviewer.TreePanelI; +import jalview.ext.treeviewer.TreeViewerUtils; import jalview.gui.Desktop; import jalview.gui.EPSOptions; import jalview.io.JalviewFileChooser; @@ -152,7 +153,7 @@ public class AptxFrame implements TreeFrameI sortByTree.setFont(menu.getFont()); refreshJalview - .addActionListener(AptxInit.getAllAptxFrames().get(this)); + .addActionListener(TreeViewerUtils.getActiveTreeViews().get(this)); } diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 5752e51..d0ec425 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -1,28 +1,23 @@ package jalview.ext.archaeopteryx; import jalview.analysis.TreeBuilder; -import jalview.datamodel.SequenceI; import jalview.ext.forester.UtilityMethods; import jalview.ext.treeviewer.LoadedTreeAssociationI; +import jalview.ext.treeviewer.LoadedTreeSequenceAssociation; import jalview.ext.treeviewer.TreeBuilderI; import jalview.ext.treeviewer.TreeFrameI; import jalview.ext.treeviewer.TreeI; -import jalview.ext.treeviewer.TreeNodeI; -import jalview.ext.treeviewer.TreeViewerBindingI; -import jalview.ext.treeviewer.LoadedTreeSequenceAssociation; +import jalview.ext.treeviewer.TreeViewerUtils; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; -import java.awt.Dimension; import java.io.File; 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; import org.forester.archaeopteryx.Configuration; @@ -74,7 +69,7 @@ public final class AptxInit private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG .getTaxonomyExtraction(); - private static Map activeAptx = new HashMap<>(); + @@ -495,10 +490,10 @@ public final class AptxInit jalviewTree); bindAptxNodes.associateLeavesToSequences(); - bindNodesToJalviewSequences(aptxApp, jalviewAlignport, + TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport, bindAptxNodes.getAlignmentWithNodes(), bindAptxNodes.getNodesWithAlignment()); - bindTreeViewFrameToJalview(aptxApp); + TreeViewerUtils.addTreeViewFrameToJalview(aptxApp); // adaptAptxGui(aptxApp); //moved to AptxFrame return aptxApp; @@ -518,52 +513,16 @@ public final class AptxInit jalviewTree); bindAptxNodes.associateLeavesToSequences(); - bindNodesToJalviewSequences(aptxApp, jalviewAlignport, + TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport, bindAptxNodes.getAlignmentWithNodes(), bindAptxNodes.getNodesWithAlignment()); - bindTreeViewFrameToJalview(aptxApp); + TreeViewerUtils.addTreeViewFrameToJalview(aptxApp); // adaptAptxGui(aptxApp); //moved to AptxFrame return aptxApp; } - protected static TreeViewerBindingI bindNodesToJalviewSequences( - final TreeFrameI aptxApp, - final AlignmentViewport jalviewAlignViewport, - final Map alignMappedToNodes, - final Map nodesMappedToAlign) - { - TreeViewerBindingI treeBinding = new JalviewBinding(aptxApp, - jalviewAlignViewport, - alignMappedToNodes, nodesMappedToAlign); - activeAptx.put(aptxApp, treeBinding); - return treeBinding; - } - - - protected static TreeFrameI bindTreeViewFrameToJalview( - final TreeFrameI aptxApp) - { - int width = 400; - int height = 550; - aptxApp.setMinimumSize(new Dimension(width, height)); - // aptxApp.setFont(Desktop.instance.getFont()); - // aptxApp.getMainPanel().setFont(Desktop.instance.getFont()); - String frameTitle = MessageManager.getString("label.aptx_title"); - File treeFile = aptxApp.getTreePanel().getTreeFile(); - if (treeFile != null) - { - frameTitle += MessageManager.formatMessage("label.aptx_title_append", - new String[] - { treeFile.getAbsolutePath() }); - } - aptxApp.addFrameToJalview(frameTitle, true, width, height, true, - true); - return aptxApp; - - } - private static boolean validateConfig(Configuration aptxConfig) { if (aptxConfig == null || aptxConfig.isCouldReadConfigFile() == false) @@ -587,11 +546,4 @@ 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 6ad0b60..54b9225 100644 --- a/src/jalview/ext/archaeopteryx/JalviewBinding.java +++ b/src/jalview/ext/archaeopteryx/JalviewBinding.java @@ -14,6 +14,7 @@ import jalview.ext.treeviewer.TreeI; import jalview.ext.treeviewer.TreeNodeI; import jalview.ext.treeviewer.TreePanelI; import jalview.ext.treeviewer.TreeViewerBindingI; +import jalview.ext.treeviewer.TreeViewerUtils; import jalview.ext.treeviewer.LoadedTreeSequenceAssociation; import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; @@ -129,7 +130,7 @@ public final class JalviewBinding @Override public void internalFrameClosed(InternalFrameEvent e) { - AptxInit.getAllAptxFrames().remove(aptxFrame); + TreeViewerUtils.getActiveTreeViews().remove(aptxFrame); ssm.removeSelectionListener(JalviewBinding.this); } @@ -182,7 +183,7 @@ public final class JalviewBinding bindAptxNodes.associateLeavesToSequences(); sequencesBoundToNodes = bindAptxNodes.getAlignmentWithNodes(); nodesBoundToSequences = bindAptxNodes.getNodesWithAlignment(); - AptxInit.bindNodesToJalviewSequences(aptxFrame, parentAvport, + TreeViewerUtils.associateNodesWithJalviewSequences(aptxFrame, parentAvport, sequencesBoundToNodes, nodesBoundToSequences); diff --git a/src/jalview/ext/treeviewer/TreeViewerUtils.java b/src/jalview/ext/treeviewer/TreeViewerUtils.java new file mode 100644 index 0000000..aa07040 --- /dev/null +++ b/src/jalview/ext/treeviewer/TreeViewerUtils.java @@ -0,0 +1,57 @@ +package jalview.ext.treeviewer; + +import jalview.datamodel.SequenceI; +import jalview.ext.archaeopteryx.JalviewBinding; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; + +import java.awt.Dimension; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +public class TreeViewerUtils +{ + private static Map activeViews = new HashMap<>(); + + public static TreeViewerBindingI associateNodesWithJalviewSequences( + final TreeFrameI treeFrame, + final AlignmentViewport jalviewAlignViewport, + final Map alignMappedToNodes, + final Map nodesMappedToAlign) + { + TreeViewerBindingI treeBinding = new JalviewBinding(treeFrame, + jalviewAlignViewport, + alignMappedToNodes, nodesMappedToAlign); + activeViews.put(treeFrame, treeBinding); + return treeBinding; + } + + public static TreeFrameI addTreeViewFrameToJalview( + final TreeFrameI treeFrame) + { + int width = 400; + int height = 550; + treeFrame.setMinimumSize(new Dimension(width, height)); + // aptxApp.setFont(Desktop.instance.getFont()); + // aptxApp.getMainPanel().setFont(Desktop.instance.getFont()); + String frameTitle = MessageManager.getString("label.aptx_title"); + File treeFile = treeFrame.getTreePanel().getTreeFile(); + if (treeFile != null) + { + frameTitle += MessageManager.formatMessage("label.aptx_title_append", + new String[] + { treeFile.getAbsolutePath() }); + } + treeFrame.addFrameToJalview(frameTitle, true, width, height, true, + true); + return treeFrame; + + } + + public static Map getActiveTreeViews() + { + return activeViews; + } + +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 579ed09..dbcddf9 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -66,6 +66,7 @@ import jalview.ext.forester.io.SupportedTreeFileFilter; import jalview.ext.forester.io.TreeParser; import jalview.ext.treeviewer.TreeFrameI; import jalview.ext.treeviewer.TreeViewerBindingI; +import jalview.ext.treeviewer.TreeViewerUtils; import jalview.gui.ColourMenuHelper.ColourChangeListener; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AlignmentProperties; @@ -3765,8 +3766,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .get(viewport.getSequenceSetId()); List treePanels = new ArrayList<>(); - Map aptxFrames = AptxInit - .getAllAptxFrames(); + Map aptxFrames = TreeViewerUtils + .getActiveTreeViews(); for (Component comp : comps) { -- 1.7.10.2