JAL-1528 new Preference CHIMERA_PATH (Preferences | Structure)
[jalview.git] / src / jalview / gui / Preferences.java
index 2e8aa89..ab4f94f 100755 (executable)
@@ -35,7 +35,9 @@ import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
+import java.io.File;
 import java.util.Collection;
 import java.util.StringTokenizer;
 import java.util.Vector;
@@ -65,6 +67,8 @@ public class Preferences extends GPreferences
 
   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
 
+  public static final String CHIMERA_PATH = "CHIMERA_PATH";
+
   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
 
   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
@@ -281,6 +285,25 @@ public class Preferences extends GPreferences
     addTempFactor.setEnabled(structSelected);
     structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
             Viewer.JMOL.name()));
+    chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
+    chimeraPath.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        if (chimeraPath.getText().trim().length() > 0)
+        {
+          File f = new File(chimeraPath.getText());
+          if (!f.canExecute())
+          {
+            JOptionPane.showInternalMessageDialog(Desktop.desktop,
+                    MessageManager.getString("label.invalid_path"),
+                    MessageManager.getString("label.invalid_name"),
+                    JOptionPane.ERROR_MESSAGE);
+          }
+        }
+      }
+    });
 
     /*
      * Set Connections tab defaults
@@ -449,6 +472,7 @@ public class Preferences extends GPreferences
             Boolean.toString(structFromPdb.isSelected()));
     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
             .getSelectedItem().toString());
+    Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
 
     /*
      * Save Output settings
@@ -466,15 +490,7 @@ public class Preferences extends GPreferences
     /*
      * Save Connections settings
      */
-    if (defaultBrowser.getText().trim().length() < 1)
-    {
-      Cache.applicationProperties.remove("DEFAULT_BROWSER");
-    }
-    else
-    {
-      Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
-              defaultBrowser.getText());
-    }
+    Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
 
     jalview.util.BrowserLauncher.resetBrowser();
 
@@ -502,25 +518,9 @@ public class Preferences extends GPreferences
     Cache.applicationProperties.setProperty("USE_PROXY",
             Boolean.toString(useProxy.isSelected()));
 
-    if (proxyServerTB.getText().trim().length() < 1)
-    {
-      Cache.applicationProperties.remove("PROXY_SERVER");
-    }
-    else
-    {
-      Cache.applicationProperties.setProperty("PROXY_SERVER",
-              proxyServerTB.getText());
-    }
+    Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
 
-    if (proxyPortTB.getText().trim().length() < 1)
-    {
-      Cache.applicationProperties.remove("PROXY_PORT");
-    }
-    else
-    {
-      Cache.applicationProperties.setProperty("PROXY_PORT",
-              proxyPortTB.getText());
-    }
+    Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
 
     if (useProxy.isSelected())
     {