From 5c4b42c87757da3b130f6bf9ff84a840706b0d00 Mon Sep 17 00:00:00 2001 From: mstr2 <43553916+mstr2@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:09:25 +0100 Subject: [PATCH 1/2] Seal Paint and Material --- .../src/main/java/javafx/scene/paint/Material.java | 2 +- .../src/main/java/javafx/scene/paint/Paint.java | 3 ++- .../src/main/java/javafx/scene/paint/PhongMaterial.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java index 0af53e24d3f..0c4f4ea1937 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java @@ -45,7 +45,7 @@ * * @since JavaFX 8.0 */ -public abstract class Material { +public abstract sealed class Material permits PhongMaterial { static { // This is used by classes in different packages to get access to diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java index 709ba3c6975..a91acb6c5c9 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java @@ -45,7 +45,8 @@ * * @since JavaFX 2.0 */ -public abstract class Paint implements Interpolatable { +public abstract sealed class Paint implements Interpolatable + permits Color, LinearGradient, RadialGradient, ImagePattern { static { Toolkit.setPaintAccessor(new Toolkit.PaintAccessor() { diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/paint/PhongMaterial.java b/modules/javafx.graphics/src/main/java/javafx/scene/paint/PhongMaterial.java index 3e7f85125d1..54717d8bb84 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/PhongMaterial.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/PhongMaterial.java @@ -431,7 +431,7 @@ * @see Shape3D * @since JavaFX 8.0 */ -public class PhongMaterial extends Material { +public non-sealed class PhongMaterial extends Material { private boolean diffuseColorDirty = true; private boolean specularColorDirty = true; From f0a39b16acc12741b5740072dd5e64871f36cbf0 Mon Sep 17 00:00:00 2001 From: mstr2 <43553916+mstr2@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:12:38 +0100 Subject: [PATCH 2/2] use exhaustive switch pattern --- .../main/java/com/sun/javafx/tk/Toolkit.java | 23 +++++-------------- .../java/javafx/scene/paint/ImagePattern.java | 1 - 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java index 527db4f8a44..d76cfbdc04e 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java @@ -594,23 +594,12 @@ private Object getPaint(RadialGradient paint) { } public Object getPaint(Paint paint) { - if (paint instanceof Color) { - return createColorPaint((Color) paint); - } - - if (paint instanceof LinearGradient) { - return getPaint((LinearGradient) paint); - } - - if (paint instanceof RadialGradient) { - return getPaint((RadialGradient) paint); - } - - if (paint instanceof ImagePattern) { - return createImagePatternPaint((ImagePattern) paint); - } - - return null; + return switch (paint) { + case Color color -> createColorPaint(color); + case LinearGradient gradient -> getPaint(gradient); + case RadialGradient gradient -> getPaint(gradient); + case ImagePattern pattern -> createImagePatternPaint(pattern); + }; } protected static final double clampStopOffset(double offset) { diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/paint/ImagePattern.java b/modules/javafx.graphics/src/main/java/javafx/scene/paint/ImagePattern.java index 8b896766343..8dde5b10d08 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/ImagePattern.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/ImagePattern.java @@ -383,7 +383,6 @@ void acc_removeListener(AbstractNotifyListener platformChangeListener) { @Override Object acc_getPlatformPaint() { if (acc_isMutable() || platformPaint == null) { platformPaint = Toolkit.getToolkit().getPaint(this); - assert platformPaint != null; } return platformPaint; }