JAL-2423 refactored method to build panel title for tree either
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 17 Feb 2017 15:14:19 +0000 (15:14 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 17 Feb 2017 15:14:19 +0000 (15:14 +0000)
calculated or read from file

src/jalview/analysis/NJTree.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/TreePanel.java

index a7ead1d..542f15e 100644 (file)
@@ -44,10 +44,15 @@ import java.util.Vector;
  */
 public class NJTree
 {
+  /*
+   * 'methods'
+   */
   public static final String AVERAGE_DISTANCE = "AV";
 
   public static final String NEIGHBOUR_JOINING = "NJ";
 
+  public static final String FROM_FILE = "FromFile";
+
   Vector<Cluster> cluster;
 
   SequenceI[] sequence;
index 0da8381..1162c53 100644 (file)
@@ -24,6 +24,7 @@ import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.CrossRef;
 import jalview.analysis.Dna;
+import jalview.analysis.NJTree;
 import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignExportSettingI;
@@ -4025,7 +4026,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
       if (nf.getTree() != null)
       {
-        tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
+        tp = new TreePanel(alignPanel, NJTree.FROM_FILE, title, nf, input);
 
         tp.setSize(w, h);
 
@@ -5639,13 +5640,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   public void newTreePanel(String treeType, ScoreModelI sm)
   {
-    String treecalcnm = MessageManager.getString("label.tree_calc_"
-            + treeType.toLowerCase());
-    String smn = MessageManager.getStringOrReturn("label.score_model_",
-            sm.getName());
-    final String ttl = MessageManager.formatMessage("label.treecalc_title",
-            treecalcnm, smn);
-    newTreePanel(treeType, sm.getName(), ttl);
+    String scoreModelName = sm.getName();
+    final String ttl = TreePanel.getPanelTitle(treeType, scoreModelName);
+    newTreePanel(treeType, scoreModelName, ttl);
   }
 }
 
index 477c28d..7df1f71 100755 (executable)
@@ -107,27 +107,6 @@ public class TreePanel extends GTreePanel
     // showDistances(true);
   }
 
-  /**
-   * Creates a new TreePanel object.
-   * 
-   * @param av
-   *          DOCUMENT ME!
-   * @param seqVector
-   *          DOCUMENT ME!
-   * @param newtree
-   *          DOCUMENT ME!
-   * @param type
-   *          DOCUMENT ME!
-   * @param pwtype
-   *          DOCUMENT ME!
-   */
-  public TreePanel(AlignmentPanel ap, String type, String pwtype,
-          NewickFile newtree)
-  {
-    super();
-    initTreePanel(ap, type, pwtype, newtree, null);
-  }
-
   public TreePanel(AlignmentPanel av, String type, String pwtype,
           NewickFile newtree, AlignmentView inputData)
   {
@@ -400,26 +379,14 @@ public class TreePanel extends GTreePanel
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
 
-    StringBuffer buffer = new StringBuffer();
-
-    if (type.equals(NJTree.AVERAGE_DISTANCE))
-    {
-      buffer.append("Average distance tree using ");
-    }
-    else
-    {
-      buffer.append("Neighbour joining tree using ");
-    }
-
-    ScoreModelI sm = ScoreModels.getInstance().forName(pwtype);
-    buffer.append(sm.getName());
+    String newTitle = getPanelTitle(type, pwtype);
 
     NewickFile fout = new NewickFile(tree.getTopNode());
     try
     {
       cap.setText(fout.print(tree.isHasBootstrap(), tree.isHasDistances(),
               tree.isHasRootDistance()));
-      Desktop.addInternalFrame(cap, buffer.toString(), 500, 100);
+      Desktop.addInternalFrame(cap, newTitle, 500, 100);
     } catch (OutOfMemoryError oom)
     {
       new OOMWarning("generating newick tree file", oom);
@@ -892,4 +859,43 @@ public class TreePanel extends GTreePanel
       }
     });
   }
+
+  /**
+   * Formats a localised title for the tree panel, like
+   * <p>
+   * Neighbour Joining Using BLOSUM62
+   * <p>
+   * For a tree loaded from file, just uses the file name
+   * 
+   * @param treeType
+   *          NJ or AV or FromFile
+   * @param modelOrFileName
+   * @return
+   */
+  public static String getPanelTitle(String treeType, String modelOrFileName)
+  {
+    if (NJTree.FROM_FILE.equals(treeType))
+    {
+      return modelOrFileName;
+    }
+
+    /*
+     * i18n description of Neighbour Joining or Average Distance method
+     */
+    String treecalcnm = MessageManager.getString("label.tree_calc_"
+            + treeType.toLowerCase());
+
+    /*
+     * i18n description (if any) of score model used
+     */
+    String smn = MessageManager.getStringOrReturn("label.score_model_",
+            modelOrFileName);
+
+    /*
+     * put them together as <method> Using <model>
+     */
+    final String ttl = MessageManager.formatMessage("label.treecalc_title",
+            treecalcnm, smn);
+    return ttl;
+  }
 }