Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / getdown / src / getdown / core / src / main / java / jalview / util / LaunchUtils.java
diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java b/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java
new file mode 100644 (file)
index 0000000..3302dba
--- /dev/null
@@ -0,0 +1,56 @@
+package jalview.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+public class LaunchUtils
+{
+
+  public static void loadChannelProps(File dir)
+  {
+    ChannelProperties.loadProps(dir);
+  }
+
+  private static Properties userPreferences = null;
+
+  public static String getUserPreference(String key)
+  {
+    if (userPreferences == null)
+    {
+      String channelPrefsFilename = ChannelProperties
+              .getProperty("preferences.filename");
+      if (channelPrefsFilename == null)
+      {
+        return null;
+      }
+      File propertiesFile = new File(System.getProperty("user.home"),
+              channelPrefsFilename);
+      if (!propertiesFile.exists())
+      {
+        return null;
+      }
+      try
+      {
+        userPreferences = new Properties();
+        userPreferences.load(new FileInputStream(propertiesFile));
+      } catch (FileNotFoundException e)
+      {
+        // didn't find user preferences file
+        return null;
+      } catch (IOException e)
+      {
+        System.err.println(e.getMessage());
+        return null;
+      }
+    }
+    return userPreferences.getProperty(key);
+  }
+
+  public static boolean getBooleanUserPreference(String key)
+  {
+    return Boolean.parseBoolean(getUserPreference(key));
+  }
+}