MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getColor

Method getColor

ij/src/main/java/ij/plugin/Colors.java:113–134  ·  view source on GitHub ↗

For named colors, converts the name String to the corresponding color. Returns 'defaultColor' if the color has no name. Use 'decode' to also decode hex color names like "#ffff00"

(String name, Color defaultColor)

Source from the content-addressed store, hash-verified

111 * Returns 'defaultColor' if the color has no name.
112 * Use 'decode' to also decode hex color names like "#ffff00" */
113 public static Color getColor(String name, Color defaultColor) {
114 if (name==null || name.length()<2)
115 return defaultColor;
116 name = name.toLowerCase(Locale.US);
117 Color c = defaultColor;
118 if (name.contains(colors[7])) c = Color.black;
119 else if (name.contains(colors[8])) c = Color.white;
120 else if (name.contains(colors[0])) c = Color.red;
121 else if (name.contains(colors[2])) c = Color.blue;
122 else if (name.contains(colors[5])) c = Color.yellow;
123 else if (name.contains(colors[1])) c = Color.green;
124 else if (name.contains(colors[3])) c = Color.magenta;
125 else if (name.contains(colors[4])) c = Color.cyan;
126 else if (name.contains(colors[6])) c = Color.orange;
127 else if (name.contains(colors[12])) c = Color.pink;
128 else if (name.contains(colors[9]) || name.contains("grey")) { //gray or grey
129 if (name.contains("light")) c = Color.lightGray;
130 else if (name.contains("dark")) c = Color.darkGray;
131 else c = Color.gray;
132 }
133 return c;
134 }
135
136 /** Converts a String with the color name or the hexadecimal representation
137 * of a color with 6 or 8 hex digits to a Color.

Callers 9

showStatusMethod · 0.95
showDialogMethod · 0.95
decodeMethod · 0.95
itemStateChangedMethod · 0.95
dialogItemChangedMethod · 0.95
dialogItemChangedMethod · 0.95
drawGridMethod · 0.95
setOptionsMethod · 0.95
dialogItemChangedMethod · 0.95

Calls 2

lengthMethod · 0.65
containsMethod · 0.45

Tested by

no test coverage detected