com.jfoenix.transitions.template.JFXAnimationTemplate Maven / Gradle / Ivy
/*
* 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.Timeline;
import javafx.scene.Node;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Class which represents a general {@link JFXAnimationTemplate}.
* This class is responsible for providing methods where it's possible to build a CSS like
* structured animation.
*
* @author Marcel Schlegel (schlegel11)
* @version 1.0
* @since 2018-09-18
*/
public class JFXAnimationTemplate implements JFXTemplateConfig, JFXTemplateBuilder {
private static final String NO_KEY_FOUND_MESSAGE =
"No animation objects with key \"%s\" found.\n"
+ "Please check your build method where the "
+ "namedAnimationObjects are defined or your "
+ "withAnimationObject methods where the keys are accessed.";
private final Set percents = new HashSet<>();
private final Map<
Double,
List<
Function<
JFXAnimationTemplateAction.InitBuilder,
JFXAnimationTemplateAction.Builder>>>
creatorValueBuilderFunctions = new HashMap<>();
private final Class animationObjectType;
private Map> animationObjects;
private Function
creatorConfigBuilderFunction;
private boolean clearPercents;
private JFXAnimationTemplate(Class animationObjectType) {
this.animationObjectType = animationObjectType;
}
/**
* Create a {@link JFXTemplateProcess} with a specific default animation type.
* The default animation objects with this type are set later in the {@link
* JFXTemplateBuilder#build(Object)} method.
* These objects are generally used in {@link JFXTemplateAction#action(Function)} methods.
*
* @param animationObjectType a specific animation object type.
* @param the specific type.
* @return a {@link JFXTemplateProcess} instance.
*/
public static JFXTemplateProcess create(Class animationObjectType) {
return new JFXAnimationTemplate<>(animationObjectType);
}
/**
* Same method as {@link #create(Class)} but with the default type {@link Node}. This type is a
* general default type in a {@link JFXAnimationTemplate}.
*
* @see #create(Class)
* @return a {@link JFXTemplateProcess} instance.
*/
public static JFXTemplateProcess create() {
return create(Node.class);
}
public Map>> buildAndGetAnimationValues() {
Map>> animationValueMap = new HashMap<>();
creatorValueBuilderFunctions.forEach(
(percent, animationValueBuilderFunctions) -> {
List> animationValues =
animationValueBuilderFunctions
.stream()
.flatMap(
builderFunction ->
builderFunction
.apply(JFXAnimationTemplateAction.builder(animationObjectType))
.buildActions(this::getAnimationObjectsWithKeys))
.collect(Collectors.toList());
animationValueMap.put(percent, animationValues);
});
return animationValueMap;
}
private List