### List Color Names Library

This is an open source B4J Library with additional Color subroutines.
The library is writting in Java 8.
Library Subroutines
• Get the list of standard color values
• Get the list of standard color names
• Get the standard colors a list of maps name and value
• Get all color names and values as a map
Library Source
package com.rwblinn.jRLColor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
//import java.awt.Color;
import javafx.scene.paint.Color;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.collections.Map;
@BA.DesignerName("Build 20140830")
@BA.Version(1.0F)
@BA.Author("Robert Linn")
@BA.ShortName("RLColor")
public class RLColor {
private static final double version = 1.0D;
/**
* Get list of Colors
* @param None
* @return Array of Colors which can be assigned to a B4A/J List
*/
public static Color[] getColorList() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
List colors = new ArrayList<>();
@SuppressWarnings("rawtypes")
Class clcolor = Class.forName("javafx.scene.paint.Color");
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
// Get Hex
Object obj = f.get(null);
if(obj instanceof Color){
colors.add((Color) obj);
}
}
}
Color [] colorlist = colors.toArray(new Color[colors.size()]);
return colorlist;
}
/**
* Get list of Color Names
* @param None
* @return Array of Color Names which can be assigned to a B4A/J List
*/
public static String[] getColorNames() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
List colors = new ArrayList<>();
@SuppressWarnings("rawtypes")
Class clcolor = Class.forName("javafx.scene.paint.Color");
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
// Get Name
Object objn = f.get(null);
if(objn instanceof Color){
final String colorName = f.getName();
colors.add(colorName);
}
}
}
String[] colorlist = colors.toArray(new String[colors.size()]);
return colorlist;
}
/**
* getColorMapAsList
* Use in B4A/J:
* Dim l As List = cl.ColorMapAsList
* For i = 0 To l.Size - 1
* Dim m As Map = l.Get(i)
* Log(m.Get("Name") & " = " & m.Get("Value"))
* Next
* @param None
* @return List of (B4A object MyMap) Color Names which can be assigned to a B4A/J List
*/
public static List getColorMapAsList() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
List colors = new ArrayList();
Class clcolor = Class.forName("javafx.scene.paint.Color");
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
Object objn = f.get(null);
if(objn instanceof Color){
Color c = (Color) objn;
Map m = new Map();
m.Initialize();
m.Put("Name", f.getName());
m.Put("Value", c.toString());
colors.add(m.getObject());
}
}
}
return colors;
}
/**
* getColorMap
* Use in B4A/J:
* Dim m As Map = cl.ColorMap
* For i = 0 To m.Size - 1
* Log(m.GetKeyAt(i) & " = " & m.GetValueAt(i))
* Next
* @param None
* @return Map (B4A object MyMap) of Colors Name = Value
*/
public static Map.MyMap getColorMap() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
Class clcolor = Class.forName("javafx.scene.paint.Color");
Map.MyMap colormap = new Map.MyMap();
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
Object objn = f.get(null);
if(objn instanceof Color){
Color c = (Color) objn;
Map m = new Map();
m.Initialize();
m.Put(f.getName(), c.toString());
colormap.putAll(m.getObject());
}
}
}
return colormap;
}
/**
* getVersion
* @return Version
*/
public double getVersion()
{
return version;
}
}

Changed: , Category: Colors, File: T6C174M1259.htm, ID: 1259