first experiment with GA application use tracking
[jalview.git] / src / jalview / bin / Cache.java
index d315626..dad7326 100755 (executable)
@@ -22,6 +22,10 @@ import java.io.*;
 import java.util.*;
 
 import org.apache.log4j.*;
+import org.biojava.dasobert.dasregistry.Das1Source;
+
+import com.boxysystems.jgoogleanalytics.FocusPoint;
+import com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker;
 
 /**
  * Stores and retrieves Jalview Application Properties Lists and fields within
@@ -105,6 +109,9 @@ import org.apache.log4j.*;
  * (false) </li>
  * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence ID tooltip</li>
  * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence ID tooltip</li>
+ * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved displayed as '.'</li>
+ * <li>SORT_BY_TREE (false) sort the current alignment view according to the order of a newly displayed tree</li>
+ * 
  * <li> </li>
  * 
  * </ul>
@@ -131,6 +138,10 @@ public class Cache
 
   public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
 
+  public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
+
+  public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
+
   /**
    * Initialises the Jalview Application Log
    */
@@ -485,4 +496,71 @@ public class Cache
     return (groovyJarsArePresent > 0);
   }
 
+  /**
+   * generate Das1Sources from the local das source list
+   * @return Vector of Das1Sources
+   */
+  public static Vector getLocalDasSources()
+  {
+    Vector localSources = new Vector();
+    String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
+    if (local != null)
+    {
+      StringTokenizer st = new StringTokenizer(local, "\t");
+      while (st.hasMoreTokens())
+      {
+        String token = st.nextToken();
+        int bar = token.indexOf("|");
+        Das1Source source = new Das1Source();
+        source.setUrl(token.substring(bar + 1));
+        if (source.getUrl().startsWith("sequence:"))
+        {
+          source.setUrl(source.getUrl().substring(9));
+          // this source also serves sequences as well as features
+          source.setCapabilities(new String[] { "sequence", "features"});
+        } else {
+          // default is that all user added sources serve features
+          source.setCapabilities(new String[] { "features"}); 
+        }
+
+        source.setNickname(token.substring(0, bar));
+
+        localSources.addElement(source);
+      }
+    }
+    return localSources;
+  }
+  
+  public static JGoogleAnalyticsTracker tracker=null;
+  
+  public static void initGoogleTracker()
+  {
+    if (tracker==null)
+    {
+      String vrs="No Version Accessible";
+      try {
+    //Google analytics tracking code for Library Finder
+      tracker = new JGoogleAnalyticsTracker("Jalview Desktop",
+              (vrs=jalview.bin.Cache.getProperty("VERSION")+"_"+jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")),
+              "UA-9060947-1");
+      tracker.trackAsynchronously(new FocusPoint("Application Started."));
+    } catch (RuntimeException e)
+    {
+      if (log!=null) {
+        log.debug("Caught runtime exception in googletracker init:",e);
+      } 
+      // quietly return.
+    }
+      catch (Exception e)
+    {
+        // unexpected error
+        if (log!=null)
+        {
+          log.warn("Failed to initialise GoogleTracker for Jalview Desktop with version "+vrs,e); 
+        } else {
+          log.warn("Failed to initialise GoogleTracker for Jalview Desktop with version "+vrs,e);
+        }
+    }
+    }
+  }
 }