JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / gui / CalculationChooser.java
index 13506a5..097a5a0 100644 (file)
@@ -62,13 +62,8 @@ import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
 /**
- * A dialog where a user can choose and action Tree or PCA calculation options.
- * 
- * Allows also for dialog-free static methods openPCAPanel(...) and
- * openTreePanel(...) for scripted use.
- * 
+ * A dialog where a user can choose and action Tree or PCA calculation options
  */
-@SuppressWarnings("serial")
 public class CalculationChooser extends JPanel
 {
   /*
@@ -79,7 +74,7 @@ public class CalculationChooser extends JPanel
    */
   private static boolean treeMatchGaps = true;
 
-  private static Font VERDANA_11PT;
+  private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
 
   private static final int MIN_TREE_SELECTION = 3;
 
@@ -107,7 +102,7 @@ public class CalculationChooser extends JPanel
 
   private JCheckBox shorterSequence;
 
-  private static ComboBoxTooltipRenderer renderer; // BH was not static
+  final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
 
   List<String> tips = new ArrayList<>();
 
@@ -117,37 +112,6 @@ public class CalculationChooser extends JPanel
   private PCAPanel pcaPanel;
 
   /**
-   * Open a new Tree panel on the desktop statically. Params are standard (not
-   * set by Groovy). No dialog is opened.
-   * 
-   * @param af
-   * @param treeType
-   * @param modelName
-   * @return null if successful; the string
-   *         "label.you_need_at_least_n_sequences" if number of sequences
-   *         selected is inappropriate
-   */
-  public static Object openTreePanel(AlignFrame af, String treeType,
-          String modelName)
-  {
-    return openTreePanel(af, treeType, modelName, null);
-  }
-
-  /**
-   * public static method for JalviewJS API to open a PCAPanel without
-   * necessarily using a dialog.
-   * 
-   * @param af
-   * @param modelName
-   * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
-   *         if number of sequences selected is inappropriate
-   */
-  public static Object openPcaPanel(AlignFrame af, String modelName)
-  {
-    return openPcaPanel(af, modelName, null);
-  }
-
-  /**
    * Constructor
    * 
    * @param af
@@ -268,10 +232,6 @@ public class CalculationChooser extends JPanel
     paramsPanel.add(includeGappedColumns);
     paramsPanel.add(shorterSequence);
 
-    if (VERDANA_11PT == null)
-    {
-      VERDANA_11PT = new Font("Verdana", 0, 11);
-    }
     /*
      * OK / Cancel buttons
      */
@@ -420,11 +380,7 @@ public class CalculationChooser extends JPanel
    */
   protected JComboBox<String> buildModelOptionsList()
   {
-    JComboBox<String> scoreModelsCombo = new JComboBox<>();
-    if (renderer == null)
-    {
-      renderer = new ComboBoxTooltipRenderer();
-    }
+    final JComboBox<String> scoreModelsCombo = new JComboBox<>();
     scoreModelsCombo.setRenderer(renderer);
 
     /*
@@ -544,8 +500,7 @@ public class CalculationChooser extends JPanel
      * for backwards compatibility with Jalview < 2.8 (JAL-2962)
      */
     if (nucleotide && forPca
-            && Cache.getDefault(Preferences.BLOSUM62_PCA_FOR_NUCLEOTIDE,
-                    false))
+            && Cache.getDefault("BLOSUM62_PCA_FOR_NUCLEOTIDE", false))
     {
       filtered.add(scoreModels.getBlosum62());
     }
@@ -582,63 +537,6 @@ public class CalculationChooser extends JPanel
    */
   protected void openTreePanel(String modelName, SimilarityParamsI params)
   {
-    Object ret = openTreePanel(af,
-            neighbourJoining.isSelected() ? TreeBuilder.NEIGHBOUR_JOINING
-                    : TreeBuilder.AVERAGE_DISTANCE,
-            modelName, params);
-    if (ret instanceof String)
-    {
-      JvOptionPane.showMessageDialog(this, // was opening on Desktop?
-              MessageManager.formatMessage(
-                      (String) ret,
-                      MIN_TREE_SELECTION),
-              MessageManager.getString("label.not_enough_sequences"),
-              JvOptionPane.WARNING_MESSAGE);
-
-    }
-  }
-
-  /**
-   * Open a new PCA panel on the desktop
-   * 
-   * @param modelName
-   * @param params
-   */
-  protected void openPcaPanel(String modelName, SimilarityParamsI params)
-  {
-    Object ret = openPcaPanel(af, modelName, params);
-    if (ret instanceof String)
-    {
-      JvOptionPane.showInternalMessageDialog(this,
-              MessageManager.formatMessage(
-                      (String) ret,
-                      MIN_PCA_SELECTION),
-              MessageManager
-                      .getString("label.sequence_selection_insufficient"),
-              JvOptionPane.WARNING_MESSAGE);
-    }
-    else
-    {
-      // only used for test suite
-      pcaPanel = (PCAPanel) ret;
-    }
-
-  }
-
-  /**
-   * Open a new Tree panel on the desktop statically
-   * 
-   * @param af
-   * @param treeType
-   * @param modelName
-   * @param params
-   * @return null, or the string "label.you_need_at_least_n_sequences" if number
-   *         of sequences selected is inappropriate
-   */
-  public static Object openTreePanel(AlignFrame af, String treeType,
-          String modelName, SimilarityParamsI params)
-  {
-
     /*
      * gui validation shouldn't allow insufficient sequences here, but leave
      * this check in in case this method gets exposed programmatically in future
@@ -647,58 +545,56 @@ public class CalculationChooser extends JPanel
     SequenceGroup sg = viewport.getSelectionGroup();
     if (sg != null && sg.getSize() < MIN_TREE_SELECTION)
     {
-      return "label.you_need_at_least_n_sequences";
-    }
-
-    if (params == null)
-    {
-      params = getSimilarityParameters(false);
+      JvOptionPane.showMessageDialog(Desktop.desktop,
+              MessageManager.formatMessage(
+                      "label.you_need_at_least_n_sequences",
+                      MIN_TREE_SELECTION),
+              MessageManager.getString("label.not_enough_sequences"),
+              JvOptionPane.WARNING_MESSAGE);
+      return;
     }
 
+    String treeType = neighbourJoining.isSelected()
+            ? TreeBuilder.NEIGHBOUR_JOINING
+            : TreeBuilder.AVERAGE_DISTANCE;
     af.newTreePanel(treeType, modelName, params);
-    return null;
   }
 
   /**
-   * public static method for JalviewJS API
+   * Open a new PCA panel on the desktop
    * 
-   * @param af
    * @param modelName
    * @param params
-   * @return the PCAPanel, or null if number of sequences selected is
-   *         inappropriate
    */
-  public static Object openPcaPanel(AlignFrame af, String modelName,
-          SimilarityParamsI params)
+  protected void openPcaPanel(String modelName, SimilarityParamsI params)
   {
-
     AlignViewport viewport = af.getViewport();
 
     /*
      * gui validation shouldn't allow insufficient sequences here, but leave
      * this check in in case this method gets exposed programmatically in future
-     * 
-     * 
      */
     if (((viewport.getSelectionGroup() != null)
             && (viewport.getSelectionGroup().getSize() < MIN_PCA_SELECTION)
             && (viewport.getSelectionGroup().getSize() > 0))
             || (viewport.getAlignment().getHeight() < MIN_PCA_SELECTION))
     {
-      return "label.you_need_at_least_n_sequences";
-    }
-
-    if (params == null)
-    {
-      params = getSimilarityParameters(true);
+      JvOptionPane.showInternalMessageDialog(this,
+              MessageManager.formatMessage(
+                      "label.you_need_at_least_n_sequences",
+                      MIN_PCA_SELECTION),
+              MessageManager
+                      .getString("label.sequence_selection_insufficient"),
+              JvOptionPane.WARNING_MESSAGE);
+      return;
     }
 
     /*
      * construct the panel and kick off its calculation thread
      */
-    PCAPanel pcap = new PCAPanel(af.alignPanel, modelName, params);
-    new Thread(pcap).start();
-    return pcap;
+    pcaPanel = new PCAPanel(af.alignPanel, modelName, params);
+    new Thread(pcaPanel).start();
+
   }
 
   /**
@@ -714,7 +610,6 @@ public class CalculationChooser extends JPanel
     }
   }
 
-
   /**
    * Returns a data bean holding parameters for similarity (or distance) model
    * calculation
@@ -722,8 +617,7 @@ public class CalculationChooser extends JPanel
    * @param doPCA
    * @return
    */
-  public static SimilarityParamsI getSimilarityParameters(
-          boolean doPCA)
+  protected SimilarityParamsI getSimilarityParameters(boolean doPCA)
   {
     // commented out: parameter choices read from gui widgets
     // SimilarityParamsI params = new SimilarityParams(
@@ -744,7 +638,6 @@ public class CalculationChooser extends JPanel
 
     return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
             matchOnShortestLength);
-
   }
 
   /**
@@ -762,7 +655,6 @@ public class CalculationChooser extends JPanel
 
   public PCAPanel getPcaPanel()
   {
-    // only called for FreeUpMemoryTest
     return pcaPanel;
   }
 }