AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
addColor (String name, Color value) yoix.swing
addColor (String name, String value)  
addColor (String name, Number red, Number green, Number blue)  
addColor (Dictionary colors)  
addColor ()  
 
Depending on the form used, this built-in adds a name / color pair or a Dictionary of name / color pairs to the yoix.swing.Color dictionary. It returns 1 if the operation succeeded and 0 if it failed, which usually means name has already been defined or all names in the dictionary are already defined. Note that yoix.swing.Color is automatically initialized with the colors in Java's java.awt.Color package. Colors are stored both under the supplied name and also a canonical name derived from the supplied name. A canonical name is formed by taking the supplied name, converting it to lower case and removing all non-alphanumeric characters. If no characters remain, the generic name, color, is used. If the resulting canonical name collides with an already installed name for a different color, a sequentially generated three digit suffix, starting with 000, is appended to assure a unique canonical name for each color in the dictionary. If more than one thousand different colors are asked to be stored using names that in all cases distill to the same base canonical form, then this utter lack of imagination generates a badvalue error. The canonical name for a loaded color can be retrieved by using the getColorName built-in.

When the supplied argument or dictionary value is a Color, it is simply added to yoix.swing.Color. When the supplied argument or dictionary value is a String, it is treated as an octal or hexadecimal string representation of the three RGB values (e.g., "#ff00ff" for all red, no green and all blue) and the corresponding color is added to yoix.swing.Color. It is also possible to supply arguments that are the three numbers representing the RGB components of the color that is being added to yoix.swing.Color. A color component that is a double should be a number between 0.0 and 1.0, while a color component that is an int should be a number between 0 and 255.

As a convenience, calling addColor with no arguments, namely as simply addColor(), is equivalent to the call: addColor(yoix.xcolor). Namely, the colors in the yoix.xcolor dictionary are loaded into the yoix.swing.Color dictionary, which also makes the names available to the getColorName built-in.
 
 Example:   The program,
import yoix.*.*;

Color salmon = {
    double red   = 1.0;
    double green = 0.73;
    double blue  = 0.73;
};

addColor("periwinkle", 0.86, 0.86, 1.0);
addColor("salmon", salmon);
addColor("lime", "#baffba");

JFrame f = {
    Dimension size = null;
    Color     background = Color.lightGray;

    FlowLayout layoutmanager = {
        int hgap = 18;
        int vgap = 18;
    };

    Array layout = {
        new JButton {
            Color  background = Color.periwinkle;
            String text = "periwinkle";
        },
        new JButton {
            Color  background = Color.salmon;
            String text = "salmon";
        },
        new JButton {
            Color  background = Color.lime;
            String text = "lime";
        },
    };
};

f.visible = TRUE;
Adds three colors to the Color dictionary and uses them as backgrounds for buttons in a frame.
 
 Return:   int
 
 See Also:   Color, getBrighterColor, getCMYKColor, getColorName, getDarkerColor, getHSBColor, getHSBComponents, getRGBColor, getSaturationAdjustedColor

 

Yoix is a registered trademark of AT&T Inc.