if (!hasAlpha) alpha = 255;
	private void setColor(ContextStack context, Argument []args, int nArgs)		throws MapyrusException	{		int alpha = 0;		float decimalAlpha = 0.0f;		boolean hasAlpha = false;		if (nArgs == 1 || nArgs == 2)		{			String color = args[0].getStringValue();			Color c;			if (nArgs == 2)			{				/*				 * Parse transparency value.				 */				decimalAlpha = (float)args[1].getNumericValue();				if (decimalAlpha < 0.0f)					decimalAlpha = 0.0f;				else if (decimalAlpha > 1.0f)					decimalAlpha = 1.0f;				alpha = (int)Math.round(decimalAlpha * 255.0);				hasAlpha = true;			}			if (color.startsWith("#") || color.startsWith("0x"))			{				int startIndex = (color.charAt(0) == '#') ? 1 : 2;				/*				 * Parse color from a 6 digit hex value like '#ff0000',				 * as used in HTML pages.				 */				try				{					int rgb = Integer.parseInt(color.substring(startIndex), 16);					rgb = (rgb & 0xffffff);					c = new Color(rgb | (alpha << 24), hasAlpha);				}				catch (NumberFormatException e)				{					throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_COLOR) + ": " + color);				}			}			else			{				if (color.equals("contrast"))				{					context.contrastColor(alpha);					return;				}				/*				 * Find named color in color name database.				 */				c = ColorDatabase.getColor(color);				if (c == null)				{					throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.COLOR_NOT_FOUND) +						": " + color);				}				/*				 * Add transparency value to color, if given.				 */				if (hasAlpha)				{					c = new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);				}			}			context.setColor(c);		}		else if (nArgs == 4 || nArgs == 5)		{			String colorType = args[0].getStringValue();			float c1 = (float)args[1].getNumericValue();			float c2 = (float)args[2].getNumericValue();			float c3 = (float)args[3].getNumericValue();			if (nArgs == 5)			{				/*				 * Parse transparency value.				 */				decimalAlpha = (float)args[4].getNumericValue();				if (decimalAlpha < 0.0f)					decimalAlpha = 0.0f;				else if (decimalAlpha > 1.0f)					decimalAlpha = 1.0f;				alpha = (int)Math.round(decimalAlpha * 255.0);				hasAlpha = true;			}			/*			 * Constrain color to valid range.			 */			if (c2 < 0.0f)				c2 = 0.0f;			else if (c2 > 1.0f)				c2 = 1.0f;			if (c3 < 0.0f)				c3 = 0.0f;			else if (c3 > 1.0f)				c3 = 1.0f;			if (colorType.equalsIgnoreCase("hsb"))			{				/*				 * Set HSB color.				 */				int rgb = Color.HSBtoRGB(c1, c2, c3);				context.setColor(new Color(rgb | (alpha << 24), hasAlpha));			}			else if (colorType.equalsIgnoreCase("rgb"))			{				if (c1 < 0.0f)					c1 = 0.0f;				else if (c1 > 1.0f)					c1 = 1.0f;				/*				 * Set RGB color.				 */				if (hasAlpha)					context.setColor(new Color(c1, c2, c3, decimalAlpha));				else					context.setColor(new Color(c1, c2, c3));			}			else			{				throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_COLOR_TYPE) +					": " + colorType);			}		}		else		{			throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.INVALID_COLOR));		}	}