From d85d2bf55610bc799dd67d7f9ed6b494632e5420 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 9 Aug 2005 16:47:21 +0000 Subject: [PATCH] Properties file is used in preference to viewport/cache/preferences replicating defaults --- src/jalview/bin/Cache.java | 116 +++++++++++++++++++++++++++++------- src/jalview/bin/Jalview.java | 31 ++++------ src/jalview/gui/AlignViewport.java | 61 +++++++++---------- 3 files changed, 135 insertions(+), 73 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index d8a6d3d..d5757df 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -30,7 +30,6 @@ import java.net.*; *

Current properties include: *
logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services) *
logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization) - *
jalview.browser - used in the jalview.utils.browserLauncher class if it doesn't know what else to do. *
SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION, @@ -43,7 +42,7 @@ public class Cache { /** Jalview Properties */ - public static Properties applicationProperties; + public static Properties applicationProperties = new Properties(); /** Default file is ~/.jalview_properties */ static String propertiesFile; @@ -51,7 +50,6 @@ public class Cache /** Called when Jalview is started */ public static void loadProperties(String propsFile) { - applicationProperties = new Properties(); propertiesFile = propsFile; if (propsFile == null) { @@ -71,6 +69,14 @@ public class Cache System.out.println("Error reading properties file: "+ex); } + if(getDefault("USE_PROXY", false)) + { + System.out.println("Using proxyServer: "+getDefault("PROXY_SERVER", null)+ + " proxyPort: "+getDefault("PROXY_PORT", null)); + System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null)); + System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null)); + } + // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW @@ -114,30 +120,55 @@ public class Cache System.getProperty("java.awt.headless")==null || System.getProperty("java.awt.headless").equals("false"))) { - try{ - java.net.URL url = new java.net.URL("http://www.jalview.org/webstart/jalview.jnlp"); - BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); - String line = null; - while( (line = in.readLine()) !=null) - { - if(line.indexOf("jalview.version")==-1) - continue; - line = line.substring(line.indexOf("value=")+7); - line = line.substring(0, line.lastIndexOf("\"")); - jnlpVersion = line; - break; + + class VersionChecker + extends Thread + { + public void run() + { + String jnlpVersion = null; + try + { + java.net.URL url = new java.net.URL( + "http://www.jalview.org/webstart/jalview.jnlp"); + BufferedReader in = new BufferedReader(new InputStreamReader(url. + openStream())); + String line = null; + while ( (line = in.readLine()) != null) + { + if (line.indexOf("jalview.version") == -1) + continue; + + line = line.substring(line.indexOf("value=") + 7); + line = line.substring(0, line.lastIndexOf("\"")); + jnlpVersion = line; + break; + } + } + catch (Exception ex) + { + System.out.println(ex); + jnlpVersion = getProperty("VERSION"); + } + + setProperty("LATEST_VERSION", jnlpVersion); } - }catch(Exception ex) - { jnlpVersion = codeVersion; } + } - System.out.println("Latest : "+jnlpVersion); + VersionChecker vc = new VersionChecker(); + vc.start(); + } + else + { + setProperty("LATEST_VERSION", jnlpVersion); } - setProperty("LATEST_VERSION", jnlpVersion); setProperty("VERSION", codeVersion); } + + /** * Gets Jalview application property of given key. Returns null * if key not found @@ -151,6 +182,37 @@ public class Cache return applicationProperties.getProperty(key); } + + /** These methods are used when checking if the saved preference + * is different to the default setting + */ + + public static boolean getDefault(String property, boolean def) + { + String string = getProperty(property); + if (string != null) + { + def = Boolean.valueOf(string).booleanValue(); + } + + return def; + } + + /** These methods are used when checking if the saved preference + * is different to the default setting + */ + public static String getDefault(String property, String def) + { + String string = getProperty(property); + if (string != null) + { + return string; + } + + return def; + } + + /** * Stores property in the file "HOME_DIR/.jalview_properties" * @@ -164,16 +226,24 @@ public class Cache try { FileOutputStream out = new FileOutputStream(propertiesFile); - applicationProperties.setProperty(key, obj); - applicationProperties.store(out, "---JalviewX Properties File---"); out.close(); } catch (Exception ex) + { } + return obj; + } + + public static void saveProperties() + { + try { + FileOutputStream out = new FileOutputStream(propertiesFile); + applicationProperties.store(out, "---JalviewX Properties File---"); + out.close(); } - - return obj; + catch (Exception ex) + { } } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 3ab3bf4..882818c 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -25,9 +25,6 @@ import org.apache.log4j.*; import javax.swing.*; import java.util.Vector; -import jalview.datamodel.Alignment; -import jalview.io.FormatAdapter; -import jalview.datamodel.SequenceI; /** @@ -103,18 +100,17 @@ public class Jalview } - if (aparser.contains("nodisplay")) - System.setProperty("java.awt.headless", "true"); - - if( System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true")) - { - headless = true; - } + if (aparser.contains("nodisplay")) + System.setProperty("java.awt.headless", "true"); + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) + { + headless = true; + } Cache.loadProperties(aparser.getValue("props")); - jalview.gui.Preferences.initPreferences(); + try { initLogger(); @@ -131,9 +127,8 @@ public class Jalview try { UIManager.setLookAndFeel( - // "javax.swing.plaf.metal.MetalLookAndFeel" - // "javax.swing.plaf.multi.MultiLookAndFeel" - UIManager.getSystemLookAndFeelClassName()); + UIManager.getSystemLookAndFeelClassName() + ); } catch (Exception ex) { @@ -234,11 +229,11 @@ public class Jalview ////////////////////// if ( !headless && - jalview.gui.Preferences.showStartupFile && - jalview.gui.Preferences.startupFile != null) + jalview.bin.Cache.getProperty("SHOW_STARTUP_FILE").equals("true") && + jalview.bin.Cache.getProperty("STARTUP_FILE") != null) { - file = jalview.gui.Preferences.startupFile; + file = jalview.bin.Cache.getProperty("STARTUP_FILE"); protocol = "File"; if (file.indexOf("http:") > -1) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 904e1e2..05927b6 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -106,48 +106,43 @@ public class AlignViewport */ public void updateFromPreferences() { - showFullId = Preferences.showFullId; - showAnnotation = Preferences.showAnnotation; - showConservation = Preferences.showConservation; - showQuality = Preferences.showQuality; - showIdentity = Preferences.showIdentity; - showFullId = Preferences.showFullId; - - String fontName = Preferences.fontName; - String fontStyle = Preferences.fontStyle; - String fontSize = Cache.getProperty("FONT_SIZE"); - - if ((fontName != null) && (fontStyle != null) && (fontSize != null)) - { - int style = 0; + showFullId = Cache.getDefault("SHOW_FULL_ID", true); + showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + showConservation = Cache.getDefault("SHOW_CONSERVATION", true); - if (fontStyle.equals("bold")) - { - style = 1; - } - else if (fontStyle.equals("italic")) - { - style = 2; - } + showQuality = Cache.getDefault("SHOW_QUALITY", true); + showIdentity = Cache.getDefault("SHOW_IDENTITY", true); - setFont(new Font(fontName, style, Integer.parseInt(fontSize))); - } - else - { - setFont(font); - } + String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); + String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ; + String fontSize = Cache.getDefault("FONT_SIZE", "10"); + + int style = 0; + + if (fontStyle.equals("bold")) + { + style = 1; + } + else if (fontStyle.equals("italic")) + { + style = 2; + } + + setFont(new Font(fontName, style, Integer.parseInt(fontSize))); + + + alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) ); - alignment.setGapCharacter(Preferences.gapSymbol); // We must set conservation and consensus before setting colour, // as Blosum and Clustal require this to be done updateConservation(); updateConsensus(); - if (Preferences.defaultColour != null) + if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) { - globalColourScheme = ColourSchemeProperty.getColour(alignment, - Preferences.defaultColour); + globalColourScheme = ColourSchemeProperty.getColour(alignment, + jalview.bin.Cache.getProperty("DEFAULT_COLOUR")); if (globalColourScheme instanceof UserColourScheme) { @@ -161,6 +156,8 @@ public class AlignViewport } } + + /** * DOCUMENT ME! * -- 1.7.10.2