Depending on the form used, this built-in
adds a name / color pair or a
Dictionary
of name / color pairs to the
yoix.awt.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.awt.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.awt.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.awt.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.awt.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.awt.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");
Frame f = {
Dimension size = null;
Color background = Color.lightGray;
FlowLayout layoutmanager = {
int hgap = 18;
int vgap = 18;
};
Array layout = {
new Button {
Color background = Color.periwinkle;
String text = "periwinkle";
},
new Button {
Color background = Color.salmon;
String text = "salmon";
},
new Button {
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
|
|