public enum ColourScheme
{
- AVOID_RED, AVOID_GREEN, AVOID_BLUE, SATURATED, DESATURATED, GREYISH,
- GREYSCALE, BRIGHT, MEDIUM, DARK
+ NONE, AVOID_RED, AVOID_GREEN, AVOID_BLUE, SATURATED, DESATURATED,
+ GREYISH, GREYSCALE, BRIGHT, MEDIUM, DARK
}
public static float[] getHSBRanges(String colourScheme)
float Smax = 1.0f;
float Bmin = 0.6f;
float Bmax = 1.0f;
- for (String scheme : colourScheme.split(","))
+ if (!colourScheme.contains(ColourScheme.NONE.name()))
{
- Console.debug("Applying colourScheme component " + scheme);
- ColourScheme cs;
- try
- {
- cs = ColourScheme.valueOf(scheme);
- } catch (IllegalArgumentException | NullPointerException e)
+ for (String scheme : colourScheme.split(","))
{
- Console.warn("Did not recognise something in the colour scheme '"
- + colourScheme + "'");
- return new float[] { Hmin, Hmax, Smin, Smax, Bmin, Bmax };
- }
- switch (cs)
- {
- case AVOID_RED:
- Hmin = 0.15f;
- Hmax = 0.85f;
- break;
- case AVOID_GREEN:
- Hmin = 0.48f;
- Hmax = 0.18f;
- break;
- case AVOID_BLUE:
- Hmin = 0.81f;
- Hmax = 0.51f;
- break;
- case SATURATED:
- Smin = 1.0f;
- Smax = 1.0f;
- break;
- case DESATURATED:
- Smin = 0.2f;
- Smax = 0.6f;
- break;
- case GREYISH:
- Smin = 0.0f;
- Smax = 0.2f;
- case GREYSCALE:
- Smin = 0.0f;
- Smax = 0.0f;
- Bmin = 0.1f;
- Bmax = 0.9f;
- break;
- case BRIGHT:
- Bmin = 1.0f;
- Bmax = 1.0f;
- break;
- case MEDIUM:
- Bmin = 0.6f;
- Bmax = 0.8f;
- case DARK:
- Bmin = 0.1f;
- Bmax = 0.4f;
- break;
+ Console.debug("Applying colourScheme component " + scheme);
+ ColourScheme cs;
+ try
+ {
+ cs = ColourScheme.valueOf(scheme);
+ } catch (IllegalArgumentException | NullPointerException e)
+ {
+ Console.warn("Did not recognise something in the colour scheme '"
+ + colourScheme + "'");
+ return new float[] { Hmin, Hmax, Smin, Smax, Bmin, Bmax };
+ }
+ switch (cs)
+ {
+ case AVOID_RED:
+ Hmin = 0.15f;
+ Hmax = 0.85f;
+ break;
+ case AVOID_GREEN:
+ Hmin = 0.48f;
+ Hmax = 0.18f;
+ break;
+ case AVOID_BLUE:
+ Hmin = 0.81f;
+ Hmax = 0.51f;
+ break;
+ case SATURATED:
+ Smin = 1.0f;
+ Smax = 1.0f;
+ break;
+ case DESATURATED:
+ Smin = 0.2f;
+ Smax = 0.6f;
+ break;
+ case GREYISH:
+ Smin = 0.0f;
+ Smax = 0.2f;
+ case GREYSCALE:
+ Smin = 0.0f;
+ Smax = 0.0f;
+ Bmin = 0.1f;
+ Bmax = 0.9f;
+ break;
+ case BRIGHT:
+ Bmin = 1.0f;
+ Bmax = 1.0f;
+ break;
+ case MEDIUM:
+ Bmin = 0.6f;
+ Bmax = 0.8f;
+ case DARK:
+ Bmin = 0.1f;
+ Bmax = 0.4f;
+ break;
+ }
}
}
return new float[] { Hmin, Hmax, Smin, Smax, Bmin, Bmax };
// use first three bytes from MD5 rather than String.hashCode() as short
// strings all low number hashCodes
- byte[] hash = StringUtils.getMD5Bytes(name);
+ byte[] hash = StringUtils.getHashedBytes(name);
int b = hash.length > 0 ? Byte.toUnsignedInt(hash[0]) : 0;
int g = hash.length > 1 ? Byte.toUnsignedInt(hash[1]) : 0;
int r = hash.length > 2 ? Byte.toUnsignedInt(hash[2]) : 0;
return max;
}
+ private final static String fixedSalt = "Fixed Jalview Salt String";
+
/*
* return an MD5 hash of the given String
*/
- public static byte[] getMD5Bytes(String name)
+ public static byte[] getHashedBytes(String name)
{
- final String alg = "MD5";
+ final String alg = "SHA-256";
+ final String enc = "UTF-8";
try
{
- MessageDigest md5 = MessageDigest.getInstance(alg);
- return md5.digest(name.getBytes());
+ MessageDigest hash = MessageDigest.getInstance(alg);
+ Console.debug("Using hashing algorithm " + alg);
+ return hash.digest((name + fixedSalt).getBytes(enc));
} catch (NoSuchAlgorithmException e)
{
Console.warn("Could not find hashing algorithm '" + alg + "'");
- return null;
+ } catch (UnsupportedEncodingException e)
+ {
+ Console.warn("Could not find character encoding '" + enc + "'");
}
+ return null;
}
- public static String getMD5String(String name)
+ public static String getHashedString(String name)
{
- byte[] hashBytes = getMD5Bytes(name);
+ // add a string to ensure some length to the name string
+ byte[] hashBytes = getHashedBytes(name);
if (hashBytes == null)
{
return null;