X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;h=68edf1bcef3ea849136fabd24dc7daac64bed5cc;hb=5e34c2ccda1cf0d409618a564804408350c932d0;hp=48837ff99f68878911d9f01f9bb7535b3317bd83;hpb=077fea81a02a33eefed6895bfa7cff993609dab8;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 48837ff..68edf1b 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -17,6 +17,7 @@ */ package jalview.bin; +import java.awt.Color; import java.io.*; import java.util.*; @@ -105,7 +106,7 @@ import org.biojava.dasobert.dasregistry.Das1Source; *
  • SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop * (false)
  • *
  • VERSION_CHECK (true) check for the latest release version from - * www.jalview.org
  • + * www.jalview.org (or the alias given by the www.jalview.org property) *
  • SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence * ID tooltip
  • *
  • SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence @@ -129,8 +130,9 @@ import org.biojava.dasobert.dasregistry.Das1Source; *
  • *
  • SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery * warning dialog box is displayed.
  • - * - *
  • + *
  • ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation when shading by annotation
  • + *
  • ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation when shading by annotation
  • + *
  • www.jalview.org (http://www.jalview.org) a property enabling all HTTP requests to be redirected to a mirror of http://www.jalview.org
  • * *
  • * @@ -173,6 +175,8 @@ public class Cache /** Default file is ~/.jalview_properties */ static String propertiesFile; + private static boolean propsAreReadOnly=false; + public static void initLogger() { if (log != null) @@ -225,11 +229,31 @@ public class Cache { propertiesFile = System.getProperty("user.home") + File.separatorChar + ".jalview_properties"; + } else { + // don't corrupt the file we've been given. + propsAreReadOnly = true; } try { - FileInputStream fis = new FileInputStream(propertiesFile); + InputStream fis; + try + { + fis = new java.net.URL(propertiesFile).openStream(); + System.out.println("Loading jalview properties from : " + + propertiesFile); + System.out + .println("Disabling Jalview writing to user's local properties file."); + propsAreReadOnly = true; + + } catch (Exception ex) + { + fis = null; + } + if (fis == null) + { + fis = new FileInputStream(propertiesFile); + } applicationProperties.load(fis); applicationProperties.remove("LATEST_VERSION"); applicationProperties.remove("VERSION"); @@ -306,7 +330,7 @@ public class Cache System.setProperty("sun.net.client.defaultConnectTimeout", "5000"); java.net.URL url = new java.net.URL( - "http://www.jalview.org/webstart/jalview.jnlp"); + Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp"); BufferedReader in = new BufferedReader(new InputStreamReader( url.openStream())); String line = null; @@ -417,12 +441,16 @@ public class Cache */ public static String setProperty(String key, String obj) { + try { - FileOutputStream out = new FileOutputStream(propertiesFile); applicationProperties.setProperty(key, obj); - applicationProperties.store(out, "---JalviewX Properties File---"); - out.close(); + if (!propsAreReadOnly) + { + FileOutputStream out = new FileOutputStream(propertiesFile); + applicationProperties.store(out, "---JalviewX Properties File---"); + out.close(); + } } catch (Exception ex) { System.out.println("Error setting property: " + key + " " + obj @@ -447,14 +475,17 @@ public class Cache */ public static void saveProperties() { - try - { - FileOutputStream out = new FileOutputStream(propertiesFile); - applicationProperties.store(out, "---JalviewX Properties File---"); - out.close(); - } catch (Exception ex) + if (!propsAreReadOnly) { - System.out.println("Error saving properties: " + ex); + try + { + FileOutputStream out = new FileOutputStream(propertiesFile); + applicationProperties.store(out, "---JalviewX Properties File---"); + out.close(); + } catch (Exception ex) + { + System.out.println("Error saving properties: " + ex); + } } } @@ -697,4 +728,40 @@ public class Cache } } + /** + * get the user's default colour if available + * @param property + * @param defcolour + * @return + */ + public static Color getDefaultColour(String property, Color defcolour) + { + String colprop = getProperty(property); + if (colprop==null) { + return defcolour; + } + Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop); + if (col==null) + { + try { + col = new jalview.schemes.UserColourScheme(colprop).findColour('A'); + } catch (Exception ex) + { + log.warn("Couldn't parse '"+colprop+"' as a colour for "+property); + col=null; + } + } + return (col==null) ? defcolour: col; + } + + /** + * store a colour as a Jalview user default property + * @param property + * @param colour + */ + public static void setColourProperty(String property, Color colour) + { + setProperty(property, jalview.util.Format + .getHexString(colour)); + } }