Commit 51678222 authored by Nico Mack's avatar Nico Mack

Added AnimationPropertyUtils class

Added START_FORWARD and START_BACKWARD constants to AnimationProperty
class
parent f1924b4f
......@@ -82,6 +82,9 @@ public class AnimationProperty<T> implements TimelineCallback {
BACKWARD
}
public static final Boolean START_FORWARD = Boolean.FALSE;
public static final Boolean START_BACKWARD = Boolean.TRUE;
private static final Logger logger = LoggerFactory.getLogger(AnimationProperty.class.getSimpleName());
// ---------------------------------------------------------------------------
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.feature.animation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AnimationPropertyUtils {
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(AnimationPropertyUtils.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
private AnimationPropertyUtils() {}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param clazz
* @return
*/
// ---------------------------------------------------------------------------
public static Map<String, Class<?>> getAnimationPropertyTypes(Class<?> clazz) {
Map<String, Class<?>> propertyTypes = new HashMap<>();
try {
for (Class<?> current = clazz; current != null; current = current.getSuperclass()) {
BeanInfo classDetails = Introspector.getBeanInfo(current);
PropertyDescriptor[] properties = classDetails.getPropertyDescriptors();
for (Method method : current.getDeclaredMethods()) {
AnimatedProperty animated = method.getAnnotation(AnimatedProperty.class);
if (animated != null) {
String property = animated.property();
for (PropertyDescriptor descriptor : properties) {
if (method.equals(descriptor.getWriteMethod())) {
Class<?>[] parameters = method.getParameterTypes();
propertyTypes.put(property, parameters[0]);
}
}
}
}
}
} catch (IntrospectionException e) {
LOGGER.error("Failed to lookup animation property types for class {}!", clazz.getSimpleName(), e); //$NON-NLS-1$
}
return propertyTypes;
}
// ---------------------------------------------------------------------------
/**
*
* @param clazz
* @return
*/
// ---------------------------------------------------------------------------
public static Map<String, Method> getAnimationSetters(Class<?> clazz) {
Map<String, Method> setters = new HashMap<>();
try {
for (Class<?> current = clazz; current != null; current = current.getSuperclass()) {
BeanInfo classDetails = Introspector.getBeanInfo(current);
PropertyDescriptor[] properties = classDetails.getPropertyDescriptors();
for (Method method : current.getDeclaredMethods()) {
AnimatedProperty animated = method.getAnnotation(AnimatedProperty.class);
if (animated != null) {
String property = animated.property();
for (PropertyDescriptor descriptor : properties) {
if (method.equals(descriptor.getWriteMethod())) {
setters.put(property, method);
}
}
}
}
}
} catch (IntrospectionException e) {
LOGGER.error("Failed to lookup animation Setters for corona {}!", clazz.getSimpleName()); //$NON-NLS-1$
}
return setters;
}
// ---------------------------------------------------------------------------
/**
* @param method
* @param object
* @param parameters
* @return
*/
// ---------------------------------------------------------------------------
public static Object invokeAnimationSetter(Method method, Object object, Object[] parameters) {
Object result = null;
try {
result = method.invoke(object, parameters);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
LOGGER.error("Failed to invoke method {} on object {}!", method.getName(), object.getClass().getSimpleName(), e); //$NON-NLS-1$
}
return result;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
// ***************************************************************************
// ---------------------------------------------------------------------------
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment