Code cleanup (#50)

Minor code refactoring and formatting.
This commit is contained in:
CodeDead 2023-05-01 19:49:32 +02:00 committed by GitHub
parent a949420f6a
commit 7ebfa7ac0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 47 deletions

@ -9,7 +9,7 @@ AtlantaFX is based on GitHub Primer color system. You can check [GitHub Primer i
### Foreground Colors ### Foreground Colors
| Color | Usage | | Color | Usage |
|----------------------|--------------------------------| |----------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `-color-fg-default` | Primary color for text and icons. It should be used for body content, titles and labels. | | `-color-fg-default` | Primary color for text and icons. It should be used for body content, titles and labels. |
| `-color-fg-muted` | For content that is secondary or that provides additional context but is not critical to understanding the flow of an interface. | | `-color-fg-muted` | For content that is secondary or that provides additional context but is not critical to understanding the flow of an interface. |
| `-color-fg-subtle` | For placeholders or decorative foregrounds. | | `-color-fg-subtle` | For placeholders or decorative foregrounds. |

@ -14,6 +14,8 @@ import atlantafx.sampler.page.SampleBlock;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -127,9 +129,10 @@ public class CustomTextFieldPage extends AbstractPage {
timeField.textProperty().addListener((obs, old, val) -> { timeField.textProperty().addListener((obs, old, val) -> {
if (val != null) { if (val != null) {
try { try {
//noinspection ResultOfMethodCallIgnored
LocalTime.parse(val, timeFormatter); LocalTime.parse(val, timeFormatter);
timeField.pseudoClassStateChanged(STATE_DANGER, false); timeField.pseudoClassStateChanged(STATE_DANGER, false);
} catch (Exception e) { } catch (DateTimeParseException e) {
timeField.pseudoClassStateChanged(STATE_DANGER, true); timeField.pseudoClassStateChanged(STATE_DANGER, true);
} }
} }

@ -24,22 +24,28 @@ import java.util.List;
@SuppressWarnings({"unused", "NarrowingCompoundAssignment"}) @SuppressWarnings({"unused", "NarrowingCompoundAssignment"})
final class ColorThief { final class ColorThief {
private ColorThief() {
// Default constructor
}
private static final int DEFAULT_QUALITY = 10; private static final int DEFAULT_QUALITY = 10;
private static final boolean DEFAULT_IGNORE_WHITE = true; private static final boolean DEFAULT_IGNORE_WHITE = true;
public static int[] getColor(BufferedImage source) { public static int[] getColor(BufferedImage source) {
int[][] palette = getPalette(source, 5); int[][] palette = getPalette(source, 5);
if (palette == null) {
if (palette == null)
return null; return null;
}
return palette[0]; return palette[0];
} }
public static int[][] getPalette(BufferedImage source, int colorCount) { public static int[][] getPalette(BufferedImage source, int colorCount) {
MMCQ.ColorMap colorMap = getColorMap(source, colorCount); MMCQ.ColorMap colorMap = getColorMap(source, colorCount);
if (colorMap == null) {
if (colorMap == null)
return null; return null;
}
return colorMap.palette(); return colorMap.palette();
} }
@ -49,12 +55,10 @@ final class ColorThief {
public static MMCQ.ColorMap getColorMap(BufferedImage sourceImage, int colorCount, int quality, public static MMCQ.ColorMap getColorMap(BufferedImage sourceImage, int colorCount, int quality,
boolean ignoreWhite) { boolean ignoreWhite) {
if (colorCount < 2 || colorCount > 256) { if (colorCount < 2 || colorCount > 256)
throw new IllegalArgumentException("Specified colorCount must be between 2 and 256."); throw new IllegalArgumentException("Specified colorCount must be between 2 and 256.");
} if (quality < 1)
if (quality < 1) {
throw new IllegalArgumentException("Specified quality should be greater then 0."); throw new IllegalArgumentException("Specified quality should be greater then 0.");
}
int[][] pixelArray = switch (sourceImage.getType()) { int[][] pixelArray = switch (sourceImage.getType()) {
case TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR -> getPixelsFast(sourceImage, quality, ignoreWhite); case TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR -> getPixelsFast(sourceImage, quality, ignoreWhite);
@ -94,7 +98,7 @@ final class ColorThief {
int offset, r, g, b, a; int offset, r, g, b, a;
switch (type) { switch (type) {
case TYPE_3BYTE_BGR: case TYPE_3BYTE_BGR -> {
for (int i = 0; i < pixelCount; i += quality) { for (int i = 0; i < pixelCount; i += quality) {
offset = i * 3; offset = i * 3;
b = pixels[offset] & 0xFF; b = pixels[offset] & 0xFF;
@ -106,9 +110,8 @@ final class ColorThief {
numUsedPixels++; numUsedPixels++;
} }
} }
break; }
case TYPE_4BYTE_ABGR -> {
case TYPE_4BYTE_ABGR:
for (int i = 0; i < pixelCount; i += quality) { for (int i = 0; i < pixelCount; i += quality) {
offset = i * 4; offset = i * 4;
a = pixels[offset] & 0xFF; a = pixels[offset] & 0xFF;
@ -121,10 +124,8 @@ final class ColorThief {
numUsedPixels++; numUsedPixels++;
} }
} }
break; }
default -> throw new IllegalArgumentException("Unhandled type: " + type);
default:
throw new IllegalArgumentException("Unhandled type: " + type);
} }
return Arrays.copyOfRange(pixelArray, 0, numUsedPixels); return Arrays.copyOfRange(pixelArray, 0, numUsedPixels);
@ -279,7 +280,7 @@ final class ColorThief {
public static class ColorMap { public static class ColorMap {
public final ArrayList<VBox> vboxes = new ArrayList<>(); public final List<VBox> vboxes = new ArrayList<>();
public void push(VBox box) { public void push(VBox box) {
vboxes.add(box); vboxes.add(box);