/* * @(#)TextAreaFigure.java * * Project: JHotdraw - a GUI framework for technical drawings * http://www.jhotdraw.org * http://jhotdraw.sourceforge.net * Copyright: © by the original author(s) and all contributors * License: Lesser GNU Public License (LGPL) * http://www.opensource.org/licenses/lgpl-license.html */ package CH.ifa.draw.contrib.html; import java.awt.Color; import java.io.Serializable; /** * HTMLColorContentProducer produces RGB color HTML encoded strings.
* Ex: * Color.blue ==> #0000FF
* Color.red ==> #FF00FF
* It can either be specific if set for a specific color, or generic, encoding * any color passed to the getContents method. * * @author Eduardo Francos - InContext * @created 4 mai 2002 * @version 1.0 */ public class HTMLColorContentProducer extends ColorContentProducer implements Serializable { /**Constructor for the HTMLColorContentProducer object */ public HTMLColorContentProducer() { } /** * Produces the contents for the color * * @param context the calling client context * @param ctxAttrName the color attribute name (FrameColor, TextColor, etc) * @param ctxAttrValue the color * @return The HTML encoded RBG value for the color */ public Object getContent(ContentProducerContext context, String ctxAttrName, Object ctxAttrValue) { // if we have our own color then use it // otherwise use the one supplied Color color = (getColor() != null) ? getColor() : (Color)ctxAttrValue; return getHTMLColorCode(color); } public static String getHTMLColorCode(Color color) { String colorCode = Integer.toHexString(color.getRGB()); return "#" + colorCode.substring(colorCode.length() - 6); } }