FileDocCategorySizeDatePackage
ColorImplicitObject.javaAPI DocGlassfish v2 API7687Fri May 04 22:34:24 BST 2007jsp2_1.examples.elresolver

ColorImplicitObject

public class ColorImplicitObject extends Object
Implicit object that ${Color} resolves to.
author
Mark Roth

Fields Summary
private static HashMap
colorNames
Set of colors by name
Constructors Summary
Methods Summary
static java.util.IteratorcolorNameIterator()
Package-scope method to get list of all color names

        if(colorNames == null) {
            loadColorNames();
        }
        return colorNames.keySet().iterator();
    
public static jsp2_1.examples.elresolver.ColorImplicitObject$ColorRGBfromColor(java.awt.Color color)
Returns a color from a java.awt.Color object.

        return new ColorRGB(color.getRed(), color.getGreen(), color.getBlue());
    
public static jsp2_1.examples.elresolver.ColorImplicitObject$ColorRGBfromHex(java.lang.String hex)
Returns a color from an HTML-style hex String, e.g. #f0f0f0

    
                   
         
        return fromColor(java.awt.Color.decode(hex));
    
public static jsp2_1.examples.elresolver.ColorImplicitObject$ColorRGBfromName(java.lang.String name)
Returns a color from a name. Uses the resource rgb.txt to load color names.

        if(colorNames == null) {
            loadColorNames();
        }
        return (ColorRGB)colorNames.get(name);
    
private static synchronized voidloadColorNames()
Loads colors from resource rgb.txt and converts them to instances of ColorRGB.

        if(colorNames == null) {
            colorNames = new HashMap();
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(
                    ColorImplicitObject.class.getResourceAsStream(
                    "/jsp2_1/examples/elresolver/rgb.txt")));
                String line;
                while((line = in.readLine()) != null) {
                    if(!line.startsWith("!")) {
                        String colorText = line.substring(0, 12);
                        String colorName = line.substring(12).trim();
                        StringTokenizer st = new StringTokenizer(
                            colorText, " ");
                        int red = Integer.parseInt(st.nextToken().trim());
                        int green = Integer.parseInt(st.nextToken().trim());
                        int blue = Integer.parseInt(st.nextToken().trim());
                        colorNames.put(colorName, new ColorRGB(red, green, 
                            blue));
                    }
                }
                in.close();
            }
            catch(IOException e) {
                throw new RuntimeException("Could not load rgb.txt", e);
            }
        }
    
public java.lang.StringtoString()

        return "Color Implicit Object";