Java tutorial
/** * Utilities for GUI work. * @author Alex Kurzhanskiy * @version $Id: UtilGUI.java 38 2010-02-08 22:59:00Z akurzhan $ */ import java.awt.Color; public class Util { /** * Returns color based on 0-9 scale ranging from green to yellow. */ public static Color gyColor(int i) { int[][] rgb = { { 0, 164, 0 }, { 19, 174, 0 }, { 41, 184, 0 }, { 65, 194, 0 }, { 91, 204, 0 }, { 119, 215, 0 }, { 150, 225, 0 }, { 183, 235, 0 }, { 218, 245, 0 }, { 255, 255, 0 } }; int ii = 0; if (i > 9) ii = 9; else ii = Math.max(i, ii); float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null); return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } /** * Returns n-dimensional array of colors for given nx3 integer array of RGB values. */ public static Color[] getColorScale(int[][] rgb) { if (rgb == null) return null; Color[] clr = new Color[rgb.length]; for (int i = 0; i < rgb.length; i++) { float[] hsb = Color.RGBtoHSB(rgb[i][0], rgb[i][1], rgb[i][2], null); clr[i] = Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } return clr; } }