/*
* ColorValue.java v1.1 10/20/96
*
* Copyright (c) 1996-7 H.J. Tsai, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies.
*
* H.J. Tsai MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. H.J. Tsai SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*
* Author: H.J. Tsai hjtsai@cargobay.com
*
* Version 1.1 Oct 20 1996
* allow '#' before hex string
*
* Version 1.0 Sep 08 1996
* initial version
*/
import java.awt.Color;
public final class ColorValue {
public final static Color getShadowColor(Color c) {
return c.darker().darker().darker().darker();
}
public final static Color getHighLightColor(Color c) {
return c.brighter().brighter().brighter().brighter();
}
/**
* Converts a string representing a color into its Color value.
* If the string can not be converted, the supplied defaultColor is returned.
*
* Examples:
* Color c = ColorValue,s2color("113355", Color.red);
* Color c = ColorValue.s2color("#113355", Color.red);
* Color c = ColorValue.s2color("red", Color.red);
*
* @param s the string representing the color value
* @param defaultColor the default color if 's' is no good
* @returns the converted color
*/
public final static Color s2color(String s, Color defaultColor) {
try {
if (s.charAt(0) == '#')
return new Color(Integer.parseInt(s.substring(1), 16));
else
return new Color(Integer.parseInt(s, 16));
} catch (NumberFormatException e) {
if (s.equalsIgnoreCase("black")) {
return Color.black;
} else if (s.equalsIgnoreCase("blue")) {
return Color.blue;
} else if (s.equalsIgnoreCase("cyan")) {
return Color.cyan;
} else if (s.equalsIgnoreCase("darkGray")) {
return Color.darkGray;
} else if (s.equalsIgnoreCase("gray")) {
return Color.gray;
} else if (s.equalsIgnoreCase("green")) {
return Color.green;
} else if (s.equalsIgnoreCase("lightGray")) {
return Color.lightGray;
} else if (s.equalsIgnoreCase("magenta")) {
return Color.magenta;
} else if (s.equalsIgnoreCase("orange")) {
return Color.orange;
} else if (s.equalsIgnoreCase("pink")) {
return Color.pink;
} else if (s.equalsIgnoreCase("red")) {
return Color.red;
} else if (s.equalsIgnoreCase("white")) {
return Color.white;
} else if (s.equalsIgnoreCase("yellow")) {
return Color.yellow;
} else {
return defaultColor;
}
}
}
}