Formatted source
[jalview.git] / src / jalview / bin / Cache.java
index b054bc3..9857f44 100755 (executable)
-/********************
- * 2004 Jalview Reengineered
- * Barton Group
- * Dundee University
- *
- * AM Waterhouse
- *******************/
-
-
-package jalview.bin;
-
-public class Cache
-{
-  public static String LAST_DIRECTORY = ".";
-}
+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+*/\r
+package jalview.bin;\r
+\r
+import java.io.*;\r
+\r
+import java.util.*;\r
+import java.util.jar.*;\r
+\r
+\r
+public class Cache {\r
+    public static String VERSION = "Release 2.0";\r
+    public static String BUILD_DATE = "";\r
+    public static Properties applicationProperties;\r
+\r
+    // Current properties include:\r
+    //\r
+    // LAST_DIRECTORY   , use this to cache record of where the user looked to find a file\r
+    // UNIPROT_CACHE\r
+    // USER_DEFINED_COLOUR - file describing last user set colours\r
+    // FONT_NAME\r
+    // FONT_STYLE\r
+    // FONT_SIZE\r
+    // logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)\r
+    // jalview.browser - used in the jalview.utils.browserLauncher class if it doesn't know what else to do.\r
+    public static void loadProperties() {\r
+        // get last build time.\r
+        long date = 0;\r
+\r
+        try {\r
+            String localFile = Cache.class.getProtectionDomain().getCodeSource()\r
+                                          .getLocation().toString();\r
+            localFile = localFile.concat("!/");\r
+\r
+            String tmpString = "jar:";\r
+            String localJarFileString = tmpString.concat(localFile);\r
+            java.net.URL localJarFileURL = new java.net.URL(localJarFileString);\r
+            java.net.JarURLConnection localJarFile = (java.net.JarURLConnection) localJarFileURL.openConnection();\r
+            date = localJarFile.getLastModified();\r
+        } catch (Exception ex) {\r
+            ex.printStackTrace();\r
+        }\r
+\r
+        if (date == 0) {\r
+            // this is called for unpackaged class files, ie not in a Jar file\r
+            // InstallAnywhere version will find build date this way\r
+            // not entirely accurate as it only tells you when Cache.class was last compiled\r
+            java.io.File f = new java.io.File(System.getProperty("user.dir") +\r
+                    "/jalview/bin/Cache.class");\r
+            date = f.lastModified();\r
+        }\r
+\r
+        if (date != 0) {\r
+            BUILD_DATE = new Date(date).toString();\r
+        }\r
+\r
+        applicationProperties = new Properties();\r
+\r
+        try {\r
+            FileInputStream in = new FileInputStream(System.getProperty(\r
+                        "user.home") + "/.jalview_properties");\r
+            applicationProperties = new Properties();\r
+            applicationProperties.load(in);\r
+            in.close();\r
+        } catch (Exception ex) {\r
+        }\r
+    }\r
+\r
+    public static String getProperty(String key) {\r
+        return applicationProperties.getProperty(key);\r
+    }\r
+\r
+    public static String setProperty(String key, String obj) {\r
+        try {\r
+            FileOutputStream out = new FileOutputStream(System.getProperty(\r
+                        "user.home") + "/.jalview_properties");\r
+\r
+            applicationProperties.setProperty(key, obj);\r
+\r
+            applicationProperties.store(out, "---JalviewX Properties File---");\r
+            out.close();\r
+        } catch (Exception ex) {\r
+        }\r
+\r
+        return obj;\r
+    }\r
+}\r