Skip to content
Snippets Groups Projects
Commit 6ccf2fdf authored by Piotr Gawron's avatar Piotr Gawron
Browse files

parsing of colors without hash didn't work

parent 4deed6ce
No related branches found
No related tags found
1 merge request!1009Resolve "when processing color codes allow colors with alpha"
Pipeline #16540 failed
package lcsb.mapviewer.common.geometry;
import java.awt.*;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
......@@ -57,6 +57,9 @@ public class ColorParser {
"Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
}
if (string.charAt(0) != '#') {
string = "#" + string;
}
if (string.length() == COLOR_STRING_LENGTH_WITHOUT_ALPHA) {
return parseColorWithoutAlpha(string);
} else {
......@@ -100,14 +103,14 @@ public class ColorParser {
public Color parseColorWithAlpha(String string) {
if (string == null || string.isEmpty()) {
throw new InvalidArgumentException(
"Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
"Invalid color value: " + string + ". Correct format: #xxxxxxxx (where x is a hex value)");
}
if (string.charAt(0) != '#') {
string = "#" + string;
}
if (string.length() != COLOR_STRING_LENGTH_WITH_ALPHA) {
throw new InvalidArgumentException(
"Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
"Invalid color value: " + string + ". Correct format: #xxxxxxxx (where x is a hex value)");
} else {
return new Color(
Integer.valueOf(string.substring(COLOR_SUBSTRING_START_RED, COLOR_SUBSTRING_START_GREEN), HEX_BASE),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment