From 2d47dfc28c8fe45a47c12357a2755d86702ff34e Mon Sep 17 00:00:00 2001 From: Tinglyyy Date: Tue, 10 Feb 2026 22:30:57 +0100 Subject: [PATCH] Added javadoc --- .../oacswing/animated/AnimationPath.java | 68 +++++++------------ .../oacswing/animated/KeyFrame.java | 57 ++++++++++++++-- 2 files changed, 77 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/openautonomousconnection/oacswing/animated/AnimationPath.java b/src/main/java/org/openautonomousconnection/oacswing/animated/AnimationPath.java index fe5b520..e2e9829 100644 --- a/src/main/java/org/openautonomousconnection/oacswing/animated/AnimationPath.java +++ b/src/main/java/org/openautonomousconnection/oacswing/animated/AnimationPath.java @@ -102,16 +102,18 @@ public class AnimationPath extends ArrayList { case LINEAR -> switch (nextMethod) { case LINEAR -> CombinedPathMethod.LINEAR; case EASE_IN -> CombinedPathMethod.LINEAR_EASE_IN; - case EASE_OUT -> CombinedPathMethod.LINEAR_EASE_OUT; + // Removed this case, as ease-out doesn't make sense right before a keyframe +// case EASE_OUT -> CombinedPathMethod.LINEAR_EASE_OUT; default -> throw new IllegalStateException("Unexpected value: " + nextMethod); }; - case EASE_IN -> switch (nextMethod) { - case LINEAR -> CombinedPathMethod.EASE_IN_LINEAR; - case EASE_IN -> CombinedPathMethod.EASE_IN; - case EASE_OUT -> CombinedPathMethod.EASE_OUT_LINEAR; - default -> throw new IllegalStateException("Unexpected value: " + nextMethod); - }; + // Removed this case, as ease-in doesn't make sense right after a keyframe +// case EASE_IN -> switch (nextMethod) { +// case LINEAR -> CombinedPathMethod.EASE_IN_LINEAR; +// case EASE_IN -> CombinedPathMethod.EASE_IN; +// case EASE_OUT -> CombinedPathMethod.EASE_OUT_LINEAR; +// default -> throw new IllegalStateException("Unexpected value: " + nextMethod); +// }; case EASE_OUT -> switch (nextMethod) { case LINEAR -> CombinedPathMethod.EASE_OUT_LINEAR; @@ -122,57 +124,37 @@ public class AnimationPath extends ArrayList { default -> throw new IllegalStateException("Unexpected value: " + currentMethod); }; - boolean overHalf = transition > 0.5; + double threshold = Math.min(current.transition(), next.transition()); - if(overHalf) + boolean thresholdReached; + + if(current.transition() < next.transition()) + thresholdReached = transition > threshold; + else + thresholdReached = transition <= next.transition(); + + if(thresholdReached) transition = 2 * transition - 1; transition = switch (method) { case LINEAR -> transition; - case LINEAR_EASE_IN -> overHalf ? easeIn(subIterator) : transition; + case LINEAR_EASE_IN -> thresholdReached ? easeIn(subIterator) : transition; - case EASE_IN -> easeIn(subIterator); - - case EASE_IN_LINEAR -> overHalf ? transition : easeIn(subIterator); - - case LINEAR_EASE_OUT -> overHalf ? easeOut(subIterator) : transition; +// case EASE_IN -> easeIn(subIterator); case EASE_OUT -> easeOut(subIterator); - case EASE_OUT_LINEAR -> overHalf ? transition : easeOut(subIterator); + case EASE_OUT_LINEAR -> thresholdReached ? transition : easeOut(subIterator); - case EASE_OUT_AND_IN -> overHalf ? easeOut(subIterator) : easeIn(subIterator); + case EASE_OUT_AND_IN -> thresholdReached ? easeOut(subIterator) : easeIn(subIterator); }; System.out.println(method + " " + transition + " - linear: " + linear(subIterator)); - return inBetween(current, next, transition, overHalf); + return inBetween(current, next, transition, thresholdReached); - -// KeyFrame.PathMethod method; -// -// // Translate EASE_IN_AND_OUT to its respective currently relevant counterpart -// -// //TODO: non-linear keyframes can't behandled this way. This just makes it bug around -// -// if(transition < 0.5) -// method = current.pathMethod().equals(KeyFrame.PathMethod.EASE_IN_AND_OUT) ? -// KeyFrame.PathMethod.EASE_OUT : current.pathMethod(); -// else -// method = next.pathMethod().equals(KeyFrame.PathMethod.EASE_IN_AND_OUT) ? -// KeyFrame.PathMethod.EASE_OUT : next.pathMethod(); -// -// // Else-case would be linear, which doesn't change anything -// -// if(method.equals(KeyFrame.PathMethod.EASE_IN)) -// transition = this.easeIn(subIterator); -// -// else if(method.equals(KeyFrame.PathMethod.EASE_OUT)) -// transition = this.easeOut(subIterator); -// -// return inBetween(current, next, transition, method); } @@ -324,9 +306,7 @@ public class AnimationPath extends ArrayList { private enum CombinedPathMethod { LINEAR, LINEAR_EASE_IN, - EASE_IN, - EASE_IN_LINEAR, - LINEAR_EASE_OUT, +// EASE_IN, EASE_OUT, EASE_OUT_LINEAR, EASE_OUT_AND_IN; diff --git a/src/main/java/org/openautonomousconnection/oacswing/animated/KeyFrame.java b/src/main/java/org/openautonomousconnection/oacswing/animated/KeyFrame.java index 2f3f325..f9c9332 100644 --- a/src/main/java/org/openautonomousconnection/oacswing/animated/KeyFrame.java +++ b/src/main/java/org/openautonomousconnection/oacswing/animated/KeyFrame.java @@ -7,18 +7,67 @@ package org.openautonomousconnection.oacswing.animated; import javax.swing.*; import java.awt.*; -public record KeyFrame(Point position, int width, int height, PathMethod pathMethod) { +/** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent} + * @param position positional vector (where is the object at this moment?) + * @param width first transformational vector (how wide is the object at this moment) + * @param height second transformational vector (how tall is the object at this moment) + * @param pathMethod how the path from this KeyFrame to the next should look like + * @param transition adds to pathMethod in how much of the path should be defined by this decision (default 0% for linear and 50% for all other methods) + */ +public record KeyFrame(Point position, int width, int height, PathMethod pathMethod, double transition) { - public KeyFrame(Point position, int width, int height) { - this(position, width, height, PathMethod.LINEAR); + /** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}. + * @param position positional vector (where is the object at this moment?) + * @param width first transformational vector (how wide is the object at this moment) + * @param height second transformational vector (how tall is the object at this moment) + * @param pathMethod how the path from this KeyFrame to the next should look like + */ + public KeyFrame(Point position, int width, int height, PathMethod pathMethod) { + this(position, width, height, pathMethod, pathMethod.equals(PathMethod.LINEAR) ? 0 : 0.5); } + /** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}. + * Defaults pathMethod to linear and transition percentage to 0% + * @param position positional vector (where is the object at this moment?) + * @param width first transformational vector (how wide is the object at this moment) + * @param height second transformational vector (how tall is the object at this moment) + */ + public KeyFrame(Point position, int width, int height) { + this(position, width, height, PathMethod.LINEAR, 0); + } + + /** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}. + * @param component component that contains necessary vectors + * @param pathMethod how the path from this KeyFrame to the next should look like + * @param transition adds to pathMethod in how much of the path should be defined by this decision (default 50%) + */ + public KeyFrame(JComponent component, PathMethod pathMethod, double transition) { + this( + new Point(component.getX(), component.getY()), + component.getBounds().width, component.getBounds().height, pathMethod, transition); + } + + /** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}. + * @param component component that contains necessary vectors + * @param pathMethod how the path from this KeyFrame to the next should look like + */ public KeyFrame(JComponent component, PathMethod pathMethod) { this( new Point(component.getX(), component.getY()), - component.getBounds().width, component.getBounds().height, pathMethod); + component.getBounds().width, component.getBounds().height, pathMethod, + pathMethod.equals(PathMethod.LINEAR) ? 0 : 0.5); } + /** + * Record that contains certain vectors and factors for animating in {@link AnimatedComponent}. + * Defaults pathMethod to linear and transition percentage to 50% + * @param component component that contains necessary vectors + */ public KeyFrame(JComponent component) { this(component, PathMethod.LINEAR); }