diff --git a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/PaginationSkin.java b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/PaginationSkin.java index 01fd7e97f66..264b4fd812b 100644 --- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/PaginationSkin.java +++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/PaginationSkin.java @@ -94,7 +94,7 @@ public class PaginationSkin extends SkinBase { private static final Duration DURATION = new Duration(125.0); private static final double SWIPE_THRESHOLD = 0.30; private static final double TOUCH_THRESHOLD = 15; - private static final Interpolator interpolator = Interpolator.SPLINE(0.4829, 0.5709, 0.6803, 0.9928); + private static final Interpolator interpolator = Interpolator.ofSpline(0.4829, 0.5709, 0.6803, 0.9928); diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/css/InterpolatorConverter.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/css/InterpolatorConverter.java index 19c160c8a5b..980864ab39c 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/css/InterpolatorConverter.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/css/InterpolatorConverter.java @@ -64,10 +64,10 @@ public static StyleConverter getInstance() { // SMIL 3.0's definitions that are used for Interpolator.EASE_IN and Interpolator.EASE_OUT. // https://www.w3.org/TR/css-easing-1/#cubic-bezier-easing-functions // - public static final Interpolator CSS_EASE = Interpolator.SPLINE(0.25, 0.1, 0.25, 1); - public static final Interpolator CSS_EASE_IN = Interpolator.SPLINE(0.42, 0, 1, 1); - public static final Interpolator CSS_EASE_OUT = Interpolator.SPLINE(0, 0, 0.58, 1); - public static final Interpolator CSS_EASE_IN_OUT = Interpolator.SPLINE(0.42, 0, 0.58, 1); + public static final Interpolator CSS_EASE = Interpolator.ofSpline(0.25, 0.1, 0.25, 1); + public static final Interpolator CSS_EASE_IN = Interpolator.ofSpline(0.42, 0, 1, 1); + public static final Interpolator CSS_EASE_OUT = Interpolator.ofSpline(0, 0, 0.58, 1); + public static final Interpolator CSS_EASE_IN_OUT = Interpolator.ofSpline(0.42, 0, 0.58, 1); // We're using an LRU cache (least recently used) to limit the number of redundant instances. private static final Map, Interpolator> CACHE = new LinkedHashMap<>(10, 0.75f, true) { @@ -101,13 +101,13 @@ public Interpolator convert(ParsedValue value, Font font) return switch (funcName) { case "cubic-bezier(" -> CACHE.computeIfAbsent(value, key -> { List args = arguments(key); - return Interpolator.SPLINE(args.get(0), args.get(1), args.get(2), args.get(3)); + return Interpolator.ofSpline(args.get(0), args.get(1), args.get(2), args.get(3)); }); case "steps(" -> CACHE.computeIfAbsent(value, key -> { List args = arguments(key); String position = args.get(1) != null ? (String)args.get(1) : "end"; - return Interpolator.STEPS((int)args.get(0), switch (position) { + return Interpolator.ofSteps((int)args.get(0), switch (position) { case "jump-start", "start" -> StepPosition.START; case "jump-both" -> StepPosition.BOTH; case "jump-none" -> StepPosition.NONE; diff --git a/modules/javafx.graphics/src/main/java/javafx/animation/Interpolator.java b/modules/javafx.graphics/src/main/java/javafx/animation/Interpolator.java index e95b891d0b7..3d2fc193b16 100644 --- a/modules/javafx.graphics/src/main/java/javafx/animation/Interpolator.java +++ b/modules/javafx.graphics/src/main/java/javafx/animation/Interpolator.java @@ -216,28 +216,59 @@ public String toString() { }; /** - * Creates an {@code Interpolator}, which {@link #curve(double) curve()} is + * This is a legacy method named inconsistently with method naming conventions, + * use {@link #ofSpline(double, double, double, double)} instead. + * + * @param x1 x coordinate of the first control point + * @param y1 y coordinate of the first control point + * @param x2 x coordinate of the second control point + * @param y2 y coordinate of the second control point + * @throws IllegalArgumentException if {@code x1} or {@code x2} is outside of {@code [0, 1]} + * @return a spline interpolator + * @deprecated use {@link #ofSpline(double, double, double, double)} instead + */ + @Deprecated(since = "26") + public static Interpolator SPLINE(double x1, double y1, double x2, double y2) { + return ofSpline(x1, y1, x2, y2); + } + + /** + * Returns an {@code Interpolator} whose {@link #curve(double) curve()} is * shaped using the spline control points defined by ({@code x1}, {@code y1} * ) and ({@code x2}, {@code y2}). The anchor points of the spline are * implicitly defined as ({@code 0.0}, {@code 0.0}) and ({@code 1.0}, * {@code 1.0}). * - * @param x1 - * x coordinate of the first control point - * @param y1 - * y coordinate of the first control point - * @param x2 - * x coordinate of the second control point - * @param y2 - * y coordinate of the second control point - * @return A spline interpolator + * @param x1 x coordinate of the first control point + * @param y1 y coordinate of the first control point + * @param x2 x coordinate of the second control point + * @param y2 y coordinate of the second control point + * @throws IllegalArgumentException if {@code x1} or {@code x2} is outside of {@code [0, 1]} + * @return a spline interpolator + * @since 26 */ - public static Interpolator SPLINE(double x1, double y1, double x2, double y2) { + public static Interpolator ofSpline(double x1, double y1, double x2, double y2) { return new SplineInterpolator(x1, y1, x2, y2); } /** - * Create a tangent interpolator. A tangent interpolator allows to define + * This is a legacy method named inconsistently with method naming conventions, + * use {@link #ofTangent(Duration, double, Duration, double)} instead. + * + * @param t1 the delta time of the in-tangent, relative to the KeyFrame + * @param v1 the value of the in-tangent + * @param t2 the delta time of the out-tangent, relative to the KeyFrame + * @param v2 the value of the out-tangent + * @return a tangent interpolator + * @deprecated use {@link #ofTangent(Duration, double, Duration, double)} instead + */ + @Deprecated(since = "26") + public static Interpolator TANGENT(Duration t1, double v1, Duration t2, double v2) { + return ofTangent(t1, v1, t2, v2); + } + + /** + * Returns a tangent interpolator. A tangent interpolator allows to define * the behavior of an animation curve very precisely by defining the * tangents close to a key frame. * @@ -260,36 +291,45 @@ public static Interpolator SPLINE(double x1, double y1, double x2, double y2) { * The interpolation then follows a bezier curve, with 2 control points defined by the specified tangent and * positioned at 1/3 of the duration before the second KeyFrame or after the first KeyFrame. See the picture above. * - * @param t1 - * The delta time of the in-tangent, relative to the KeyFrame - * @param v1 - * The value of the in-tangent - * @param t2 - * The delta time of the out-tangent, relative to the KeyFrame - * @param v2 - * The value of the out-tangent - * @return the new tangent interpolator + * @param t1 the delta time of the in-tangent, relative to the KeyFrame + * @param v1 the value of the in-tangent + * @param t2 the delta time of the out-tangent, relative to the KeyFrame + * @param v2 the value of the out-tangent + * @return a tangent interpolator + * @since 26 */ - public static Interpolator TANGENT(Duration t1, double v1, Duration t2, - double v2) { + public static Interpolator ofTangent(Duration t1, double v1, Duration t2, double v2) { return new NumberTangentInterpolator(t1, v1, t2, v2); } /** - * Creates a tangent interpolator, for which in-tangent and out-tangent are + * This is a legacy method named inconsistently with method naming conventions, + * use {@link #ofTangent(Duration, double)} instead. + * + * @param t the delta time of the tangent + * @param v the value of the tangent + * @return a tangent interpolator + * @deprecated use {@link #ofTangent(Duration, double)} instead + */ + @Deprecated(since = "26") + public static Interpolator TANGENT(Duration t, double v) { + return ofTangent(t, v); + } + + /** + * Returns a tangent interpolator, for which in-tangent and out-tangent are * identical. This is especially useful for the first and the last key frame * of a {@link Timeline}, because for these key frames only one tangent is * used. * - * @see #TANGENT(Duration, double, Duration, double) + * @see #ofTangent(Duration, double, Duration, double) * - * @param t - * The delta time of the tangent - * @param v - * The value of the tangent - * @return the new Tangent interpolator + * @param t the delta time of the tangent + * @param v the value of the tangent + * @return a tangent interpolator + * @since 26 */ - public static Interpolator TANGENT(Duration t, double v) { + public static Interpolator ofTangent(Duration t, double v) { return new NumberTangentInterpolator(t, v); } @@ -337,19 +377,18 @@ public enum StepPosition { * * @since 23 */ - public static final Interpolator STEP_START = STEPS(1, StepPosition.START); + public static final Interpolator STEP_START = ofSteps(1, StepPosition.START); /** * Built-in interpolator instance that is equivalent to {@code STEPS(1, StepPosition.END)}. * * @since 23 */ - public static final Interpolator STEP_END = STEPS(1, StepPosition.END); + public static final Interpolator STEP_END = ofSteps(1, StepPosition.END); /** - * Creates a step interpolator that divides the input time into a series of intervals, each - * interval being equal in length, where each interval maps to a constant output time value. - * The output time value is determined by the {@link StepPosition}. + * This is a legacy method named inconsistently with method naming conventions, + * use {@link #ofSteps(int, StepPosition)} instead. * * @param intervalCount the number of intervals in the step interpolator * @param position the {@code StepPosition} of the step interpolator @@ -357,10 +396,28 @@ public enum StepPosition { * less than 2 when {@code position} is {@link StepPosition#NONE} * @throws NullPointerException if {@code position} is {@code null} * @return a new step interpolator - * + * @deprecated use {@link #ofSteps(int, StepPosition)} instead * @since 23 */ + @Deprecated(since = "26") public static Interpolator STEPS(int intervalCount, StepPosition position) { + return ofSteps(intervalCount, position); + } + + /** + * Returns a step interpolator that divides the input time into a series of intervals, each + * interval being equal in length, where each interval maps to a constant output time value. + * The output time value is determined by the {@link StepPosition}. + * + * @param intervalCount the number of intervals in the step interpolator + * @param position the {@code StepPosition} of the step interpolator + * @throws IllegalArgumentException if {@code intervals} is less than 1, or if {@code intervals} is + * less than 2 when {@code position} is {@link StepPosition#NONE} + * @throws NullPointerException if {@code position} is {@code null} + * @return a step interpolator + * @since 26 + */ + public static Interpolator ofSteps(int intervalCount, StepPosition position) { return new StepInterpolator(intervalCount, position); } diff --git a/modules/javafx.graphics/src/main/java/javafx/animation/KeyValue.java b/modules/javafx.graphics/src/main/java/javafx/animation/KeyValue.java index bb15885dead..e0a9fa721d5 100644 --- a/modules/javafx.graphics/src/main/java/javafx/animation/KeyValue.java +++ b/modules/javafx.graphics/src/main/java/javafx/animation/KeyValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,7 +51,7 @@ * direction) specifies the interpolator to be used in the interval. *

* Tangent-interpolators define the interpolation to the left and to the right of - * a {@code KeyFrame} (see {@link Interpolator#TANGENT(javafx.util.Duration, double, javafx.util.Duration, double) + * a {@code KeyFrame} (see {@link Interpolator#ofTangent(javafx.util.Duration, double, javafx.util.Duration, double) * Interpolator.TANGENT}). *

* By default, {@link Interpolator#LINEAR} is used in the interval. diff --git a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/converters/InterpolatorConverterTest.java b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/converters/InterpolatorConverterTest.java index e6e16a2fb78..1f9bee71c74 100644 --- a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/converters/InterpolatorConverterTest.java +++ b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/converters/InterpolatorConverterTest.java @@ -115,7 +115,7 @@ public void testConvertCubicBezierInterpolator() { new ParsedValueImpl<>(List.of(0.1, 0.2, 0.3, 0.4), null) }, null); var result = InterpolatorConverter.getInstance().convert(value, null); - assertInterpolatorEquals(SPLINE(0.1, 0.2, 0.3, 0.4), result); + assertInterpolatorEquals(ofSpline(0.1, 0.2, 0.3, 0.4), result); } @Test @@ -141,7 +141,7 @@ public void testConvertStepsInterpolator() { new ParsedValueImpl<>(List.of(3, cssName), null) }, null); var result = InterpolatorConverter.getInstance().convert(value, null); - assertInterpolatorEquals(STEPS(3, stepPosition), result); + assertInterpolatorEquals(ofSteps(3, stepPosition), result); } } diff --git a/modules/javafx.graphics/src/test/java/test/javafx/animation/InterpolatorTest.java b/modules/javafx.graphics/src/test/java/test/javafx/animation/InterpolatorTest.java index b39a6b5ac86..d4805bd9990 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/animation/InterpolatorTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/animation/InterpolatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -225,8 +225,8 @@ public void testEASE_OUT() { } @Test - public void testSPLINE_Concave() { - Interpolator i = Interpolator.SPLINE(0.0, 0.5, 0.5, 1.0); + public void testSpline_Concave() { + Interpolator i = Interpolator.ofSpline(0.0, 0.5, 0.5, 1.0); assertEquals(1.0, i.interpolate(1.0, 2.0, 0.0), EPSILON); assertEquals(1.5573742287206063, i.interpolate(1.0, 2.0, 0.2), EPSILON); assertEquals(1.8400223953585164, i.interpolate(1.0, 2.0, 0.5), EPSILON); @@ -235,8 +235,8 @@ public void testSPLINE_Concave() { } @Test - public void testSPLINE_Convex() { - Interpolator i = Interpolator.SPLINE(0.5, 0.0, 1.0, 0.5); + public void testSpline_Convex() { + Interpolator i = Interpolator.ofSpline(0.5, 0.0, 1.0, 0.5); assertEquals(1.0, i.interpolate(1.0, 2.0, 0.0), EPSILON); assertEquals(1.0257826739185762, i.interpolate(1.0, 2.0, 0.2), EPSILON); assertEquals(1.1599776046414838, i.interpolate(1.0, 2.0, 0.5), EPSILON); @@ -245,8 +245,8 @@ public void testSPLINE_Convex() { } @Test - public void testSPLINE_WithInflectionPoint() { - Interpolator i = Interpolator.SPLINE(0.0, 1.0, 1.0, 0.0); + public void testSpline_WithInflectionPoint() { + Interpolator i = Interpolator.ofSpline(0.0, 1.0, 1.0, 0.0); assertEquals(1.0, i.interpolate(1.0, 2.0, 0.0), EPSILON); assertEquals(1.4614221762502215, i.interpolate(1.0, 2.0, 0.2), EPSILON); @@ -256,8 +256,8 @@ public void testSPLINE_WithInflectionPoint() { } @Test - public void testSPLINE_Linear() { - Interpolator i = Interpolator.SPLINE(1/3, 1/3, 2/3, 2/3); + public void testSpline_Linear() { + Interpolator i = Interpolator.ofSpline(1/3, 1/3, 2/3, 2/3); assertEquals(1.0, i.interpolate(1.0, 2.0, 0.0), EPSILON); assertEquals(1.2, i.interpolate(1.0, 2.0, 0.2), EPSILON); @@ -267,11 +267,11 @@ public void testSPLINE_Linear() { } @Test - public void testTANGENT_Linear() { + public void testTangent_Linear() { SimpleLongProperty property = new SimpleLongProperty(); - Interpolator i0 = Interpolator.TANGENT(Duration.seconds(1), 20); - Interpolator i1 = Interpolator.TANGENT(Duration.seconds(1), 40); + Interpolator i0 = Interpolator.ofTangent(Duration.seconds(1), 20); + Interpolator i1 = Interpolator.ofTangent(Duration.seconds(1), 40); InterpolationInterval interval = InterpolationInterval.create(new KeyValue(property, 60L, i1), TickCalculation.fromDuration(Duration.seconds(3)), diff --git a/modules/javafx.graphics/src/test/java/test/javafx/css/CssParser_transition_Test.java b/modules/javafx.graphics/src/test/java/test/javafx/css/CssParser_transition_Test.java index 6182ab897af..2582c861e1e 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/css/CssParser_transition_Test.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/css/CssParser_transition_Test.java @@ -189,21 +189,21 @@ public void testTransitionTimingFunction() { assertInterpolatorEquals(CSS_EASE_IN, values[1]); assertInterpolatorEquals(CSS_EASE_OUT, values[2]); assertInterpolatorEquals(CSS_EASE_IN_OUT, values[3]); - assertInterpolatorEquals(SPLINE(0.1, 0.2, 0.3, 0.4), values[4]); - assertInterpolatorEquals(SPLINE(0.5, 2, 0.5, -1), values[5]); + assertInterpolatorEquals(ofSpline(0.1, 0.2, 0.3, 0.4), values[4]); + assertInterpolatorEquals(ofSpline(0.5, 2, 0.5, -1), values[5]); values = values("transition-timing-function", stylesheet.getRules().get(2)); assertInterpolatorEquals(STEP_START, values[0]); assertInterpolatorEquals(STEP_END, values[1]); - assertInterpolatorEquals(STEPS(3, StepPosition.START), values[2]); - assertInterpolatorEquals(STEPS(3, StepPosition.END), values[3]); - assertInterpolatorEquals(STEPS(3, StepPosition.NONE), values[4]); - assertInterpolatorEquals(STEPS(3, StepPosition.BOTH), values[5]); - assertInterpolatorEquals(STEPS(3, StepPosition.START), values[6]); - assertInterpolatorEquals(STEPS(3, StepPosition.END), values[7]); + assertInterpolatorEquals(ofSteps(3, StepPosition.START), values[2]); + assertInterpolatorEquals(ofSteps(3, StepPosition.END), values[3]); + assertInterpolatorEquals(ofSteps(3, StepPosition.NONE), values[4]); + assertInterpolatorEquals(ofSteps(3, StepPosition.BOTH), values[5]); + assertInterpolatorEquals(ofSteps(3, StepPosition.START), values[6]); + assertInterpolatorEquals(ofSteps(3, StepPosition.END), values[7]); values = values("transition-timing-function", stylesheet.getRules().get(3)); - assertInterpolatorEquals(STEPS(3, StepPosition.END), values[0]); + assertInterpolatorEquals(ofSteps(3, StepPosition.END), values[0]); values = values("transition-timing-function", stylesheet.getRules().get(4)); assertInterpolatorEquals(ofLinear(new Point2D(0, 0), new Point2D(0.5, 0.25), new Point2D(1, 1)), values[0]); @@ -247,12 +247,12 @@ public void testShorthandTransition() { assertTransition( new TransitionDefinition("foo", seconds(0.3), seconds(0.4), - SPLINE(0.1, 0.2, 0.3, .4)), + ofSpline(0.1, 0.2, 0.3, .4)), ((TransitionDefinition[])values("transition", stylesheet.getRules().get(3)))[0]); assertTransition( new TransitionDefinition("foo", seconds(0.3), seconds(0.4), - SPLINE(0.1, 0.2, 0.3, .4)), + ofSpline(0.1, 0.2, 0.3, .4)), ((TransitionDefinition[])values("transition", stylesheet.getRules().get(4)))[0]); assertStartsWith("Expected ''", CssParser.errorsProperty().get(0).getMessage());