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