JAL-2422 more responsive Chimera/X path prompts in Preferences
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 5685e84..58045cb 100755 (executable)
@@ -53,6 +53,8 @@ import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.swing.AbstractCellEditor;
 import javax.swing.BorderFactory;
@@ -177,6 +179,8 @@ public class GPreferences extends JPanel
 
   protected JComboBox<String> structViewer = new JComboBox<>();
 
+  protected JLabel chimeraPathLabel;
+
   protected JTextField chimeraPath = new JTextField();
 
   protected ButtonGroup mappingMethod = new ButtonGroup();
@@ -301,7 +305,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;
 
@@ -627,6 +631,8 @@ public class GPreferences extends JPanel
                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
                     new Insets(0, 2, 5, 5), 70, 1));
 
+    versioncheck.setVisible(false);
+
     // Add padding so the panel doesn't look ridiculous
     JPanel spacePanel = new JPanel();
     connectTab.add(spacePanel,
@@ -1191,7 +1197,7 @@ public class GPreferences extends JPanel
     structureTab.setBorder(new TitledBorder(
             MessageManager.getString("label.structure_options")));
     structureTab.setLayout(null);
-    final int width = 400;
+    final int width = 420;
     final int height = 22;
     final int lineSpacing = 25;
     int ypos = 15;
@@ -1239,13 +1245,14 @@ public class GPreferences extends JPanel
     viewerLabel.setFont(LABEL_FONT);
     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
-    viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
+    viewerLabel.setBounds(new Rectangle(10, ypos, 220, height));
     structureTab.add(viewerLabel);
 
     structViewer.setFont(LABEL_FONT);
-    structViewer.setBounds(new Rectangle(160, ypos, 120, height));
+    structViewer.setBounds(new Rectangle(190, ypos, 120, height));
     structViewer.addItem(ViewerType.JMOL.name());
     structViewer.addItem(ViewerType.CHIMERA.name());
+    structViewer.addItem(ViewerType.CHIMERAX.name());
     structViewer.addActionListener(new ActionListener()
     {
       @Override
@@ -1258,25 +1265,28 @@ public class GPreferences extends JPanel
     structureTab.add(structViewer);
 
     ypos += lineSpacing;
-    JLabel pathLabel = new JLabel();
-    pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
-    pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
-    pathLabel.setText(MessageManager.getString("label.chimera_path"));
-    pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
-    structureTab.add(pathLabel);
+    chimeraPathLabel = new JLabel();
+    chimeraPathLabel.setFont(LABEL_FONT);// new Font("SansSerif", 0, 11));
+    chimeraPathLabel.setHorizontalAlignment(SwingConstants.LEFT);
+    chimeraPathLabel.setText(MessageManager
+            .formatMessage("label.chimera_path", "Chimera(X)"));
+    chimeraPathLabel.setBounds(new Rectangle(10, ypos, 170, height));
+    chimeraPathLabel.setEnabled(false);
+    structureTab.add(chimeraPathLabel);
 
     chimeraPath.setFont(LABEL_FONT);
     chimeraPath.setText("");
+    chimeraPath.setEnabled(false);
     final String tooltip = JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.chimera_path_tip"));
     chimeraPath.setToolTipText(tooltip);
-    chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
+    chimeraPath.setBounds(new Rectangle(190, ypos, 290, height));
     chimeraPath.addMouseListener(new MouseAdapter()
     {
       @Override
       public void mouseClicked(MouseEvent e)
       {
-        if (e.getClickCount() == 2)
+        if (chimeraPath.isEnabled() && e.getClickCount() == 2)
         {
           String chosen = openFileChooser();
           if (chosen != null)
@@ -1301,7 +1311,7 @@ public class GPreferences extends JPanel
             MessageManager.getString("label.mapping_method"));
     mmTitledBorder.setTitleFont(LABEL_FONT);
     mappingPanel.setBorder(mmTitledBorder);
-    mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
+    mappingPanel.setBounds(new Rectangle(10, ypos, 472, 45));
     // GridLayout mappingLayout = new GridLayout();
     mappingPanel.setLayout(new GridLayout());
     mappingPanel.add(nwMapping);
@@ -1312,7 +1322,7 @@ public class GPreferences extends JPanel
     ypos += lineSpacing;
     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
-    docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
+    docFieldPref.setBounds(new Rectangle(10, ypos, 470, 120));
     structureTab.add(docFieldPref);
 
     return structureTab;
@@ -1720,27 +1730,13 @@ public class GPreferences extends JPanel
     setComboIntStringKey(backupfilesPresetsCombo,
             Cache.getDefault(BackupFiles.NS + "_PRESET",
                     BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
-    // backupsTabUpdatePresets();
 
-    System.out
-            .println("LOADLASTSAVEDBACKUPSOPTIONS SETTING BACKUPS OPTIONS");
     backupsSetOptions(savedPreset);
 
     backupsOptionsSetEnabled();
     updateBackupFilesExampleLabel();
   }
 
-  private void setBackupfilesCustomPreset()
-  {
-    if (customiseCheckbox.isSelected() && getComboIntStringKey(
-            backupfilesPresetsCombo) == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
-    {
-      BackupFilesPresetEntry.backupfilesPresetEntriesValues
-              .put(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
-                      getBackupfilesCurrentEntry());
-    }
-  }
-
   private boolean warnAboutSuffixReverseChange()
   {
     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
@@ -1867,11 +1863,19 @@ public class GPreferences extends JPanel
     presetsComboLabel = new JLabel(title + ":");
     presetsPanel.add(presetsComboLabel, gbc);
 
+    List<Object> entries = Arrays
+            .asList((Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
+    List<String> tooltips = Arrays.asList(
+            BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
+    backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
+            tooltips);
+    /*
     for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
     {
       backupfilesPresetsCombo
               .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
     }
+    */
 
     backupfilesPresetsCombo.addActionListener(new ActionListener()
     {
@@ -1910,6 +1914,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
@@ -1947,6 +1953,8 @@ public class GPreferences extends JPanel
         backupfilesCustomOptionsSetEnabled();
       }
     });
+    customiseCheckbox.setToolTipText(
+            MessageManager.getString("label.customise_description"));
 
     // customise checkbox
     gbc.gridx = 0;
@@ -1963,7 +1971,7 @@ public class GPreferences extends JPanel
   private JPanel initBackupsTabFilenameExamplesPanel()
   {
     String title = MessageManager
-            .getString("label.summary_of_backups_scheme");
+            .getString("label.scheme_examples");
     TitledBorder tb = new TitledBorder(title);
     exampleFilesPanel.setBorder(tb);
     exampleFilesPanel.setLayout(new GridBagLayout());
@@ -1989,8 +1997,8 @@ public class GPreferences extends JPanel
   {
     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
             .getSelectedItem();
-    int key = entry.getKey();
-    String value = entry.getValue();
+    int key = entry.k;
+    String value = entry.v;
 
     if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
             .containsKey(key))
@@ -2001,7 +2009,7 @@ public class GPreferences extends JPanel
     }
     else
     {
-      System.out.println(
+      Cache.log.error(
               "Preset '" + value + "' [key:" + key + "] not implemented");
     }
 
@@ -2011,21 +2019,42 @@ public class GPreferences extends JPanel
     updateBackupFilesExampleLabel();
   }
 
-  protected int getComboIntStringKey(JComboBox<IntKeyStringValueEntry> c)
+  protected int getComboIntStringKey(
+          JComboBox<Object> backupfilesPresetsCombo2)
   {
-    IntKeyStringValueEntry e = (IntKeyStringValueEntry) c.getSelectedItem();
-    return e != null ? e.getKey() : 0;
+    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);
-      if (e.getKey() == key)
+      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;
       }
     }
@@ -2076,7 +2105,6 @@ public class GPreferences extends JPanel
       @Override
       public void keyTyped(KeyEvent e)
       {
-        int count = 300;
         char c = e.getKeyChar();
         if (c == ':' || c == '/' || c == '\\')
         {
@@ -2465,10 +2493,10 @@ public class GPreferences extends JPanel
     {
       try
       {
-        i = Integer.parseInt((String) s.getValue());
+        i = ((Integer) s.getValue()).intValue();
       } catch (Exception e)
       {
-        System.out.println(
+        Cache.log.error(
                 "Exception casting the initial value of s.getValue()");
       }
     }
@@ -2500,7 +2528,7 @@ public class GPreferences extends JPanel
       i = (Integer) s.getValue();
     } catch (Exception e)
     {
-      System.out.println("Failed casting (Integer) JSpinner s.getValue()");
+      Cache.log.error("Failed casting (Integer) JSpinner s.getValue()");
     }
     return i;
   }