+ /**
+ * 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 = ColorUtils.parseColourString(colprop);
+ if (col == null)
+ {
+ log.warn("Couldn't parse '" + colprop + "' as a colour for "
+ + property);
+ }
+ 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));
+ }
+
+ /**
+ * Stores a formatted date in a jalview property, using a fixed locale.
+ *
+ * @param propertyName
+ * @param date
+ * @return the formatted date string
+ */
+ public static String setDateProperty(String propertyName, Date date)
+ {
+ String formatted = date_format.format(date);
+ setProperty(propertyName, formatted);
+ return formatted;
+ }
+
+ /**
+ * Reads a date stored in a Jalview property, parses it (using a fixed locale
+ * format) and returns as a Date, or null if parsing fails
+ *
+ * @param propertyName
+ * @return
+ *
+ */
+ public static Date getDateProperty(String propertyName)
+ {
+ String val = getProperty(propertyName);
+ if (val != null)
+ {
+ try
+ {
+ return date_format.parse(val);
+ } catch (Exception ex)
+ {
+ System.err.println("Invalid or corrupt date in property '"
+ + propertyName + "' : value was '" + val + "'");
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get and parse a property as an integer. send any parsing problems to
+ * System.err
+ *
+ * @param property
+ * @return null or Integer
+ */
+ public static Integer getIntegerProperty(String property)
+ {
+ String val = getProperty(property);
+ if (val != null && (val = val.trim()).length() > 0)
+ {
+ try
+ {
+ return Integer.valueOf(val);
+ } catch (NumberFormatException x)
+ {
+ System.err.println("Invalid integer in property '" + property
+ + "' (value was '" + val + "')");
+ }
+ }
+ return null;
+ }
+
+ private static DasSourceRegistryI sourceRegistry = null;
+
+ /**
+ * initialise and ..
+ *
+ * @return instance of the das source registry
+ */
+ public static DasSourceRegistryI getDasSourceRegistry()
+ {
+ if (sourceRegistry == null)
+ {
+ sourceRegistry = new DasSourceRegistry();
+ }
+ return sourceRegistry;
+ }
+
+ /**
+ * Set the specified value, or remove it if null or empty. Does not save the
+ * properties file.
+ *
+ * @param propName
+ * @param value
+ */
+ public static void setOrRemove(String propName, String value)
+ {
+ if (propName == null)
+ {
+ return;
+ }
+ if (value == null || value.trim().length() < 1)
+ {
+ Cache.applicationProperties.remove(propName);
+ }
+ else
+ {
+ Cache.applicationProperties.setProperty(propName, value);
+ }
+ }
+
+ /**
+ * Loads in user colour schemes from files.
+ *
+ * @param files
+ * a '|'-delimited list of file paths
+ */
+ public static void initUserColourSchemes(String files)
+ {
+ if (files == null || files.length() == 0)
+ {
+ return;
+ }
+
+ // In case colours can't be loaded, we'll remove them
+ // from the default list here.
+ StringBuffer coloursFound = new StringBuffer();
+ StringTokenizer st = new StringTokenizer(files, "|");
+ while (st.hasMoreElements())
+ {
+ String file = st.nextToken();
+ try
+ {
+ UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
+ if (ucs != null)
+ {
+ if (coloursFound.length() > 0)
+ {
+ coloursFound.append("|");
+ }
+ coloursFound.append(file);
+ ColourSchemes.getInstance().registerColourScheme(ucs);
+ }
+ } catch (Exception ex)
+ {
+ System.out.println("Error loading User ColourFile\n" + ex);
+ }
+ }
+ if (!files.equals(coloursFound.toString()))
+ {
+ if (coloursFound.toString().length() > 1)
+ {
+ setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
+ coloursFound.toString());
+ }
+ else
+ {
+ applicationProperties
+ .remove(UserDefinedColours.USER_DEFINED_COLOURS);
+ }
+ }
+ }