X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FUserColourScheme.java;h=1865518d45ce34ba1892e14c30e7b26e3c744e2e;hb=b0cee3aaf7d8873910939f97b6acb217d518968d;hp=4bb54f9c93746a591ce6ff480dac1d831a8e0d89;hpb=9d15a20b1f34c76427da5ec9274ff97a1ca49393;p=jalview.git diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 4bb54f9..1865518 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -23,6 +23,7 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.ColorUtils; import java.awt.Color; import java.util.Map; @@ -63,12 +64,12 @@ public class UserColourScheme extends ResidueColourScheme public UserColourScheme(String colour) { super(ResidueProperties.aaIndex); - Color col = getColourFromString(colour); + Color col = ColorUtils.parseColourString(colour); if (col == null) { System.out.println("Making colour from name: " + colour); - col = createColourFromName(colour); + col = ColorUtils.createColourFromName(colour); } colors = new Color[24]; @@ -100,86 +101,6 @@ public class UserColourScheme extends ResidueColourScheme } /** - * Parses a string into a Color, where the accepted formats are - * - * - * @param colour - * @return the parsed colour, or null if parsing fails - */ - public static Color getColourFromString(String colour) - { - if (colour == null) - { - return null; - } - 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 - { - String[] tokens = colour.split(","); - if (tokens.length == 3) - { - int r = Integer.parseInt(tokens[0].trim()); - int g = Integer.parseInt(tokens[1].trim()); - int b = Integer.parseInt(tokens[2].trim()); - col = new Color(r, g, b); - } - } catch (Exception ex) - { - // non-numeric token or out of 0-255 range - } - } - - return col; - } - - public static Color createColourFromName(String name) - { - int r, g, b; - - int lsize = name.length(); - int start = 0, end = lsize / 3; - - int rgbOffset = Math.abs(name.hashCode() % 10) * 15; - - r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; - start = end; - end += lsize / 3; - if (end > lsize) - { - end = lsize; - } - - g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20; - - b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20; - - Color color = new Color(r, g, b); - - return color; - } - - /** * Parse and save residue colours specified as (for example) * *
@@ -230,7 +151,7 @@ public class UserColourScheme extends ResidueColourScheme
             {
               if (lowerCaseColours[i] == null)
               {
-                lowerCaseColours[i] = getColourFromString(colour);
+                lowerCaseColours[i] = ColorUtils.parseColourString(colour);
               }
             }
 
@@ -243,11 +164,11 @@ public class UserColourScheme extends ResidueColourScheme
             {
               lowerCaseColours = new Color[23];
             }
-            lowerCaseColours[colIndex] = getColourFromString(colour);
+            lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
           }
           else
           {
-            colors[colIndex] = getColourFromString(colour);
+            colors[colIndex] = ColorUtils.parseColourString(colour);
           }
         }
       }
@@ -313,4 +234,18 @@ public class UserColourScheme extends ResidueColourScheme
     return super.findColour(c);
   }
 
+  /**
+   * Answers the customised name of the colour scheme, if it has one, else
+   * "User Defined"
+   */
+  @Override
+  public String getSchemeName()
+  {
+    if (schemeName != null && schemeName.length() > 0)
+    {
+      return schemeName;
+    }
+    return JalviewColourScheme.UserDefined.toString();
+  }
+
 }