label.principal_component_analysis_must_take_least_four_input_sequences = Principal component analysis must take\nat least 4 input sequences.
label.sequence_selection_insufficient = Sequence selection insufficient
label.you_need_more_two_sequences_selected_build_tree = You need to have more than two sequences selected to build a tree!
+label.you_need_more_than_n_sequences = You need to have more than {0} sequences
label.not_enough_sequences = Not enough sequences
label.selected_region_to_tree_may_only_contain_residues_or_gaps = The selected region to create a tree may\nonly contain residues or gaps.\nTry using the Pad function in the edit menu,\nor one of the multiple sequence alignment web services.
label.sequences_selection_not_aligned = Sequences in selection are not aligned
calcTypes.add(pca);
calcTypes.add(neighbourJoining);
calcTypes.add(averageDistance);
+
+ ActionListener calcChanged = new ActionListener()
{
@Override
- public void itemStateChanged(ItemEvent e)
+ public void actionPerformed(ActionEvent e)
{
- neighbourJoining.setEnabled(tree.isSelected());
- averageDistance.setEnabled(tree.isSelected());
+ validateCalcTypes();
}
};
-
+ pca.addActionListener(calcChanged);
+ neighbourJoining.addActionListener(calcChanged);
+ averageDistance.addActionListener(calcChanged);
/*
* score models drop-down - with added tooltips!
*/
}
/**
+ * enable calculations applicable for the current alignment or selection.
+ */
+ protected void validateCalcTypes()
+ {
+ int size = af.getViewport().getAlignment().getHeight();
+ if (af.getViewport().getSelectionGroup() != null)
+ {
+ size = af.getViewport().getSelectionGroup().getSize();
+ }
+ if (!(checkEnabled(pca, size, 4)
+ | checkEnabled(neighbourJoining, size, 3) | checkEnabled(
+ averageDistance, size, 3)))
+ {
+ ok.setToolTipText(null);
+ ok.setEnabled(true);
+ }
+ else
+ {
+ ok.setEnabled(false);
+ }
+ }
+
+ /**
+ * Check the input and disable a calculation's radio button if necessary. A
+ * tooltip is shown for disabled calculations.
+ *
+ * @param calc
+ * - radio button for the calculation being validated
+ * @param size
+ * - size of input to calculation
+ * @param minsize
+ * - minimum size for calculation
+ * @return true if size < minsize *and* calc.isSelected
+ */
+ private boolean checkEnabled(JRadioButton calc, int size, int minsize)
+ {
+ String ttip = MessageManager.formatMessage(
+ "label.you_need_more_than_n_sequences", minsize);
+
+ calc.setEnabled(size >= minsize);
+ if (!calc.isEnabled())
+ {
+ calc.setToolTipText(ttip);
+ }
+ else
+ {
+ calc.setToolTipText(null);
+ }
+ if (calc.isSelected())
+ {
+ modelNames.setEnabled(calc.isEnabled());
+ if (!calc.isEnabled())
+ {
+ ok.setEnabled(false);
+ ok.setToolTipText(ttip);
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
* A rather elaborate helper method (blame Swing, not me) that builds a
* drop-down list of score models (by name) with descriptions as tooltips.
* There is also a tooltip shown for the currently selected item when hovering