Animation: onStart method
Sebastian Rheinnecker
sebastian.rheinnecker at yworks.com
Fri May 10 01:00:10 PDT 2013
Hi Martin,
thanks for the clarification. The issue is promising, but the fixed
version is "Van Ness". I don't know which version this code name is
referencing to, but my guess is that it's beyond Javafx 8.0, so that
makes me a sad panda.
I tried to fiddle around a bit:
- Subclassing Animation and wrapping an Animation to call a handler
prior to play(): Didn't work, my Idea told me that I needed to implement
a package-private method that I couldn't call on the wrapped animation.
- Subclassing Transition and wrapping a Transition: doesn't work because
I cannot call the protected method interpolate from my wrapper.
However, I found out that the statusProperty of an animation is changing
prior to executing the animation:
(in Animation.java)
void impl_start(boolean forceSync) {
impl_sync(forceSync);
setStatus(Status.RUNNING); // <<<
clipEnvelope.start();
setCurrentRate(clipEnvelope.getCurrentRate());
lastPulse = 0;
}
called from play() via:
lastPlayedFinished = false;
impl_start(forceSync);
startReceiver(TickCalculation.fromDuration(getDelay()));
So I tried to bind a ChangeListener to the statusProperty of the
animation and waited for changes to "RUNNING". In my local test this was
satisfying:
ft = new Transition(){
{
setCycleDuration(Duration.millis(2000));
}
@Override
protected void interpolate(double frac) {
System.out.println("interpolating");
}
};
ft.statusProperty().addListener(new
ChangeListener<Animation.Status>() {
@Override
public void changed(ObservableValue<? extends Animation.Status>
observable, Animation.Status oldValue, Animation.Status newValue) {
if (newValue.equals(Animation.Status.RUNNING)){
System.out.println("starting");
}
}
});
ft.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("finished");
}
});
-->
starting
interpolating
interpolating
(...)
interpolating
interpolating
finished
But I didn't try it in my real application yet and I'm not sure if this
listener really gets called prior to starting the animation or not.
Would do you think?
Kind regards,
Sebastian
Am 10.05.2013 09:28, schrieb Martin Sladecek:
> Hi Sebastian,
>
> This is currently not possible. There's a JIRA issue for more
> Animation/Transition events here:
> https://javafx-jira.kenai.com/browse/RT-14455, so don't forget to vote
> for it ;-).
>
> Unfortunately, there's no reasonable workaround. One dirty fix might
> be wrapping such animation in a ParallelTransition, with a 0-length
> Timeline before it, putting the code in the it's onFinishedProperty.
>
> Regards,
> -Martin
>
> On 05/10/2013 09:09 AM, Sebastian Rheinnecker wrote:
>> Hello,
>>
>> is there something like an onStart property in Animation, just like
>> onFinished? Currently, if I want to do some stuff prior to executing
>> a Transition, for example, I have to do something like
>>
>> void playTranisition(){
>> doStuff();
>> doSomeOtherStuff();
>> transition.play();
>> }
>>
>> Where as
>>
>> transition.onStartPropery().set(new EventHandler<ActionEvent>() {
>> @Override
>> public void handle(ActionEvent event) {
>> doStuff();
>> doSomeOtherStuff();
>> }
>> });
>>
>> would be far more convenient, since I could use this together with
>> SequentialTransition and ParallelTransition and the like. Currently,
>> I have to set a Handler on the onFinishedProperty of the preceding
>> Transition (which blows up the code and leads to complicated adding
>> and removing the listeners).
>> Or am I missing something here?
>>
>> Kind regards,
>>
>> Sebastian
>>
>
--
Sebastian Rheinnecker
phone: +49 7071 9709050
fax: +49 7071 9709051
yWorks GmbH
Vor dem Kreuzberg 28
72070 Tuebingen
Germany
http://www.yworks.com
Managing Directors: Sebastian Müller, Michael Pfahler
Commercial Registry: Stuttgart, Germany, HRB 382340
More information about the openjfx-dev
mailing list