Interface AnimatedItemStyler<T,C extends JComponent>
- Type Parameters:
T- the type of the item of the bound property, supplied to this function as the first argument.C- the type of theJComponentthat theComponentStyleDelegateis delegating to.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
AnimatedItemStyler is conceptually a union of the ItemStyler
and AnimatedStyler functions, which is to say that it takes the current item
of a bound Val property, an AnimationStatus and a
ComponentStyleDelegate to produce a new ComponentStyleDelegate
with some style properties applied to it (usually based on both the item and the
animation progress). All parameters are immutable value oriented objects, so the function is pure and does not modify any of them.
This interface is used by UIForAnySwing.withStyle(sprouts.Val, swingtree.animation.LifeTime, AnimatedItemStyler),
where every change of the bound property item restarts a transition animation whose
AnimationStatus.progress() runs from 0 to 1 over the given
LifeTime. This allows a style to not only follow the
application state, but to animate towards it.
Like the ItemStyler, this function receives the property item as an explicit
argument, captured from the property change event on the property's owning thread,
which is what makes it safe to evaluate on the UI thread in the decoupled threading
mode (see EventProcessor.DECOUPLED). Never read the
property itself inside this function!
When a single AnimatedItemStyler should follow several properties at once, merge them
into one record with the composite view builder
Viewable.of(Object, java.util.function.Function) (requires Sprouts 2.7.0 or above) and
bind that one merged property, so that any of its inputs changing restarts the transition towards the
newly merged item.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault AnimatedItemStyler<T, C> andThen(AnimatedItemStyler<T, C> other) Returns a newAnimatedItemStylerthat applies the style of thisAnimatedItemStylerand then applies the style of the givenAnimatedItemStyler.static <T,C extends JComponent>
AnimatedItemStyler<T, C> none()AnAnimatedItemStylerthat does nothing, meaning it simply returns the givenComponentStyleDelegatewithout applying any style to it.style(T item, AnimationStatus status, ComponentStyleDelegate<C> delegate) Applies some style to the givenComponentStyleDelegate, usually based on the supplied property item and the progress of the suppliedAnimationStatus, and returns a newComponentStyleDelegatethat has the style applied (if any).
-
Method Details
-
none
AnAnimatedItemStylerthat does nothing, meaning it simply returns the givenComponentStyleDelegatewithout applying any style to it. Conceptually speaking, this returns the null object of theAnimatedItemStylertype.- Type Parameters:
T- The type of the item of the bound property.C- The type of theJComponentthat theComponentStyleDelegateis delegating to.- Returns:
- An
AnimatedItemStylerthat does nothing.
-
style
ComponentStyleDelegate<C> style(T item, AnimationStatus status, ComponentStyleDelegate<C> delegate) throws Exception Applies some style to the givenComponentStyleDelegate, usually based on the supplied property item and the progress of the suppliedAnimationStatus, and returns a newComponentStyleDelegatethat has the style applied (if any).
Note that this method deliberately requires the handling of checked exceptions at its invocation sites because there may be any number of implementations hiding behind this interface and so it is unwise to assume that all of them will be able to execute gracefully without throwing exceptions.- Parameters:
item- The current item of the bound property, captured from the property change event on the property's owning thread. Style based on this argument only, never on the property itself!status- TheAnimationStatusof the transition towards the supplied item, whoseAnimationStatus.progress()runs from0to1.delegate- TheComponentStyleDelegateto apply the style to.- Returns:
- A new
ComponentStyleDelegatethat has the style applied. - Throws:
Exception- if the style could not be applied by the client code.
-
andThen
Returns a newAnimatedItemStylerthat applies the style of thisAnimatedItemStylerand then applies the style of the givenAnimatedItemStyler.- Parameters:
other- theAnimatedItemStylerto apply after this one.- Returns:
- a new
AnimatedItemStylerthat applies the style of this and then the given one.
-