.append(attribute.getValue()).append("'"); if (bgColor != null && !bgColor.equals(Color.white))
@Test public void fromHSV() { assertThat(Color.fromHSV(0, 0, 0).toString(), is("#000000")); assertThat(Color.fromHSV(0, 1, 0).toString(), is("#000000")); assertThat(Color.fromHSV(0, -1, 0).toString(), is("#000000")); assertThat(Color.fromHSV(0, 0, 1).toString(), is("#FFFFFF")); assertThat(Color.fromHSV(0, 0, -1).toString(), is("#000000")); assertThat(Color.fromHSV(1, 1, 0).toString(), is("#000000")); assertThat(Color.fromHSV(1, 1, 0.2f).toString(), is("#330000")); assertThat(Color.fromHSV(1, 0.2f, 0.2f).toString(), is("#332929")); assertThat(Color.fromHSV(0.2f, 0.2f, 0.2f).toString(), is("#313329")); assertThat(Color.fromHSV(-0.2f, 0.2f, 0.2f).toString(), is("#312933")); assertThat(Color.fromHSV(0.2f, -0.2f, 0.2f).toString(), is("#35333D")); assertThat(Color.fromHSV(0.2f, 0.2f, -0.2f).toString(), is("#000000")); }
public void put(final String regExpPattern, final String htmlColor) { try { if (isBlank(regExpPattern)) { throw new IllegalArgumentException("No regular expression pattern provided"); } final Pattern pattern = Pattern.compile(regExpPattern, 0); final Color color = Color.fromHexTriplet(htmlColor); colorMap.put(pattern, color); } catch (final Exception e) { LOGGER.log(Level.CONFIG, new StringFormat("Could not add color mapping for %s = %s", regExpPattern, htmlColor), e); } }
@Test public void colors() { final Color color1 = Color.fromRGB(0, 0, 0); assertThat(color1.toString(), is("#000000")); final Color color2 = Color.fromRGB(0, 0, 255); assertThat(color2.toString(), is("#0000FF")); final Color color3 = Color.fromRGB(0, 9, 255); assertThat(color3.toString(), is("#0009FF")); final Color color4 = Color.fromRGB(12, 0, 1); assertThat(color4.toString(), is("#0C0001")); }
private static Color fromRGB(final float r, final float g, final float b) { return new Color((int) (r * 255 + 0.5), (int) (g * 255 + 0.5), (int) (b * 255 + 0.5)); }
@Test public void fromProperties() { final Properties properties = new Properties(); properties.put(test_color.toString().substring(1), "SC.*"); properties.put(test_color.toString().substring(1) + "A", "SC.*"); properties.put("000000", "QW.*"); final RegularExpressionColorMap colorMap = new RegularExpressionColorMap(properties); assertThat(colorMap.size(), is(2)); assertThat(colorMap.match("SCH"), is(not(emptyOptional()))); assertThat(colorMap.match("SCH").get().equals(test_color), is(true)); assertThat(colorMap.match("SHC"), emptyOptional()); assertThat(colorMap.match("QW"), is(not(emptyOptional()))); }
private Color generatePastelColor(final String text) { final float hue; if (isBlank(text)) { hue = 0.123456f; } else { final int hash = new StringBuilder(text).reverse().toString().hashCode(); hue = hash / 32771f % 1; } final float saturation = 0.15f; final float brightness = 0.95f; final Color color = Color.fromHSV(hue, saturation, brightness); return color; }
@Test public void fromHexTriplet() { assertThat(Color.fromHexTriplet("#010203").toString(), is("#010203")); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet(null)); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet("")); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet(" ")); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet("123456")); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet("#1234567")); assertThrows(IllegalArgumentException.class, () -> Color.fromHexTriplet("#12345")); }
@Test public void badColors() { final RegularExpressionColorMap colorMap = new RegularExpressionColorMap(); colorMap.put("SC.*", "1A3B5"); assertThat(colorMap.match("SCH"), emptyOptional()); colorMap.put("SC.*", test_color.toString().substring(1) + "A"); assertThat(colorMap.match("SCH"), emptyOptional()); colorMap.put("SC.*", test_color.toString().substring(1)); assertThat(colorMap.match("SCH"), emptyOptional()); }
private static Color fromRGB(final float r, final float g, final float b) { return new Color((int) (r * 255 + 0.5), (int) (g * 255 + 0.5), (int) (b * 255 + 0.5)); }
@Test public void happyPath() { final RegularExpressionColorMap colorMap = new RegularExpressionColorMap(); colorMap.put("SC.*", test_color.toString()); assertThat(colorMap.match("SCH"), is(not(emptyOptional()))); assertThat(colorMap.match("SCH").get().equals(test_color), is(true)); assertThat(colorMap.match("SC.*"), is(not(emptyOptional()))); assertThat(colorMap.match("SHC"), emptyOptional()); }
private Color generatePastelColor(final String text) { final float hue; if (isBlank(text)) { hue = 0.123456f; } else { final int hash = new StringBuilder(text).reverse().toString().hashCode(); hue = hash / 32771f % 1; } final float saturation = 0.15f; final float brightness = 0.95f; final Color color = Color.fromHSV(hue, saturation, brightness); return color; }
@Test public void badPatterns() { final RegularExpressionColorMap colorMap = new RegularExpressionColorMap(); colorMap.put("SC(H", test_color.toString()); assertThat(colorMap.match("SCH"), emptyOptional()); }
public static Color fromRGB(final int r, final int g, final int b) { return new Color(r, g, b); }
public void put(final String regExpPattern, final String htmlColor) { try { if (isBlank(regExpPattern)) { throw new IllegalArgumentException("No regular expression pattern provided"); } final Pattern pattern = Pattern.compile(regExpPattern, 0); final Color color = Color.fromHexTriplet(htmlColor); colorMap.put(pattern, color); } catch (final Exception e) { LOGGER.log(Level.CONFIG, new StringFormat("Could not add color mapping for %s = %s", regExpPattern, htmlColor), e); } }
private Color generatePastelColor(final String text) { final float hue; if (isBlank(text)) { hue = 0.123456f; } else { final int hash = new StringBuilder(text).reverse().toString().hashCode(); hue = hash / 32771f % 1; } final float saturation = 0.15f; final float brightness = 0.95f; final Color color = Color.fromHSV(hue, saturation, brightness); return color; }
.append(attribute.getValue()).append("'"); if (bgColor != null && !bgColor.equals(Color.white))