2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.bin;
\r
29 * Stores and retrieves Jalview Application Properties
\r
30 * <br><br>Current properties include:
\r
31 * <br>logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
\r
32 * <br>logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
\r
33 * <br>jalview.browser - used in the jalview.utils.browserLauncher class if it doesn't know what else to do.
\r
34 * <br>SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN
\r
35 * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR
\r
36 * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION,
\r
37 * DEFAULT_COLOUR,DEFAULT_FILE_FORMAT,STARTUP_FILE,SHOW_STARTUP_FILE
\r
40 * @version $Revision$
\r
45 /** Jalview Properties */
\r
46 public static Properties applicationProperties;
\r
48 /** Default file is ~/.jalview_properties */
\r
49 static String propertiesFile;
\r
51 /** Called when Jalview is started */
\r
52 public static void loadProperties(String propsFile)
\r
54 applicationProperties = new Properties();
\r
55 propertiesFile = propsFile;
\r
56 if (propsFile == null)
\r
58 propertiesFile = System.getProperty("user.home") + "/.jalview_properties";
\r
63 FileInputStream fis = new FileInputStream(propertiesFile);
\r
64 applicationProperties.load(fis);
\r
65 applicationProperties.remove("LATEST_VERSION");
\r
66 applicationProperties.remove("VERSION");
\r
69 catch (Exception ex)
\r
71 System.out.println("Error reading properties file: "+ex);
\r
74 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
\r
75 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
\r
76 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
\r
79 String buildDetails = "jar:"
\r
81 Cache.class.getProtectionDomain().getCodeSource().getLocation().toString()
\r
82 .concat("!/.build_properties")
\r
85 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
\r
87 InputStream in = localJarFileURL.openStream();
\r
88 applicationProperties.load(in);
\r
91 catch (Exception ex)
\r
93 System.out.println("Error reading build details: "+ex);
\r
94 applicationProperties.remove("VERSION");
\r
97 String jnlpVersion = System.getProperty("jalview.version");
\r
98 String codeVersion = getProperty("VERSION");
\r
101 if(codeVersion==null)
\r
103 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
\r
104 codeVersion = "Test";
\r
105 jnlpVersion = "Test";
\r
109 System.out.println("Version: "+codeVersion);
\r
111 // jnlpVersion will be null if we're using InstallAnywhere
\r
112 // Dont do this check if running in headless mode
\r
113 if(jnlpVersion==null && (
\r
114 System.getProperty("java.awt.headless")==null
\r
115 || System.getProperty("java.awt.headless").equals("false")))
\r
118 java.net.URL url = new java.net.URL("http://www.jalview.org/webstart/jalview.jnlp");
\r
119 BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
\r
120 String line = null;
\r
121 while( (line = in.readLine()) !=null)
\r
123 if(line.indexOf("jalview.version")==-1)
\r
126 line = line.substring(line.indexOf("value=")+7);
\r
127 line = line.substring(0, line.lastIndexOf("\""));
\r
128 jnlpVersion = line;
\r
131 }catch(Exception ex)
\r
132 { jnlpVersion = codeVersion; }
\r
134 System.out.println("Latest : "+jnlpVersion);
\r
137 setProperty("LATEST_VERSION", jnlpVersion);
\r
138 setProperty("VERSION", codeVersion);
\r
142 * Gets Jalview application property of given key. Returns null
\r
145 * @param key Name of property
\r
147 * @return Property value
\r
149 public static String getProperty(String key)
\r
151 return applicationProperties.getProperty(key);
\r
155 * Stores property in the file "HOME_DIR/.jalview_properties"
\r
157 * @param key Name of object
\r
158 * @param obj String value of property
\r
160 * @return String value of property
\r
162 public static String setProperty(String key, String obj)
\r
166 FileOutputStream out = new FileOutputStream(propertiesFile);
\r
168 applicationProperties.setProperty(key, obj);
\r
170 applicationProperties.store(out, "---JalviewX Properties File---");
\r
173 catch (Exception ex)
\r