JAL-3551 working proof of concept of Jalview driving PyMOL
[jalview.git] / src / jalview / gui / Preferences.java
index 3070ca1..d0f6cdb 100755 (executable)
@@ -107,6 +107,8 @@ public class Preferences extends GPreferences
 
   public static final String CHIMERAX_PATH = "CHIMERAX_PATH";
 
+  public static final String PYMOL_PATH = "PYMOL_PATH";
+
   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
 
   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
@@ -347,14 +349,14 @@ public class Preferences extends GPreferences
     boolean isChimeraX = viewerType.equals(ViewerType.CHIMERAX.name());
     if (viewerType.equals(ViewerType.JMOL.name()))
     {
-      chimeraPath.setText("");
+      structureViewerPath.setText("");
     }
     else
     {
-      chimeraPath.setText(Cache
+      structureViewerPath.setText(Cache
               .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
     }
-    chimeraPath.addActionListener(new ActionListener()
+    structureViewerPath.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -364,7 +366,7 @@ public class Preferences extends GPreferences
           Cache.setProperty(structViewer.getSelectedItem()
                   .equals(ViewerType.CHIMERAX.name())
                   ? CHIMERAX_PATH
-                  : CHIMERA_PATH, chimeraPath.getText());
+                  : CHIMERA_PATH, structureViewerPath.getText());
         }
       }
     });
@@ -697,12 +699,22 @@ public class Preferences extends GPreferences
             Boolean.toString(useRnaView.isSelected()));
     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
             Boolean.toString(structFromPdb.isSelected()));
+    String viewer = structViewer.getSelectedItem().toString();
+    String viewerPath = structureViewerPath.getText();
     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
-            structViewer.getSelectedItem().toString());
-    boolean isChimeraX = structViewer.getSelectedItem().toString()
-            .equals(ViewerType.CHIMERAX.name());
-    Cache.setOrRemove(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH,
-            chimeraPath.getText());
+            viewer);
+    if (viewer.equals(ViewerType.CHIMERA.name()))
+    {
+      Cache.setOrRemove(CHIMERA_PATH, viewerPath);
+    }
+    else if (viewer.equals(ViewerType.CHIMERAX.name()))
+    {
+      Cache.setOrRemove(CHIMERAX_PATH, viewerPath);
+    }
+    else if (viewer.equals(ViewerType.PYMOL.name()))
+    {
+      Cache.setOrRemove(PYMOL_PATH, viewerPath);
+    }
     Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
             Boolean.toString(siftsMapping.isSelected()));
     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
@@ -1212,9 +1224,9 @@ public class Preferences extends GPreferences
    */
   private boolean validateChimeraPath()
   {
-    if (chimeraPath.getText().trim().length() > 0)
+    if (structureViewerPath.getText().trim().length() > 0)
     {
-      File f = new File(chimeraPath.getText());
+      File f = new File(structureViewerPath.getText());
       if (!f.canExecute())
       {
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
@@ -1228,33 +1240,33 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * If Chimera or ChimeraX is selected, check it can be found on default or
-   * user-specified path, if not show a warning/help dialog.
+   * If Chimera or ChimeraX or Pymol is selected, check it can be found on
+   * default or user-specified path, if not show a warning/help dialog
    */
   @Override
   protected void structureViewer_actionPerformed(String selectedItem)
   {
     if (selectedItem.equals(ViewerType.JMOL.name()))
     {
-      chimeraPath.setEnabled(false);
-      chimeraPathLabel.setEnabled(false);
+      structureViewerPath.setEnabled(false);
+      structureViewerPathLabel.setEnabled(false);
       return;
     }
     boolean found = false;
-    chimeraPath.setEnabled(true);
-    chimeraPathLabel.setEnabled(true);
-    chimeraPathLabel.setText(MessageManager
+    structureViewerPath.setEnabled(true);
+    structureViewerPathLabel.setEnabled(true);
+    structureViewerPathLabel.setText(MessageManager
             .formatMessage("label.chimera_path", selectedItem));
 
     /*
      * Try user-specified and standard paths for Chimera executable
      */
     boolean isChimeraX = selectedItem.equals(ViewerType.CHIMERAX.name());
-    chimeraPath.setText(Cache
+    structureViewerPath.setText(Cache
             .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
 
     List<String> paths = StructureManager.getChimeraPaths(isChimeraX);
-    paths.add(0, chimeraPath.getText());
+    paths.add(0, structureViewerPath.getText());
     for (String path : paths)
     {
       if (new File(path.trim()).canExecute())