Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.jfoenix.transitions.template;
import javafx.animation.Interpolator;
import javafx.beans.value.WritableValue;
import javafx.event.ActionEvent;
import javafx.scene.Node;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
* Class which represents a builder and the configuration of animation keyframes. The configuration
* methods are based on the methods of a {@link javafx.animation.KeyFrame} and {@link
* javafx.animation.KeyValue}.
* It is possible that not all methods supported because the specific implementation of an animation
* can diverge from general {@link javafx.animation.KeyFrame} and {@link javafx.animation.KeyValue}
* implementations.
*
* @author Marcel Schlegel (schlegel11)
* @version 1.0
* @since 2018-09-22
*/
public final class JFXAnimationTemplateAction {
public static final int INFINITE_EXECUTIONS = -1;
private final Collection>> targetFunctions;
private final Function endValueSupplier;
private final Function interpolatorSupplier;
private final Predicate executeWhenPredicate;
private final BiConsumer onFinish;
private final Function executionsFunction;
private final N animationObject;
private int executionsCounter;
private JFXAnimationTemplateAction(Builder builder) {
targetFunctions = builder.targetFunctions;
endValueSupplier = builder.endValueFunction;
interpolatorSupplier = builder.interpolatorFunction;
animationObject = builder.animationObject;
executeWhenPredicate = builder.executeWhenPredicate;
onFinish = builder.onFinish;
executionsFunction = builder.executionsFunction;
}
public static InitBuilder builder(Class animationObjectType) {
return new InitBuilder<>(
animationObjectType,
JFXTemplateBuilder.JFXAnimationObjectMapBuilder.DEFAULT_ANIMATION_OBJECT_NAME);
}
public static InitBuilder builder() {
return builder(Node.class);
}
public Collection>> getTargetFunctions() {
return targetFunctions;
}
public Optional> getFirstTarget() {
return getTargetFunctions()
.stream()
.findFirst()
.map(function -> function.apply(animationObject));
}
public T getEndValue() {
return endValueSupplier.apply(animationObject);
}
public Optional getInterpolator() {
return Optional.ofNullable(interpolatorSupplier.apply(animationObject));
}
public boolean isExecuteWhen() {
return executeWhenPredicate.test(animationObject);
}
public int getExecutions() {
return Math.max(executionsFunction.apply(animationObject), INFINITE_EXECUTIONS);
}
public void addExecution(int count) {
int maxExecutions = getExecutions();
if (count >= 0 && executionsCounter < maxExecutions) {
executionsCounter = Math.min(executionsCounter + count, maxExecutions);
}
}
public int getRemainingExecutions() {
int maxExecutions = getExecutions();
return maxExecutions == INFINITE_EXECUTIONS
? INFINITE_EXECUTIONS
: Math.max(0, maxExecutions - executionsCounter);
}
public boolean hasRemainingExecutions() {
return getRemainingExecutions() > 0 || getRemainingExecutions() == INFINITE_EXECUTIONS;
}
/**
* True if {@link #hasRemainingExecutions()} and {@link #isExecuteWhen()} is {@code true}.
*
* @return a boolean.
*/
public boolean isExecuted() {
return hasRemainingExecutions() && isExecuteWhen();
}
public void handleOnFinish(ActionEvent actionEvent) {
onFinish.accept(animationObject, actionEvent);
}
@SuppressWarnings("unchecked")
public Stream mapTo(Function, M> mappingFunction) {
return getTargetFunctions()
.stream()
.map(
function ->
mappingFunction.apply((WritableValue