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
{
/*
*/
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;
private JCheckBox shorterSequence;
- private static ComboBoxTooltipRenderer renderer; // BH was not static
+ final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
List<String> tips = new ArrayList<>();
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
paramsPanel.add(includeGappedColumns);
paramsPanel.add(shorterSequence);
- if (VERDANA_11PT == null)
- {
- VERDANA_11PT = new Font("Verdana", 0, 11);
- }
/*
* OK / Cancel buttons
*/
*/
protected JComboBox<String> buildModelOptionsList()
{
- JComboBox<String> scoreModelsCombo = new JComboBox<>();
- if (renderer == null)
- {
- renderer = new ComboBoxTooltipRenderer();
- }
+ final JComboBox<String> scoreModelsCombo = new JComboBox<>();
scoreModelsCombo.setRenderer(renderer);
/*
* 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());
}
*/
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
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();
+
}
/**
}
}
-
/**
* Returns a data bean holding parameters for similarity (or distance) model
* calculation
* @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(
return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
matchOnShortestLength);
-
}
/**
public PCAPanel getPcaPanel()
{
- // only called for FreeUpMemoryTest
return pcaPanel;
}
}