JAL-1953 moved now-generic methods outside of Aptx package
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Mon, 18 Dec 2017 18:30:14 +0000 (18:30 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Mon, 18 Dec 2017 18:31:08 +0000 (18:31 +0000)
src/jalview/ext/archaeopteryx/AptxFrame.java
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/JalviewBinding.java
src/jalview/ext/treeviewer/TreeViewerUtils.java [new file with mode: 0644]
src/jalview/gui/AlignFrame.java

index e050425..6cecd28 100644 (file)
@@ -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));
 
 
       }
index 5752e51..d0ec425 100644 (file)
@@ -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<TreeFrameI, TreeViewerBindingI> 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<SequenceI, TreeNodeI> alignMappedToNodes,
-          final Map<TreeNodeI, SequenceI> 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<TreeFrameI, TreeViewerBindingI> getAllAptxFrames()
-  {
-    return activeAptx;
-  }
-
-
 }
index 6ad0b60..54b9225 100644 (file)
@@ -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 (file)
index 0000000..aa07040
--- /dev/null
@@ -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<TreeFrameI, TreeViewerBindingI> activeViews = new HashMap<>();
+
+  public static TreeViewerBindingI associateNodesWithJalviewSequences(
+          final TreeFrameI treeFrame,
+          final AlignmentViewport jalviewAlignViewport,
+          final Map<SequenceI, TreeNodeI> alignMappedToNodes,
+          final Map<TreeNodeI, SequenceI> 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<TreeFrameI, TreeViewerBindingI> getActiveTreeViews()
+  {
+    return activeViews;
+  }
+
+}
index 579ed09..dbcddf9 100644 (file)
@@ -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<TreePanel> treePanels = new ArrayList<>();
 
-    Map<TreeFrameI, TreeViewerBindingI> aptxFrames = AptxInit
-            .getAllAptxFrames();
+    Map<TreeFrameI, TreeViewerBindingI> aptxFrames = TreeViewerUtils
+            .getActiveTreeViews();
 
     for (Component comp : comps)
     {