Convert an integer to an HTML RGB value
/******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Actuate Corporation - initial API and implementation *******************************************************************************/ /** * Collection of string utilities. * */ public class StringUtil { /** * Convert an integer to an HTML RGB value. The result is of the form * #hhhhhh. The input rgb integer value will be clipped into the range 0 ~ * 0xFFFFFF * * @param rgb * the integer RGB value * @return the value as an HTML RGB string */ public static String toRgbText( int rgb ) { // clip input value. if ( rgb > 0xFFFFFF ) rgb = 0xFFFFFF; if ( rgb < 0 ) rgb = 0; String str = "000000" + Integer.toHexString( rgb ); //$NON-NLS-1$ return "#" + str.substring( str.length( ) - 6 ); //$NON-NLS-1$ } }