JAL-2629 add ability to select hmmer binaries folder
[jalview.git] / src / jalview / bin / Cache.java
index 6764430..4b890cc 100755 (executable)
 package jalview.bin;
 
 import jalview.datamodel.PDBEntry;
+import jalview.gui.UserDefinedColours;
+import jalview.schemes.ColourSchemeLoader;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.UserColourScheme;
 import jalview.structure.StructureImportSettings;
 import jalview.urls.IdOrgSettings;
+import jalview.util.ColorUtils;
 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
 import jalview.ws.sifts.SiftsSettings;
@@ -41,6 +46,7 @@ import java.util.Date;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Properties;
+import java.util.StringTokenizer;
 import java.util.TreeSet;
 
 import org.apache.log4j.ConsoleAppender;
@@ -184,6 +190,8 @@ import org.apache.log4j.SimpleLayout;
  * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
  * display</li>
  * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
+ * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
+ * </li>
  * 
  * </ul>
  * Deprecated settings:
@@ -241,9 +249,7 @@ public class Cache
    * Identifiers.org download settings
    */
   private static final String ID_ORG_FILE = System.getProperty("user.home")
-          + File.separatorChar + ".jalview_identifiers";
-
-  private static final String ID_ORG_URL = "http://identifiers.org/rest/collections/";
+          + File.separatorChar + ".identifiers.org.ids.json";
 
   /**
    * Allowed values are PDB or mmCIF
@@ -254,6 +260,8 @@ public class Cache
   private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
           .toString();
 
+  private static String HMMER_PATH;
+
   /*
    * a date formatter using a fixed (rather than the user's) locale; 
    * this ensures that date properties can be written and re-read successfully
@@ -275,7 +283,7 @@ public class Cache
     @Override
     public synchronized Enumeration<Object> keys()
     {
-      return Collections.enumeration(new TreeSet<Object>(super.keySet()));
+      return Collections.enumeration(new TreeSet<>(super.keySet()));
     }
   };
 
@@ -456,7 +464,8 @@ public class Cache
             "sifts_cache_threshold_in_days",
             DEFAULT_CACHE_THRESHOLD_IN_DAYS));
 
-    IdOrgSettings.setUrl(ID_ORG_URL);
+    IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
+            "http://www.jalview.org/services/identifiers"));
     IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
 
     System.out
@@ -545,7 +554,7 @@ public class Cache
     setProperty("VERSION", codeVersion);
 
     // LOAD USERDEFINED COLOURS
-    jalview.gui.UserDefinedColours
+    jalview.bin.Cache
             .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
     jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
             false);
@@ -887,19 +896,11 @@ public class Cache
     {
       return defcolour;
     }
-    Color col = jalview.schemes.ColourSchemeProperty
-            .getAWTColorFromName(colprop);
+    Color col = ColorUtils.parseColourString(colprop);
     if (col == null)
     {
-      try
-      {
-        col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
-      } catch (Exception ex)
-      {
-        log.warn("Couldn't parse '" + colprop + "' as a colour for "
-                + property);
-        col = null;
-      }
+      log.warn("Couldn't parse '" + colprop + "' as a colour for "
+              + property);
     }
     return (col == null) ? defcolour : col;
   }
@@ -1016,4 +1017,54 @@ public class Cache
       Cache.applicationProperties.setProperty(propName, value);
     }
   }
+
+  /**
+   * Loads in user colour schemes from files.
+   * 
+   * @param files
+   *          a '|'-delimited list of file paths
+   */
+  public static void initUserColourSchemes(String files)
+  {
+    if (files == null || files.length() == 0)
+    {
+      return;
+    }
+  
+    // In case colours can't be loaded, we'll remove them
+    // from the default list here.
+    StringBuffer coloursFound = new StringBuffer();
+    StringTokenizer st = new StringTokenizer(files, "|");
+    while (st.hasMoreElements())
+    {
+      String file = st.nextToken();
+      try
+      {
+        UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
+        if (ucs != null)
+        {
+          if (coloursFound.length() > 0)
+          {
+            coloursFound.append("|");
+          }
+          coloursFound.append(file);
+          ColourSchemes.getInstance().registerColourScheme(ucs);
+        }
+      } catch (Exception ex)
+      {
+        System.out.println("Error loading User ColourFile\n" + ex);
+      }
+    }
+    if (!files.equals(coloursFound.toString()))
+    {
+      if (coloursFound.toString().length() > 1)
+      {
+        setProperty(UserDefinedColours.USER_DEFINED_COLOURS, coloursFound.toString());
+      }
+      else
+      {
+        applicationProperties.remove(UserDefinedColours.USER_DEFINED_COLOURS);
+      }
+    }
+  }
 }