JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / util / ColorUtils.java
index 0d726a2..c2f54f7 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -59,29 +59,48 @@ public class ColorUtils
 
   }
 
-/**
-   * Returns a colour three shades darker. 
+  /**
+   * Convert to Tk colour code format
    * 
-   * We use darker text to indicate unselected buttons, lighter text for selected. Note you can't 
-   * guarantee that darkerThan/brighterThan undo each other, as they may result in black/white.
+   * @param colour
+   * @return
+   * @see http
+   *      ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/colortool.html#
+   *      tkcode
+   */
+  public static final String toTkCode(Color colour)
+  {
+    String colstring = "#" + ((colour.getRed() < 16) ? "0" : "")
+            + Integer.toHexString(colour.getRed())
+            + ((colour.getGreen() < 16) ? "0" : "")
+            + Integer.toHexString(colour.getGreen())
+            + ((colour.getBlue() < 16) ? "0" : "")
+            + Integer.toHexString(colour.getBlue());
+    return colstring;
+  }
+
+  /**
+   * Returns a colour three shades darker. Note you can't guarantee that
+   * brighterThan reverses this, as darkerThan may result in black.
    * 
    * @param col
    * @return
    */
-  public static Color darkerThan(Color col) {
-         return col.darker().darker().darker();
+  public static Color darkerThan(Color col)
+  {
+    return col == null ? null : col.darker().darker().darker();
   }
 
-/**
-   * Returns a colour three shades brighter. 
+  /**
+   * Returns a colour three shades brighter. Note you can't guarantee that
+   * darkerThan reverses this, as brighterThan may result in white.
    * 
-   * We use darker text to indicate unselected buttons, lighter text for selected. Note you can't 
-   * guarantee that darkerThan/brighterThan undo each other, as they may result in black/white.
    * @param col
    * @return
    */
-  public static Color brighterThan(Color col) {
-         return col.brighter().brighter().brighter();
+  public static Color brighterThan(Color col)
+  {
+    return col == null ? null : col.brighter().brighter().brighter();
   }
 
 }