JAL-2499 JAL-2403 push 'configure for view' inside ScoreModels, defer
[jalview.git] / src / jalview / gui / TreePanel.java
index d173319..f2f0bf7 100755 (executable)
@@ -25,9 +25,9 @@ import jalview.analysis.AverageDistanceTree;
 import jalview.analysis.NJTree;
 import jalview.analysis.TreeBuilder;
 import jalview.analysis.TreeModel;
+import jalview.analysis.scoremodels.ScoreModels;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
-import jalview.api.analysis.ViewBasedAnalysisI;
 import jalview.bin.Cache;
 import jalview.commands.CommandI;
 import jalview.commands.OrderCommand;
@@ -76,7 +76,7 @@ public class TreePanel extends GTreePanel
 {
   String treeType;
 
-  ScoreModelI scoreModel; // if tree computed
+  String scoreModelName; // if tree computed
 
   String treeTitle; // if tree loaded
 
@@ -93,15 +93,15 @@ public class TreePanel extends GTreePanel
    * 
    * @param ap
    * @param type
-   * @param sm
+   * @param modelName
    * @param options
    */
-  public TreePanel(AlignmentPanel ap, String type, ScoreModelI sm,
+  public TreePanel(AlignmentPanel ap, String type, String modelName,
           SimilarityParamsI options)
   {
     super();
     this.similarityParams = options;
-    initTreePanel(ap, type, sm, null, null);
+    initTreePanel(ap, type, modelName, null, null);
 
     // We know this tree has distances. JBPNote TODO: prolly should add this as
     // a userdefined default
@@ -126,13 +126,13 @@ public class TreePanel extends GTreePanel
     return treeCanvas.av;
   }
 
-  void initTreePanel(AlignmentPanel ap, String type, ScoreModelI sm,
+  void initTreePanel(AlignmentPanel ap, String type, String modelName,
           NewickFile newTree, AlignmentView inputData)
   {
 
     av = ap.av;
     this.treeType = type;
-    this.scoreModel = sm;
+    this.scoreModelName = modelName;
 
     treeCanvas = new TreeCanvas(this, ap, scrollPane);
     scrollPane.setViewportView(treeCanvas);
@@ -841,7 +841,7 @@ public class TreePanel extends GTreePanel
     /*
      * short score model name (long description can be too long)
      */
-    String smn = scoreModel.getName();
+    String smn = scoreModelName;
 
     /*
      * put them together as <method> Using <model>
@@ -852,26 +852,14 @@ public class TreePanel extends GTreePanel
   }
 
   /**
-   * If the score model is one that requires to get state data from the current
-   * view, create and configure a new instance of it
+   * Instantiate an instance of the score model, configured for the current view
+   * if applicable
    * 
    * @return
    */
   protected ScoreModelI configureScoreModel()
   {
-    if (scoreModel instanceof ViewBasedAnalysisI)
-    {
-      try
-      {
-        scoreModel = scoreModel.getClass().newInstance();
-        ((ViewBasedAnalysisI) scoreModel)
-                .configureFromAlignmentView(treeCanvas.ap);
-      } catch (Exception q)
-      {
-        Cache.log.error("Couldn't create a scoremodel instance for "
-                + scoreModel.getName());
-      }
-    }
-    return scoreModel;
+    return ScoreModels.getInstance().getScoreModel(scoreModelName,
+            treeCanvas.ap);
   }
 }