JAL-3746 apply copyright to source
[jalview.git] / src / jalview / util / LaunchUtils.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util;
22
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.util.Properties;
28
29 public class LaunchUtils
30 {
31
32   public static void loadChannelProps(File dir)
33   {
34     ChannelProperties.loadProps(dir);
35   }
36
37   private static Properties userPreferences = null;
38
39   public static String getUserPreference(String key)
40   {
41     if (userPreferences == null)
42     {
43       String channelPrefsFilename = ChannelProperties
44               .getProperty("preferences.filename");
45       if (channelPrefsFilename == null)
46       {
47         return null;
48       }
49       File propertiesFile = new File(System.getProperty("user.home"),
50               channelPrefsFilename);
51       if (!propertiesFile.exists())
52       {
53         return null;
54       }
55       try
56       {
57         userPreferences = new Properties();
58         userPreferences.load(new FileInputStream(propertiesFile));
59       } catch (FileNotFoundException e)
60       {
61         // didn't find user preferences file
62         return null;
63       } catch (IOException e)
64       {
65         System.err.println(e.getMessage());
66         return null;
67       }
68     }
69     return userPreferences.getProperty(key);
70   }
71
72   public static boolean getBooleanUserPreference(String key)
73   {
74     return Boolean.parseBoolean(getUserPreference(key));
75   }
76 }