X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FColorUtils.java;h=b8cd563ddd0d3bccd3f919bbd73c648b92a97617;hb=18425bf4b285d3d8aeefd8ddbe77b1d6fd434f60;hp=0d726a2470613aa1bb6da09fde79fea6ac4def17;hpb=b369b306448bbec72f29b33ebe2f654589845103;p=jalview.git diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 0d726a2..b8cd563 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -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-Rel$$) + * Copyright (C) $$Year-Rel$$ 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(); } }