From: amwaterhouse Date: Wed, 14 Jun 2006 10:14:31 +0000 (+0000) Subject: parseAppletParameter X-Git-Tag: Release_2_1~355 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=94c3c55a91089b85b9e4eccf6ea0b82750d6f405 parseAppletParameter --- diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 5f377b3..0e03797 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -19,6 +19,7 @@ package jalview.schemes; import java.awt.*; +import java.util.StringTokenizer; public class UserColourScheme extends ResidueColourScheme @@ -26,29 +27,16 @@ public class UserColourScheme protected String schemeName; public UserColourScheme() - {} + { } - public UserColourScheme(String colour) + public UserColourScheme(Color[] newColors) { - Color col = null; - try{ - int value = Integer.parseInt(colour, 16); - col = new Color(value); - } - catch(NumberFormatException ex){} - - if(col==null) - col = ColourSchemeProperty.getAWTColorFromName(colour); + colors = newColors; + } - if(col==null) - {try{ - java.util.StringTokenizer st = new java.util.StringTokenizer(colour, ","); - int r = Integer.parseInt( st.nextToken() ); - int g = Integer.parseInt( st.nextToken() ); - int b = Integer.parseInt( st.nextToken() ); - col = new Color(r,g,b); - }catch(Exception ex){} - } + public UserColourScheme(String colour) + { + Color col = getColourFromString(colour); if(col==null) { @@ -61,11 +49,6 @@ public class UserColourScheme colors[i] = col; } - public UserColourScheme(Color[] newColors) - { - colors = newColors; - } - public Color[] getColours() { return colors; @@ -75,11 +58,47 @@ public class UserColourScheme { schemeName = name; } + public String getName() { return schemeName; } + public Color getColourFromString(String colour) + { + colour = colour.trim(); + + Color col = null; + try + { + int value = Integer.parseInt(colour, 16); + col = new Color(value); + } + catch (NumberFormatException ex) + {} + + if (col == null) + col = ColourSchemeProperty.getAWTColorFromName(colour); + + if (col == null) + { + try + { + java.util.StringTokenizer st = new java.util.StringTokenizer(colour, + ","); + int r = Integer.parseInt(st.nextToken()); + int g = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + col = new Color(r, g, b); + } + catch (Exception ex) + {} + } + + return col; + + } + public Color createColourFromName(String name) { int r, g, b; @@ -104,4 +123,35 @@ public class UserColourScheme return color; } + public void parseAppletParameter(String paramValue) + { + StringTokenizer st = new StringTokenizer(paramValue, ";"); + StringTokenizer st2; + String token=null, colour, residues; + try{ + while (st.hasMoreElements()) + { + token = st.nextToken().trim(); + residues = token.substring(0, token.indexOf("=")); + colour = token.substring(token.indexOf("=") + 1); + + st2 = new StringTokenizer(residues, " ,"); + while (st2.hasMoreTokens()) + { + int colIndex = + ( (Integer) ResidueProperties.aaHash. + get(st2.nextToken())).intValue(); + + colors[colIndex] = getColourFromString(colour); + } + } + } + catch(Exception ex) + { + System.out.println("Error parsing userDefinedColours:\n" + +token+"\n"+ex); + } + + } + }