From: <ka...@us...> - 2010-07-04 14:35:47
|
Revision: 3362 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3362&view=rev Author: kappa1 Date: 2010-07-04 14:35:41 +0000 (Sun, 04 Jul 2010) Log Message: ----------- AppletLoader: Parameters boxbgcolor, boxfgcolor and boxerrorcolor have been added. Previous parameters al_bgcolor, al_fgcolor and al_errorcolor have been removed. Unlike the previous color support now you can specify the color as a string name of any AWT Color ("red", "blue", "yellow", etc), RGB format (0-255, e.g. "255,0,0") or html HEX color (must use leading #, previous didn't need to have the # e.g. "#FF0000"). This is to match the color support of boxbgcolor and boxfgcolor of the java plugin, so now the color is set and appears before the appletloader is even loaded. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2010-07-04 11:03:20 UTC (rev 3361) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2010-07-04 14:35:41 UTC (rev 3362) @@ -114,9 +114,9 @@ * <li>al_linux64 - [String] If specifed it will be used instead of al_linux on 64bit linux systems.</li> * <li>al_linux32 - [String] If specifed it will be used instead of al_linux on 32bit linux systems.</li> * <ul> - * <li>al_bgcolor - [String] Hex formated color to use as background. <i>Default: ffffff</i>.</li> - * <li>al_fgcolor - [String] Hex formated color to use as foreground. <i>Default: 000000</i>.</li> - * <li>al_errorcolor - [String] Hex formated color to use as foreground color on error. <i>Default: ff0000</i>.</li> + * <li>boxbgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as background. <i>Default: #ffffff</i>.</li> + * <li>boxfgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as foreground. <i>Default: #000000</i>.</li> + * <li>boxerrorcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as foreground color on error. <i>Default: #ff0000</i>.</li> * </ul> * </p> * @author kappaOne @@ -266,11 +266,11 @@ prependHost = getBooleanParameter("al_prepend_host", true); // get colors of applet - bgColor = getColor("al_bgcolor", Color.white); + bgColor = getColor("boxbgcolor", Color.white); setBackground(bgColor); - fgColor = getColor("al_fgcolor", Color.black); - errorColor = getColor("al_errorcolor", Color.red); + fgColor = getColor("boxfgcolor", Color.black); + errorColor = getColor("boxerrorcolor", Color.red); // load logos logo = getImage(getParameter("al_logo")); @@ -1318,12 +1318,39 @@ * @param defaultColor Default color to use if no color to load * @return Color to use */ - protected Color getColor(String color, Color defaultColor) { - String param_color = getParameter(color); - if (param_color != null) { - return new Color(Integer.parseInt(param_color, 16)); - } - return defaultColor; + protected Color getColor(String param, Color defaultColor) { + String color = getParameter(param); + + if (color == null) return defaultColor; + + // Check if RGB format + if (color.indexOf(",") != -1) { + StringTokenizer st = new StringTokenizer(color, ","); + + // We've got three components for the color + try { + return new Color(Integer.parseInt(st.nextToken().trim()), + Integer.parseInt(st.nextToken().trim()), + Integer.parseInt(st.nextToken().trim())); + } catch (Exception e) { + // failed to parse + return defaultColor; + } + } + + // Check & decode if the color is in hexadecimal color format (i.e. #808000) + try { + return Color.decode(color); + } catch (NumberFormatException e) { + // ignore exception + } + + // Get the color by name if it exists + try { + return (Color)Color.class.getField(color).get(null); + } catch (Exception e) { + return defaultColor; + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |