Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class PaginationSkin extends SkinBase<Pagination> {
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-topic: shouldn't this interpolator be specified by the stylesheet (i.e. to be able to modify the transition if needed)?

More of a question for @kevinrushforth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean should it be styleable in pagination? Probably, but I haven't heard anyone request it. It could be an RFE for "some day".




Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 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
Expand Down Expand Up @@ -62,10 +62,10 @@ public static StyleConverter<Object, Interpolator> 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<ParsedValue<?, ?>, Interpolator> CACHE = new LinkedHashMap<>(10, 0.75f, true) {
Expand Down Expand Up @@ -99,13 +99,13 @@ public Interpolator convert(ParsedValue<Object, Interpolator> value, Font font)
return switch (funcName) {
case "cubic-bezier(" -> CACHE.computeIfAbsent(value, key -> {
List<Double> 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<Object> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,57 @@ public String toString() {
};

/**
* Creates an {@code Interpolator}, which {@link #curve(double) curve()} is
* Use {@link #ofSpline(double, double, double, double)}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like "This poorly named method is deprecated in favor of ..." or words to that extent?

or keep the original description?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like "This poorly named method is deprecated in favor of ..." or words to that extent?

We wouldn't do this in the description, but possibly in the @deprecated tag text (not sure).

or keep the original description?

That's what we typically do, although I can see the value in what @mstr2 proposed. I'll take a look at the built docs and see how it looks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commited the suggested change without noticing your reply here. The description is now similar to:

     * This is a legacy method named inconsistently with method naming conventions,
     * use {@link #ofSpline(double, double, double, double)} instead.

I can revert the change, or keep the existing description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a closer look soon.

*
* @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
* Use {@link #ofTangent(Duration, double, Duration, double)}.
*
* @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.
*
Expand All @@ -233,36 +262,44 @@ 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
* Use {@link #ofTangent(Duration, double)}.
*
* @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);
}

Expand Down Expand Up @@ -310,30 +347,46 @@ 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}.
* Use {@link #ofSteps(int, 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 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@
* direction) specifies the interpolator to be used in the interval.
* <p>
* 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}).
* <p>
* By default, {@link Interpolator#LINEAR} is used in the interval.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 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
Expand Down Expand Up @@ -104,7 +104,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
Expand All @@ -130,7 +130,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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,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]);

assertStartsWith("Expected '<number [0,1]>'", CssParser.errorsProperty().get(0).getMessage());
assertStartsWith("Expected '<step-position>'", CssParser.errorsProperty().get(2).getMessage());
Expand Down Expand Up @@ -229,12 +229,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 '<single-transition-property>'", CssParser.errorsProperty().get(0).getMessage());
Expand Down