JAL-3141 Generified the JvUtils.buildComboWithTooltips to an Object and adjusted...
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 6a1a535..f8fbe06 100755 (executable)
@@ -303,7 +303,7 @@ public class GPreferences extends JPanel
 
   protected JButton revertButton = new JButton();
 
-  protected JComboBox<IntKeyStringValueEntry> backupfilesPresetsCombo = new JComboBox<>();
+  protected JComboBox<Object> 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<IntKeyStringValueEntry> entries = Arrays
+    List<Object> entries = Arrays
             .asList(BackupFilesPresetEntry.backupfilesPresetEntries);
     List<String> 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<IntKeyStringValueEntry> c)
+  protected int getComboIntStringKey(
+          JComboBox<Object> 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<IntKeyStringValueEntry> c,
+  protected void setComboIntStringKey(
+          JComboBox<Object> 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;
       }
     }