From: Ben Soares Date: Mon, 27 May 2019 09:01:12 +0000 (+0100) Subject: JAL-3141 Generified the JvUtils.buildComboWithTooltips to an Object and adjusted... X-Git-Tag: Release_2_11_1_0~53^2~12 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b8683aaaf600239e94d658bdf99012f5e684d9a8;p=jalview.git JAL-3141 Generified the JvUtils.buildComboWithTooltips to an Object and adjusted other code in FeatureTypeSettings. Added one more tooltip. --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 9a52475..f095290 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1381,6 +1381,7 @@ label.default_description = Keep the last three versions of the file label.single_file_description = Keep the last version of the file label.keep_all_versions_description = Keep all previous versions of the file label.rolled_backups_description = Keep the last nine versions of the file from _bak.1 (newest) to _bak.9 (oldest) +label.cancel_changes_description = Cancel changes made to your last saved Custom scheme label.previously_saved_scheme = Previously saved scheme label.no_backup_files = NO BACKUP FILES label.include_backup_files = Include backup files diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index e669fda..bd903b4 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1383,6 +1383,7 @@ label.default_description = Conserve las label.single_file_description = Conserve la última versión del archivo label.keep_all_versions_description = Mantener todas las versiones anteriores del archivo label.rolled_backups_description = Mantenga las últimas nueve versiones del archivo desde _bak.1 (más reciente) a _bak.9 (más antigua) +label.cancel_changes_description = Cancelar los cambios realizados en su último esquema personalizado guardado label.previously_saved_scheme = Esquema previamente guardado label.no_backup_files = NO ARCHIVOS DE RESPALDOS label.include_backup_files = Incluir archivos de respaldos diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index a2194f4..7456e18 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureColourI; +import jalview.bin.Cache; import jalview.datamodel.GraphLine; import jalview.datamodel.features.FeatureAttributes; import jalview.datamodel.features.FeatureAttributes.Datatype; @@ -165,7 +166,7 @@ public class FeatureTypeSettings extends JalviewDialog private JPanel maxColour = new JPanel(); - private JComboBox threshold = new JComboBox<>(); + private JComboBox threshold = new JComboBox<>(); private JSlider slider = new JSlider(); @@ -182,17 +183,17 @@ public class FeatureTypeSettings extends JalviewDialog /* * choice of option for 'colour for no value' */ - private JComboBox noValueCombo; + private JComboBox noValueCombo; /* * choice of what to colour by text (Label or attribute) */ - private JComboBox colourByTextCombo; + private JComboBox colourByTextCombo; /* * choice of what to colour by range (Score or attribute) */ - private JComboBox colourByRangeCombo; + private JComboBox colourByRangeCombo; private JRadioButton andFilters; @@ -1104,7 +1105,7 @@ public class FeatureTypeSettings extends JalviewDialog * @param withRange * @param withText */ - protected JComboBox populateAttributesDropdown( + protected JComboBox populateAttributesDropdown( List attNames, boolean withRange, boolean withText) { List displayAtts = new ArrayList<>(); @@ -1143,9 +1144,11 @@ public class FeatureTypeSettings extends JalviewDialog tooltips.add(desc == null ? "" : desc); } - JComboBox attCombo = JvSwingUtils - .buildComboWithTooltips(displayAtts, tooltips); - + // now convert String List to Object List for buildComboWithTooltips + List displayAttsObjects = new ArrayList<>(displayAtts); + JComboBox attCombo = JvSwingUtils + .buildComboWithTooltips(displayAttsObjects, tooltips); + return attCombo; } @@ -1316,7 +1319,7 @@ public class FeatureTypeSettings extends JalviewDialog * drop-down choice of attribute, with description as a tooltip * if we can obtain it */ - final JComboBox attCombo = populateAttributesDropdown(attNames, + final JComboBox attCombo = populateAttributesDropdown(attNames, true, true); String filterBy = setSelectedAttribute(attCombo, filter); @@ -1444,7 +1447,7 @@ public class FeatureTypeSettings extends JalviewDialog * @param attCombo * @param filter */ - private String setSelectedAttribute(JComboBox attCombo, + private String setSelectedAttribute(JComboBox attCombo, FeatureMatcherI filter) { String item = null; @@ -1661,11 +1664,19 @@ public class FeatureTypeSettings extends JalviewDialog * @param valueField * @param filterIndex */ - protected boolean updateFilter(JComboBox attCombo, + protected boolean updateFilter(JComboBox attCombo, JComboBox condCombo, JTextField valueField, int filterIndex) { - String attName = (String) attCombo.getSelectedItem(); + String attName; + try + { + attName = (String) attCombo.getSelectedItem(); + } catch (Exception e) + { + Cache.log.error("Problem casting Combo box entry to String"); + attName = attCombo.getSelectedItem().toString(); + } Condition cond = (Condition) condCombo.getSelectedItem(); String pattern = valueField.getText().trim(); diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index 8ec40cb..d6090e2 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.io.IntKeyStringValueEntry; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -320,13 +319,13 @@ public final class JvSwingUtils * @param entries * @param tooltips */ - public static JComboBox buildComboWithTooltips( - List entries, List tooltips) + public static JComboBox buildComboWithTooltips( + List entries, List tooltips) { - JComboBox combo = new JComboBox<>(); + JComboBox combo = new JComboBox<>(); final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer(); combo.setRenderer(renderer); - for (String attName : entries) + for (Object attName : entries) { combo.addItem(attName); } @@ -356,49 +355,6 @@ public final class JvSwingUtils } /** - * A helper method to build a drop-down choice of values, with tooltips for the - * entries - * - * @param entries - * @param tooltips - */ - public static JComboBox buildIntKeyStringValueComboWithTooltips( - List entries, List tooltips) - { - JComboBox combo = new JComboBox<>(); - final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer(); - combo.setRenderer(renderer); - for (IntKeyStringValueEntry attName : entries) - { - combo.addItem(attName); - } - renderer.setTooltips(tooltips); - final MouseAdapter mouseListener = new MouseAdapter() - { - @Override - public void mouseEntered(MouseEvent e) - { - int j = combo.getSelectedIndex(); - if (j > -1) - { - combo.setToolTipText(tooltips.get(j)); - } - } - - @Override - public void mouseExited(MouseEvent e) - { - combo.setToolTipText(null); - } - }; - for (Component c : combo.getComponents()) - { - c.addMouseListener(mouseListener); - } - return combo; - } - - /** * Adds a titled border to the component in the default font and position (top * left), optionally witht italic text * diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 6a1a535..f8fbe06 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -303,7 +303,7 @@ public class GPreferences extends JPanel protected JButton revertButton = new JButton(); - protected JComboBox backupfilesPresetsCombo = new JComboBox<>(); + protected JComboBox backupfilesPresetsCombo = new JComboBox<>(); private int backupfilesPresetsComboLastSelected = 0; @@ -1855,12 +1855,12 @@ public class GPreferences extends JPanel presetsComboLabel = new JLabel(title + ":"); presetsPanel.add(presetsComboLabel, gbc); - List entries = Arrays + List entries = Arrays .asList(BackupFilesPresetEntry.backupfilesPresetEntries); List tooltips = Arrays.asList( BackupFilesPresetEntry.backupfilesPresetEntryDescriptions); - backupfilesPresetsCombo = JvSwingUtils - .buildIntKeyStringValueComboWithTooltips(entries, tooltips); + backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries, + tooltips); /* for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++) { @@ -1906,6 +1906,8 @@ public class GPreferences extends JPanel presetsPanel.add(backupfilesPresetsCombo, gbc); revertButton.setText(MessageManager.getString("label.cancel_changes")); + revertButton.setToolTipText( + MessageManager.getString("label.cancel_changes_description")); revertButton.addActionListener(new ActionListener() { @Override @@ -2009,21 +2011,42 @@ public class GPreferences extends JPanel updateBackupFilesExampleLabel(); } - protected int getComboIntStringKey(JComboBox c) + protected int getComboIntStringKey( + JComboBox backupfilesPresetsCombo2) { - IntKeyStringValueEntry e = (IntKeyStringValueEntry) c.getSelectedItem(); + IntKeyStringValueEntry e; + try + { + e = (IntKeyStringValueEntry) backupfilesPresetsCombo2 + .getSelectedItem(); + } catch (Exception ex) + { + Cache.log.error( + "Problem casting Combo entry to IntKeyStringValueEntry."); + e = null; + } return e != null ? e.k : 0; } - protected void setComboIntStringKey(JComboBox c, + protected void setComboIntStringKey( + JComboBox backupfilesPresetsCombo2, int key) { - for (int i = 0; i < c.getItemCount(); i++) + for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++) { - IntKeyStringValueEntry e = c.getItemAt(i); + IntKeyStringValueEntry e; + try + { + e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i); + } catch (Exception ex) + { + Cache.log.error( + "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. "); + continue; + } if (e.k == key) { - c.setSelectedIndex(i); + backupfilesPresetsCombo2.setSelectedIndex(i); break; } }