+ Object colour = null;\r
+ String colscheme = st.nextToken();\r
+ if (colscheme.indexOf("|") > -1\r
+ || colscheme.trim().equalsIgnoreCase("label"))\r
+ {\r
+ // Parse '|' separated graduated colourscheme fields:\r
+ // [label|][mincolour|maxcolour|[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue]\r
+ // can either provide 'label' only, first is optional, next two\r
+ // colors are required (but may be\r
+ // left blank), next is optional, nxt two min/max are required.\r
+ // first is either 'label'\r
+ // first/second and third are both hexadecimal or word equivalent\r
+ // colour.\r
+ // next two are values parsed as floats.\r
+ // fifth is either 'above','below', or 'none'.\r
+ // sixth is a float value and only required when fifth is either\r
+ // 'above' or 'below'.\r
+ StringTokenizer gcol = new StringTokenizer(colscheme, "|",\r
+ true);\r
+ // set defaults\r
+ int threshtype = AnnotationColourGradient.NO_THRESHOLD;\r
+ float min = Float.MIN_VALUE, max = Float.MAX_VALUE, threshval = Float.NaN;\r
+ boolean labelCol = false;\r
+ // Parse spec line\r
+ String mincol = gcol.nextToken();\r
+ if (mincol == "|")\r
+ {\r
+ System.err\r
+ .println("Expected either 'label' or a colour specification in the line: "\r
+ + line);\r
+ continue;\r
+ }\r
+ String maxcol = null;\r
+ if (mincol.toLowerCase().indexOf("label") == 0)\r
+ {\r
+ labelCol = true;\r
+ mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); // skip\r
+ // '|'\r
+ mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);\r
+ }\r
+ String abso = null, minval, maxval;\r
+ if (mincol != null)\r
+ {\r
+ // at least four more tokens\r
+ if (mincol.equals("|"))\r
+ {\r
+ mincol = "";\r
+ }\r
+ else\r
+ {\r
+ gcol.nextToken(); // skip next '|'\r
+ }\r
+ // continue parsing rest of line\r
+ maxcol = gcol.nextToken();\r
+ if (maxcol.equals("|"))\r
+ {\r
+ maxcol = "";\r
+ }\r
+ else\r
+ {\r
+ gcol.nextToken(); // skip next '|'\r
+ }\r
+ abso = gcol.nextToken();\r
+ gcol.nextToken(); // skip next '|'\r
+ if (abso.toLowerCase().indexOf("abso") != 0)\r
+ {\r
+ minval = abso;\r
+ abso = null;\r
+ }\r
+ else\r
+ {\r
+ minval = gcol.nextToken();\r
+ gcol.nextToken(); // skip next '|'\r
+ }\r
+ maxval = gcol.nextToken();\r
+ if (gcol.hasMoreTokens())\r
+ {\r
+ gcol.nextToken(); // skip next '|'\r
+ }\r
+ try\r
+ {\r
+ if (minval.length() > 0)\r
+ {\r
+ min = new Float(minval).floatValue();\r
+ }\r
+ } catch (Exception e)\r
+ {\r
+ System.err\r
+ .println("Couldn't parse the minimum value for graduated colour for type ("\r
+ + colscheme\r
+ + ") - did you misspell 'auto' for the optional automatic colour switch ?");\r
+ e.printStackTrace();\r
+ }\r
+ try\r
+ {\r
+ if (maxval.length() > 0)\r
+ {\r
+ max = new Float(maxval).floatValue();\r
+ }\r
+ } catch (Exception e)\r
+ {\r
+ System.err\r
+ .println("Couldn't parse the maximum value for graduated colour for type ("\r
+ + colscheme + ")");\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // add in some dummy min/max colours for the label-only\r
+ // colourscheme.\r
+ mincol = "FFFFFF";\r
+ maxcol = "000000";\r
+ }\r
+ try\r
+ {\r
+ colour = new jalview.schemes.GraduatedColor(\r
+ new UserColourScheme(mincol).findColour('A'),\r
+ new UserColourScheme(maxcol).findColour('A'), min,\r
+ max);\r
+ } catch (Exception e)\r
+ {\r
+ System.err\r
+ .println("Couldn't parse the graduated colour scheme ("\r
+ + colscheme + ")");\r
+ e.printStackTrace();\r
+ }\r
+ if (colour != null)\r
+ {\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setColourByLabel(labelCol);\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setAutoScaled(abso == null);\r
+ // add in any additional parameters\r
+ String ttype = null, tval = null;\r
+ if (gcol.hasMoreTokens())\r
+ {\r
+ // threshold type and possibly a threshold value\r
+ ttype = gcol.nextToken();\r
+ if (ttype.toLowerCase().startsWith("below"))\r
+ {\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);\r
+ }\r
+ else if (ttype.toLowerCase().startsWith("above"))\r
+ {\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);\r
+ }\r
+ else\r
+ {\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setThreshType(AnnotationColourGradient.NO_THRESHOLD);\r
+ if (!ttype.toLowerCase().startsWith("no"))\r
+ {\r
+ System.err\r
+ .println("Ignoring unrecognised threshold type : "\r
+ + ttype);\r
+ }\r
+ }\r
+ }\r
+ if (((GraduatedColor) colour).getThreshType() != AnnotationColourGradient.NO_THRESHOLD)\r
+ {\r
+ try\r
+ {\r
+ gcol.nextToken();\r
+ tval = gcol.nextToken();\r
+ ((jalview.schemes.GraduatedColor) colour)\r
+ .setThresh(new Float(tval).floatValue());\r
+ } catch (Exception e)\r
+ {\r
+ System.err\r
+ .println("Couldn't parse threshold value as a float: ("\r
+ + tval + ")");\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ // parse the thresh-is-min token ?\r
+ if (gcol.hasMoreTokens())\r
+ {\r
+ System.err\r
+ .println("Ignoring additional tokens in parameters in graduated colour specification\n");\r
+ while (gcol.hasMoreTokens())\r
+ {\r
+ System.err.println("|" + gcol.nextToken());\r
+ }\r
+ System.err.println("\n");\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ UserColourScheme ucs = new UserColourScheme(colscheme);\r
+ colour = ucs.findColour('A');\r
+ }\r
+ if (colour != null)\r
+ {\r
+ colours.put(type, colour);\r
+ }\r