JAL-1632 i18n for warning messages
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 8 May 2017 13:54:56 +0000 (14:54 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 8 May 2017 13:54:56 +0000 (14:54 +0100)
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/gui/AlignFrame.java
src/jalview/gui/CalculationChooser.java

index e63752d..88bb376 100644 (file)
@@ -381,10 +381,8 @@ label.remove_from_default_list = Remove from default list?
 label.remove_user_defined_colour = Remove user defined colour
 label.you_must_select_least_two_sequences = You must select at least 2 sequences.
 label.invalid_selection = Invalid Selection
-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.you_need_at_least_n_sequences = You need to select at least {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
index 6ddbb44..f55ce6b 100644 (file)
@@ -349,9 +349,8 @@ label.remove_from_default_list = eliminar de la lista de defectuosos?
 label.remove_user_defined_colour = Eliminar el color definido por el usuario
 label.you_must_select_least_two_sequences = Debes seleccionar al menos 2 secuencias.
 label.invalid_selection = Selección inválida
-label.principal_component_analysis_must_take_least_four_input_sequences = El an\u00E1lisis de la componente principal debe tomar\nal menos 4 secuencias de entrada.
 label.sequence_selection_insufficient = Selección de secuencias insuficiente
-label.you_need_more_two_sequences_selected_build_tree = necesitas seleccionar más de dos secuencias para construir un árbol!
+label.you_need_at_least_n_sequences = Necesitas seleccionar al menos {0} secuencias
 label.not_enough_sequences = No suficientes secuencias
 label.selected_region_to_tree_may_only_contain_residues_or_gaps = La regi\u00F3n seleccionada para construir un \u00E1rbol puede\ncontener s\u00F3lo residuos o espacios.\nPrueba usando la funci\u00F3n Pad en el men\u00FA de edici\u00F3n,\n o uno de los m\u00FAltiples servicios web de alineamiento de secuencias.
 label.sequences_selection_not_aligned = Las secuencias seleccionadas no están alineadas
index 8eb09ab..016ee85 100644 (file)
@@ -3587,19 +3587,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (viewport.getSelectionGroup() != null
             && viewport.getSelectionGroup().getSize() > 0)
     {
-      if (viewport.getSelectionGroup().getSize() < 3)
-      {
-        JvOptionPane
-                .showMessageDialog(
-                        Desktop.desktop,
-                        MessageManager
-                                .getString("label.you_need_more_two_sequences_selected_build_tree"),
-                        MessageManager
-                                .getString("label.not_enough_sequences"),
-                        JvOptionPane.WARNING_MESSAGE);
-        return;
-      }
-
       SequenceGroup sg = viewport.getSelectionGroup();
 
       /* Decide if the selection is a column region */
index 05f1fba..6f5510c 100644 (file)
@@ -74,6 +74,10 @@ public class CalculationChooser extends JPanel
 
   private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
 
+  private static final int MIN_TREE_SELECTION = 3;
+
+  private static final int MIN_PCA_SELECTION = 4;
+
   AlignFrame af;
 
   JRadioButton pca;
@@ -84,7 +88,7 @@ public class CalculationChooser extends JPanel
 
   JComboBox<String> modelNames;
 
-  JButton ok;
+  JButton calculate;
 
   private JInternalFrame frame;
 
@@ -96,6 +100,10 @@ public class CalculationChooser extends JPanel
 
   private JCheckBox shorterSequence;
 
+  final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
+
+  List<String> tips = new ArrayList<String>();
+
   /**
    * Constructor
    * 
@@ -143,6 +151,7 @@ public class CalculationChooser extends JPanel
     pca.setOpaque(false);
     neighbourJoining = new JRadioButton(
             MessageManager.getString("label.tree_calc_nj"));
+    neighbourJoining.setSelected(true);
     averageDistance = new JRadioButton(
             MessageManager.getString("label.tree_calc_av"));
     neighbourJoining.setOpaque(false);
@@ -167,7 +176,6 @@ public class CalculationChooser extends JPanel
     pcaBorderless.add(pca, FlowLayout.LEFT);
     calcChoicePanel.add(pcaBorderless, FlowLayout.LEFT);
 
-
     treePanel.add(neighbourJoining);
     treePanel.add(averageDistance);
 
@@ -189,6 +197,7 @@ public class CalculationChooser extends JPanel
     pca.addActionListener(calcChanged);
     neighbourJoining.addActionListener(calcChanged);
     averageDistance.addActionListener(calcChanged);
+
     /*
      * score models drop-down - with added tooltips!
      */
@@ -216,30 +225,30 @@ public class CalculationChooser extends JPanel
     /*
      * OK / Cancel buttons
      */
-    ok = new JButton(MessageManager.getString("action.calculate"));
-    ok.setFont(VERDANA_11PT);
-    ok.addActionListener(new java.awt.event.ActionListener()
+    calculate = new JButton(MessageManager.getString("action.calculate"));
+    calculate.setFont(VERDANA_11PT);
+    calculate.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        ok_actionPerformed();
+        calculate_actionPerformed();
       }
     });
-    JButton cancel = new JButton(MessageManager.getString("action.close"));
-    cancel.setFont(VERDANA_11PT);
-    cancel.addActionListener(new java.awt.event.ActionListener()
+    JButton close = new JButton(MessageManager.getString("action.close"));
+    close.setFont(VERDANA_11PT);
+    close.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        cancel_actionPerformed(e);
+        close_actionPerformed();
       }
     });
     JPanel actionPanel = new JPanel();
     actionPanel.setOpaque(false);
-    actionPanel.add(ok);
-    actionPanel.add(cancel);
+    actionPanel.add(calculate);
+    actionPanel.add(close);
 
     boolean includeParams = false;
     this.add(calcChoicePanel, BorderLayout.CENTER);
@@ -290,18 +299,27 @@ public class CalculationChooser extends JPanel
     {
       size = af.getViewport().getSelectionGroup().getSize();
     }
-    if (!(checkEnabled(pca, size, 4)
-            | checkEnabled(neighbourJoining, size, 3) | checkEnabled(
-              averageDistance, size, 3)))
+
+    /*
+     * disable calc options for which there is insufficient input data
+     * return value of true means enabled and selected
+     */
+    boolean checkPca = checkEnabled(pca, size, MIN_PCA_SELECTION);
+    boolean checkNeighbourJoining = checkEnabled(neighbourJoining, size,
+            MIN_TREE_SELECTION);
+    boolean checkAverageDistance = checkEnabled(averageDistance, size,
+            MIN_TREE_SELECTION);
+
+    if (checkPca || checkNeighbourJoining || checkAverageDistance)
     {
-      ok.setToolTipText(null);
-      ok.setEnabled(true);
+      calculate.setToolTipText(null);
+      calculate.setEnabled(true);
     }
     else
     {
-      ok.setEnabled(false);
+      calculate.setEnabled(false);
     }
-    updateScoreModels(comboBox, tips);
+    updateScoreModels(modelNames, tips);
   }
 
   /**
@@ -314,12 +332,12 @@ public class CalculationChooser extends JPanel
    *          - size of input to calculation
    * @param minsize
    *          - minimum size for calculation
-   * @return true if size < minsize *and* calc.isSelected
+   * @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);
+            "label.you_need_at_least_n_sequences", minsize);
 
     calc.setEnabled(size >= minsize);
     if (!calc.isEnabled())
@@ -333,22 +351,18 @@ public class CalculationChooser extends JPanel
     if (calc.isSelected())
     {
       modelNames.setEnabled(calc.isEnabled());
-      if (!calc.isEnabled())
+      if (calc.isEnabled())
       {
-        ok.setEnabled(false);
-        ok.setToolTipText(ttip);
         return true;
       }
+      else
+      {
+        calculate.setToolTipText(ttip);
+      }
     }
     return false;
   }
 
-  final JComboBox<String> comboBox = new JComboBox<String>();
-
-  final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
-
-  List<String> tips = new ArrayList<String>();
-
   /**
    * A rather elaborate helper method (blame Swing, not me) that builds a
    * drop-down list of score models (by name) with descriptions as tooltips.
@@ -357,7 +371,8 @@ public class CalculationChooser extends JPanel
    */
   protected JComboBox<String> buildModelOptionsList()
   {
-    comboBox.setRenderer(renderer);
+    final JComboBox<String> scoreModelsCombo = new JComboBox<String>();
+    scoreModelsCombo.setRenderer(renderer);
 
     /*
      * show tooltip on mouse over the combobox
@@ -369,35 +384,36 @@ public class CalculationChooser extends JPanel
       @Override
       public void mouseEntered(MouseEvent e)
       {
-        comboBox.setToolTipText(tips.get(comboBox.getSelectedIndex()));
+        scoreModelsCombo.setToolTipText(tips.get(scoreModelsCombo.getSelectedIndex()));
       }
 
       @Override
       public void mouseExited(MouseEvent e)
       {
-        comboBox.setToolTipText(null);
+        scoreModelsCombo.setToolTipText(null);
       }
     };
-    for (Component c : comboBox.getComponents())
+    for (Component c : scoreModelsCombo.getComponents())
     {
       c.addMouseListener(mouseListener);
     }
 
-    updateScoreModels(comboBox, tips);
+    updateScoreModels(scoreModelsCombo, tips);
 
     /*
      * set the list of tooltips on the combobox's renderer
      */
     renderer.setTooltips(tips);
 
-    return comboBox;
+    return scoreModelsCombo;
   }
 
-  private void updateScoreModels(JComboBox comboBox, List<String> tips)
+  private void updateScoreModels(JComboBox<String> comboBox,
+          List<String> toolTips)
   {
     Object curSel = comboBox.getSelectedItem();
-    tips.clear();
-    DefaultComboBoxModel model = new DefaultComboBoxModel();
+    toolTips.clear();
+    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
 
     /*
      * now we can actually add entries to the combobox,
@@ -427,7 +443,7 @@ public class CalculationChooser extends JPanel
           tooltip = MessageManager.getStringOrReturn("label.score_model_",
                   sm.getName());
         }
-        tips.add(tooltip);
+        toolTips.add(tooltip);
       }
     }
     if (selectedIsPresent)
@@ -441,7 +457,7 @@ public class CalculationChooser extends JPanel
   /**
    * Open and calculate the selected tree or PCA on 'OK'
    */
-  protected void ok_actionPerformed()
+  protected void calculate_actionPerformed()
   {
     boolean doPCA = pca.isSelected();
     String modelName = modelNames.getSelectedItem().toString();
@@ -467,6 +483,25 @@ public class CalculationChooser extends JPanel
    */
   protected void openTreePanel(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
+     */
+    AlignViewport viewport = af.getViewport();
+    if (viewport.getSelectionGroup().getSize() < MIN_TREE_SELECTION)
+    {
+      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);
@@ -481,19 +516,21 @@ public class CalculationChooser extends JPanel
   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() < 4) && (viewport
+            && (viewport.getSelectionGroup().getSize() < MIN_PCA_SELECTION) && (viewport
             .getSelectionGroup().getSize() > 0))
-            || (viewport.getAlignment().getHeight() < 4))
+            || (viewport.getAlignment().getHeight() < MIN_PCA_SELECTION))
     {
-      JvOptionPane
-              .showInternalMessageDialog(
-                      this,
-                      MessageManager
-                              .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
-                      MessageManager
-                              .getString("label.sequence_selection_insufficient"),
-                      JvOptionPane.WARNING_MESSAGE);
+      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;
     }
     new PCAPanel(af.alignPanel, modelName, params);
@@ -542,11 +579,9 @@ public class CalculationChooser extends JPanel
   }
 
   /**
-   * Closes dialog on cancel
-   * 
-   * @param e
+   * Closes dialog on Close button press
    */
-  protected void cancel_actionPerformed(ActionEvent e)
+  protected void close_actionPerformed()
   {
     try
     {