X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fschemes%2FUserColourScheme.java;h=81947b3696e311cda68204dd2ebb63866ef62fe1;hb=1698842ec6755d1995dae7c1a590efbfc8f6e4d5;hp=9d61279ffdf679deb1643f7b6f2c9ad6b0aa8aa7;hpb=3d941a02a998676a12f8ff43fa98d9e1f4c27142;p=jalview.git diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 9d61279..81947b3 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,18 +18,19 @@ */ package jalview.schemes; +import java.util.*; + import java.awt.*; -import java.util.StringTokenizer; public class UserColourScheme extends ResidueColourScheme { - Color [] lowerCaseColours; + Color[] lowerCaseColours; protected String schemeName; public UserColourScheme() - { } + {} public UserColourScheme(Color[] newColors) { @@ -40,15 +41,17 @@ public class UserColourScheme { Color col = getColourFromString(colour); - if(col==null) + if (col == null) { - System.out.println("Unknown colour!! "+colour); + System.out.println("Unknown colour!! " + colour); col = createColourFromName(colour); } colors = new Color[24]; - for(int i=0; i<24; i++) + for (int i = 0; i < 24; i++) + { colors[i] = col; + } } public Color[] getColours() @@ -85,7 +88,9 @@ public class UserColourScheme {} if (col == null) + { col = ColourSchemeProperty.getAWTColorFromName(colour); + } if (col == null) { @@ -119,7 +124,9 @@ public class UserColourScheme start = end; end += lsize / 3; if (end > lsize) + { end = lsize; + } g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; @@ -134,8 +141,9 @@ public class UserColourScheme { StringTokenizer st = new StringTokenizer(paramValue, ";"); StringTokenizer st2; - String token=null, colour, residues; - try{ + String token = null, colour, residues; + try + { while (st.hasMoreElements()) { token = st.nextToken().trim(); @@ -147,72 +155,85 @@ public class UserColourScheme { token = st2.nextToken(); - if (ResidueProperties.aaIndex[token.charAt(0)]==-1) + if (ResidueProperties.aaIndex[token.charAt(0)] == -1) + { continue; + } int colIndex = ResidueProperties.aaIndex[token.charAt(0)]; - if(token.equalsIgnoreCase("lowerCase")) + if (token.equalsIgnoreCase("lowerCase")) { if (lowerCaseColours == null) + { lowerCaseColours = new Color[23]; + } for (int i = 0; i < 23; i++) + { if (lowerCaseColours[i] == null) + { lowerCaseColours[i] = getColourFromString(colour); + } + } - continue; + continue; } - if(token.equals(token.toLowerCase())) + if (token.equals(token.toLowerCase())) { - if(lowerCaseColours==null) + if (lowerCaseColours == null) { lowerCaseColours = new Color[23]; } lowerCaseColours[colIndex] = getColourFromString(colour); } else + { colors[colIndex] = getColourFromString(colour); + } } } } - catch(Exception ex) - { - System.out.println("Error parsing userDefinedColours:\n" - +token+"\n"+ex); - } + catch (Exception ex) + { + System.out.println("Error parsing userDefinedColours:\n" + + token + "\n" + ex); + } } - - - public Color findColour(String s, int j) + public Color findColour(char c, int j) { - Color currentColour; - int index = ResidueProperties.aaIndex[s.charAt(0)]; + Color currentColour; + int index = ResidueProperties.aaIndex[c]; - if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j)) + if ( (threshold == 0) || aboveThreshold(c, j)) + { + if (lowerCaseColours != null && 'a' <= c && c <= 'z') { - if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z') - currentColour = lowerCaseColours[index]; - else - currentColour = colors[index]; + currentColour = lowerCaseColours[index]; } else { - currentColour = Color.white; + currentColour = colors[index]; } + } + else + { + currentColour = Color.white; + } - if(conservationColouring) - applyConservation(currentColour, j); - + if (conservationColouring) + { + currentColour = applyConservation(currentColour, j); + } - return currentColour; - } + return currentColour; + } - public void setLowerCaseColours(Color [] lcolours) - { - lowerCaseColours = lcolours; - } + public void setLowerCaseColours(Color[] lcolours) + { + lowerCaseColours = lcolours; + } }