From: amwaterhouse Date: Wed, 25 May 2005 16:44:43 +0000 (+0000) Subject: getHexString added X-Git-Tag: Release_2_0~179 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fdfa02ece56124c3b72dad1963de2d79a3ad8584;p=jalview.git getHexString added --- diff --git a/src/jalview/util/Format.java b/src/jalview/util/Format.java index 4acf29e..dda9cde 100755 --- a/src/jalview/util/Format.java +++ b/src/jalview/util/Format.java @@ -4,18 +4,18 @@ * Copyright (C) 1997 Sun Microsystems Inc. * All Rights Reserved. * - * Permission to use, copy, modify, and distribute this + * Permission to use, copy, modify, and distribute this * software and its documentation for NON-COMMERCIAL purposes - * and without fee is hereby granted provided that this - * copyright notice appears in all copies. - * - * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR - * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * and without fee is hereby granted provided that this + * copyright notice appears in all copies. + * + * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR + * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS - * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED - * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED + * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */ @@ -66,6 +66,23 @@ public class Format { /** * @exception IllegalArgumentException if bad format */ + public static String getHexString(java.awt.Color color) + { + String r, g, b; + r = Integer.toHexString(color.getRed()); + if (r.length() < 2) + r = "0" + r; + g = Integer.toHexString(color.getGreen()); + if (g.length() < 2) + g = "0" + g; + b = Integer.toHexString(color.getBlue()); + if (b.length() < 2) + b = "0" + b; + + return r+g+b; + } + + public Format(String s) { width = 0; precision = -1; @@ -178,7 +195,7 @@ public class Format { /** * prints a formatted number following printf conventions * @param s a PrintStream * @param fmt the format string - * @param x the character to + * @param x the character to */ public static void print(java.io.PrintStream s, String fmt, char x) { @@ -301,7 +318,7 @@ public class Format { /** /** * Formats a double into a string (like sprintf in C) * @param x the number to format - * @return the formatted string + * @return the formatted string * @exception IllegalArgumentException if bad argument */ @@ -327,7 +344,7 @@ public class Format { /** /** * Formats a long integer into a string (like sprintf in C) * @param x the number to format - * @return the formatted string + * @return the formatted string */ public String form(long x) { @@ -356,7 +373,7 @@ public class Format { /** /** * Formats a character into a string (like sprintf in C) * @param x the value to format - * @return the formatted string + * @return the formatted string */ public String form(char c) { @@ -370,7 +387,7 @@ public class Format { /** /** * Formats a string into a larger string (like sprintf in C) * @param x the value to format - * @return the formatted string + * @return the formatted string */ public String form(String s) {