From 3e9189ff4431911fb468e9accf38ea4202383b9a Mon Sep 17 00:00:00 2001 From: mkpaz Date: Fri, 10 Feb 2023 14:32:36 +0400 Subject: [PATCH] Checkstyle: fix method order [OverloadMethodsDeclarationOrder] --- .../java/atlantafx/sampler/FileResource.java | 8 +- .../atlantafx/sampler/theme/SamplerTheme.java | 50 ++-- .../java/atlantafx/sampler/util/JColor.java | 146 +++++------ .../atlantafx/sampler/util/JColorUtils.java | 248 +++++++++--------- 4 files changed, 226 insertions(+), 226 deletions(-) diff --git a/sampler/src/main/java/atlantafx/sampler/FileResource.java b/sampler/src/main/java/atlantafx/sampler/FileResource.java index 9a19fdb..69ec98e 100644 --- a/sampler/src/main/java/atlantafx/sampler/FileResource.java +++ b/sampler/src/main/java/atlantafx/sampler/FileResource.java @@ -61,15 +61,15 @@ public final class FileResource { /////////////////////////////////////////////////////////////////////////// - public static FileResource internal(String location) { - return internal(location, FileResource.class); + public static FileResource createInternal(String location) { + return createInternal(location, FileResource.class); } - public static FileResource internal(String location, Class anchor) { + public static FileResource createInternal(String location, Class anchor) { return new FileResource(location, true, Objects.requireNonNull(anchor)); } - public static FileResource external(String location) { + public static FileResource createExternal(String location) { return new FileResource(location, false, null); } } \ No newline at end of file diff --git a/sampler/src/main/java/atlantafx/sampler/theme/SamplerTheme.java b/sampler/src/main/java/atlantafx/sampler/theme/SamplerTheme.java index bcaacc8..0f1f696 100644 --- a/sampler/src/main/java/atlantafx/sampler/theme/SamplerTheme.java +++ b/sampler/src/main/java/atlantafx/sampler/theme/SamplerTheme.java @@ -109,6 +109,27 @@ public final class SamplerTheme implements Theme { return file.internal() ? parseColorsForClasspath(file) : parseColorsForFilesystem(file); } + private Map parseColors(BufferedReader br) throws IOException { + Map colors = new HashMap<>(); + + String line; + int lineCount = 0; + + while ((line = br.readLine()) != null) { + Matcher matcher = COLOR_PATTERN.matcher(line); + if (matcher.matches()) { + colors.put(matcher.group(1), matcher.group(3)); + } + + lineCount++; + if (lineCount > PARSE_LIMIT) { + break; + } + } + + return colors; + } + private Map parseColorsForClasspath(FileResource file) throws IOException { // classpath resources are static, no need to parse project theme more than once if (colors != null) { @@ -140,37 +161,16 @@ public final class SamplerTheme implements Theme { return colors; } - private Map parseColors(BufferedReader br) throws IOException { - Map colors = new HashMap<>(); - - String line; - int lineCount = 0; - - while ((line = br.readLine()) != null) { - Matcher matcher = COLOR_PATTERN.matcher(line); - if (matcher.matches()) { - colors.put(matcher.group(1), matcher.group(3)); - } - - lineCount++; - if (lineCount > PARSE_LIMIT) { - break; - } - } - - return colors; - } - public String getPath() { return getThemeFile().toPath().toString(); } private FileResource getThemeFile() { if (!isProjectTheme()) { - return FileResource.external(theme.getUserAgentStylesheet()); + return FileResource.createExternal(theme.getUserAgentStylesheet()); } - FileResource classpathTheme = FileResource.internal(theme.getUserAgentStylesheet(), Theme.class); + FileResource classpathTheme = FileResource.createInternal(theme.getUserAgentStylesheet(), Theme.class); if (!IS_DEV_MODE) { return classpathTheme; } @@ -178,7 +178,9 @@ public final class SamplerTheme implements Theme { String filename = classpathTheme.getFilename(); try { - FileResource testTheme = FileResource.internal(Resources.resolve("theme-test/" + filename), Launcher.class); + FileResource testTheme = FileResource.createInternal( + Resources.resolve("theme-test/" + filename), Launcher.class + ); if (!testTheme.exists()) { throw new IOException(); } diff --git a/sampler/src/main/java/atlantafx/sampler/util/JColor.java b/sampler/src/main/java/atlantafx/sampler/util/JColor.java index cdcb6d5..4e74212 100644 --- a/sampler/src/main/java/atlantafx/sampler/util/JColor.java +++ b/sampler/src/main/java/atlantafx/sampler/util/JColor.java @@ -547,6 +547,20 @@ public class JColor { setOpacity(opacity); } + /** + * Set the color as a single integer. + * + * @param color color integer + */ + public void setColor(int color) { + setRed(JColorUtils.getRed(color)); + setGreen(JColorUtils.getGreen(color)); + setBlue(JColorUtils.getBlue(color)); + if (color > 16777215 || color < 0) { + setAlpha(JColorUtils.getAlpha(color)); + } + } + /** * Set the color with HSL (hue, saturation, lightness) values. * @@ -576,20 +590,6 @@ public class JColor { setAlpha(alpha); } - /** - * Set the color as a single integer. - * - * @param color color integer - */ - public void setColor(int color) { - setRed(JColorUtils.getRed(color)); - setGreen(JColorUtils.getGreen(color)); - setBlue(JColorUtils.getBlue(color)); - if (color > 16777215 || color < 0) { - setAlpha(JColorUtils.getAlpha(color)); - } - } - /** * Set the red color in hex. * @@ -599,33 +599,6 @@ public class JColor { setRed(JColorUtils.toArithmeticRGB(red)); } - /** - * Set the green color in hex. - * - * @param green green hex color in format GG or G - */ - public void setGreen(String green) { - setGreen(JColorUtils.toArithmeticRGB(green)); - } - - /** - * Set the blue color in hex. - * - * @param blue blue hex color in format BB or B - */ - public void setBlue(String blue) { - setBlue(JColorUtils.toArithmeticRGB(blue)); - } - - /** - * Set the alpha color in hex. - * - * @param alpha alpha hex color in format AA or A - */ - public void setAlpha(String alpha) { - setOpacity(JColorUtils.toArithmeticRGB(alpha)); - } - /** * Set the red color as an integer. * @@ -635,33 +608,6 @@ public class JColor { setRed(JColorUtils.toHex(red)); } - /** - * Set the green color as an integer. - * - * @param green green integer color inclusively between 0 and 255 - */ - public void setGreen(int green) { - setGreen(JColorUtils.toHex(green)); - } - - /** - * Set the blue color as an integer. - * - * @param blue blue integer color inclusively between 0 and 255 - */ - public void setBlue(int blue) { - setBlue(JColorUtils.toHex(blue)); - } - - /** - * Set the alpha color as an integer. - * - * @param alpha alpha integer color inclusively between 0 and 255 - */ - public void setAlpha(int alpha) { - setOpacity(JColorUtils.toArithmeticRGB(alpha)); - } - /** * Set the red color as an arithmetic float. * @@ -672,6 +618,24 @@ public class JColor { this.red = red; } + /** + * Set the green color in hex. + * + * @param green green hex color in format GG or G + */ + public void setGreen(String green) { + setGreen(JColorUtils.toArithmeticRGB(green)); + } + + /** + * Set the green color as an integer. + * + * @param green green integer color inclusively between 0 and 255 + */ + public void setGreen(int green) { + setGreen(JColorUtils.toHex(green)); + } + /** * Set the green color as an arithmetic float. * @@ -682,6 +646,24 @@ public class JColor { this.green = green; } + /** + * Set the blue color in hex. + * + * @param blue blue hex color in format BB or B + */ + public void setBlue(String blue) { + setBlue(JColorUtils.toArithmeticRGB(blue)); + } + + /** + * Set the blue color as an integer. + * + * @param blue blue integer color inclusively between 0 and 255 + */ + public void setBlue(int blue) { + setBlue(JColorUtils.toHex(blue)); + } + /** * Set the blue color as an arithmetic float. * @@ -693,13 +675,21 @@ public class JColor { } /** - * Set the opacity as an arithmetic float. + * Set the alpha color in hex. * - * @param opacity opacity float color inclusively between 0.0 and 1.0 + * @param alpha alpha hex color in format AA or A */ - public void setOpacity(float opacity) { - JColorUtils.validateArithmeticRGB(opacity); - this.opacity = opacity; + public void setAlpha(String alpha) { + setOpacity(JColorUtils.toArithmeticRGB(alpha)); + } + + /** + * Set the alpha color as an integer. + * + * @param alpha alpha integer color inclusively between 0 and 255 + */ + public void setAlpha(int alpha) { + setOpacity(JColorUtils.toArithmeticRGB(alpha)); } /** @@ -711,6 +701,16 @@ public class JColor { setOpacity(alpha); } + /** + * Set the opacity as an arithmetic float. + * + * @param opacity opacity float color inclusively between 0.0 and 1.0 + */ + public void setOpacity(float opacity) { + JColorUtils.validateArithmeticRGB(opacity); + this.opacity = opacity; + } + /** * Check if the color is opaque (opacity or alpha of 1.0, 255, or x00) * diff --git a/sampler/src/main/java/atlantafx/sampler/util/JColorUtils.java b/sampler/src/main/java/atlantafx/sampler/util/JColorUtils.java index 84a9752..b20a83e 100644 --- a/sampler/src/main/java/atlantafx/sampler/util/JColorUtils.java +++ b/sampler/src/main/java/atlantafx/sampler/util/JColorUtils.java @@ -59,6 +59,18 @@ public class JColorUtils { return toColorWithAlpha(red, green, blue, null); } + /** + * Convert the RGB values to a color integer. + * + * @param red red integer color inclusively between 0 and 255 + * @param green green integer color inclusively between 0 and 255 + * @param blue blue integer color inclusively between 0 and 255 + * @return integer color + */ + public static int toColor(int red, int green, int blue) { + return toColorWithAlpha(red, green, blue, -1); + } + /** * Convert the hex color values to a hex color, shorthanded when possible. * @@ -91,20 +103,6 @@ public class JColorUtils { return toColorWithAlpha(red, green, blue, defaultAlpha); } - /** - * Convert the hex color values to a hex color including an opaque alpha - * value of FF or F, shorthanded when possible. - * - * @param red red hex color in format RR or R - * @param green green hex color in format GG or G - * @param blue blue hex color in format BB or B - * @return hex color in format #ARGB or #AARRGGBB - */ - public static String toColorShorthandWithAlpha(String red, String green, - String blue) { - return shorthandHex(toColorWithAlpha(red, green, blue)); - } - /** * Convert the hex color values to a hex color. * @@ -131,32 +129,6 @@ public class JColorUtils { return color.toString(); } - /** - * Convert the hex color values to a hex color, shorthanded when possible. - * - * @param red red hex color in format RR or R - * @param green green hex color in format GG or G - * @param blue blue hex color in format BB or B - * @param alpha alpha hex color in format AA or A, null to not include alpha - * @return hex color in format #ARGB, #RGB, #AARRGGBB, or #RRGGBB - */ - public static String toColorShorthandWithAlpha(String red, String green, - String blue, String alpha) { - return shorthandHex(toColorWithAlpha(red, green, blue, alpha)); - } - - /** - * Convert the RGB values to a color integer. - * - * @param red red integer color inclusively between 0 and 255 - * @param green green integer color inclusively between 0 and 255 - * @param blue blue integer color inclusively between 0 and 255 - * @return integer color - */ - public static int toColor(int red, int green, int blue) { - return toColorWithAlpha(red, green, blue, -1); - } - /** * Convert the RGB values to a color integer including an opaque alpha value * of 255. @@ -193,6 +165,34 @@ public class JColorUtils { return color; } + /** + * Convert the hex color values to a hex color including an opaque alpha + * value of FF or F, shorthanded when possible. + * + * @param red red hex color in format RR or R + * @param green green hex color in format GG or G + * @param blue blue hex color in format BB or B + * @return hex color in format #ARGB or #AARRGGBB + */ + public static String toColorShorthandWithAlpha(String red, String green, + String blue) { + return shorthandHex(toColorWithAlpha(red, green, blue)); + } + + /** + * Convert the hex color values to a hex color, shorthanded when possible. + * + * @param red red hex color in format RR or R + * @param green green hex color in format GG or G + * @param blue blue hex color in format BB or B + * @param alpha alpha hex color in format AA or A, null to not include alpha + * @return hex color in format #ARGB, #RGB, #AARRGGBB, or #RRGGBB + */ + public static String toColorShorthandWithAlpha(String red, String green, + String blue, String alpha) { + return shorthandHex(toColorWithAlpha(red, green, blue, alpha)); + } + /** * Convert the RGB integer to a hex single color. * @@ -243,6 +243,19 @@ public class JColorUtils { return Math.round(255 * color); } + /** + * Convert HSL (hue, saturation, and lightness) values to RGB integer values. + * + * @param hue hue value inclusively between 0.0 and 360.0 + * @param saturation saturation inclusively between 0.0 and 1.0 + * @param lightness lightness inclusively between 0.0 and 1.0 + * @return RGB integer array where: 0 = red, 1 = green, 2 = blue + */ + public static int[] toRGB(float hue, float saturation, float lightness) { + float[] arithmeticRGB = toArithmeticRGB(hue, saturation, lightness); + return new int[] {toRGB(arithmeticRGB[0]), toRGB(arithmeticRGB[1]), toRGB(arithmeticRGB[2])}; + } + /** * Convert the hex single color to an arithmetic RGB float. * @@ -264,6 +277,36 @@ public class JColorUtils { return color / 255.0f; } + /** + * Convert HSL (hue, saturation, and lightness) values to RGB arithmetic + * values. + * + * @param hue hue value inclusively between 0.0 and 360.0 + * @param saturation saturation inclusively between 0.0 and 1.0 + * @param lightness lightness inclusively between 0.0 and 1.0 + * @return arithmetic RGB array where: 0 = red, 1 = green, 2 = blue + */ + public static float[] toArithmeticRGB(float hue, float saturation, float lightness) { + validateHue(hue); + validateSaturation(saturation); + validateLightness(lightness); + + hue /= 60.0f; + float t2; + if (lightness <= 0.5f) { + t2 = lightness * (saturation + 1); + } else { + t2 = lightness + saturation - (lightness * saturation); + } + float t1 = lightness * 2.0f - t2; + + float red = hslConvert(t1, t2, hue + 2); + float green = hslConvert(t1, t2, hue); + float blue = hslConvert(t1, t2, hue - 2); + + return new float[] {red, green, blue}; + } + /** * Convert red, green, and blue arithmetic values to HSL (hue, saturation, * lightness) values. @@ -332,51 +375,6 @@ public class JColorUtils { toArithmeticRGB(blue)); } - /** - * Convert HSL (hue, saturation, and lightness) values to RGB arithmetic - * values. - * - * @param hue hue value inclusively between 0.0 and 360.0 - * @param saturation saturation inclusively between 0.0 and 1.0 - * @param lightness lightness inclusively between 0.0 and 1.0 - * @return arithmetic RGB array where: 0 = red, 1 = green, 2 = blue - */ - public static float[] toArithmeticRGB(float hue, float saturation, - float lightness) { - - validateHue(hue); - validateSaturation(saturation); - validateLightness(lightness); - - hue /= 60.0f; - float t2; - if (lightness <= 0.5f) { - t2 = lightness * (saturation + 1); - } else { - t2 = lightness + saturation - (lightness * saturation); - } - float t1 = lightness * 2.0f - t2; - - float red = hslConvert(t1, t2, hue + 2); - float green = hslConvert(t1, t2, hue); - float blue = hslConvert(t1, t2, hue - 2); - - return new float[] {red, green, blue}; - } - - /** - * Convert HSL (hue, saturation, and lightness) values to RGB integer values. - * - * @param hue hue value inclusively between 0.0 and 360.0 - * @param saturation saturation inclusively between 0.0 and 1.0 - * @param lightness lightness inclusively between 0.0 and 1.0 - * @return RGB integer array where: 0 = red, 1 = green, 2 = blue - */ - public static int[] toRGB(float hue, float saturation, float lightness) { - float[] arithmeticRGB = toArithmeticRGB(hue, saturation, lightness); - return new int[] {toRGB(arithmeticRGB[0]), toRGB(arithmeticRGB[1]), toRGB(arithmeticRGB[2])}; - } - /** * HSL convert helper method. * @@ -415,6 +413,16 @@ public class JColorUtils { return getHexSingle(hex, 0); } + /** + * Get the red color from color integer. + * + * @param color color integer + * @return red color + */ + public static int getRed(int color) { + return (color >> 16) & 0xff; + } + /** * Get the hex green color from the hex string. * @@ -425,6 +433,16 @@ public class JColorUtils { return getHexSingle(hex, 1); } + /** + * Get the green color from color integer. + * + * @param color color integer + * @return green color + */ + public static int getGreen(int color) { + return (color >> 8) & 0xff; + } + /** * Get the hex blue color from the hex string. * @@ -435,6 +453,16 @@ public class JColorUtils { return getHexSingle(hex, 2); } + /** + * Get the blue color from color integer. + * + * @param color color integer + * @return blue color + */ + public static int getBlue(int color) { + return color & 0xff; + } + /** * Get the hex alpha color from the hex string if it exists. * @@ -445,6 +473,16 @@ public class JColorUtils { return getHexSingle(hex, -1); } + /** + * Get the alpha color from color integer. + * + * @param color color integer + * @return alpha color + */ + public static int getAlpha(int color) { + return (color >> 24) & 0xff; + } + /** * Get the hex single color. * @@ -482,46 +520,6 @@ public class JColorUtils { return color; } - /** - * Get the red color from color integer. - * - * @param color color integer - * @return red color - */ - public static int getRed(int color) { - return (color >> 16) & 0xff; - } - - /** - * Get the green color from color integer. - * - * @param color color integer - * @return green color - */ - public static int getGreen(int color) { - return (color >> 8) & 0xff; - } - - /** - * Get the blue color from color integer. - * - * @param color color integer - * @return blue color - */ - public static int getBlue(int color) { - return color & 0xff; - } - - /** - * Get the alpha color from color integer. - * - * @param color color integer - * @return alpha color - */ - public static int getAlpha(int color) { - return (color >> 24) & 0xff; - } - /** * Shorthand the hex color if possible. *