Skip to main content

Access to the events when using Triggers

2 replies [Last post]
rah003
Offline
Joined: 2004-05-26
Points: 0

Hi Chet,

would it be possible to make event that triggered start of the animation available to the TimingTarget? It would be enough if the event is visible for (or supplied to) begin() and end() methods only.
I think it would be fairly easy to do with simple change to Trigger and Animator. Would you accept any code submissions going in that direction?

Cheers,
Jan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chet
Offline
Joined: 2003-08-07
Points: 0

I'm not sure I follow - can you supply a snippet that illustrates what you want?

rah003
Offline
Joined: 2004-05-26
Points: 0

Suppose I want to have a transition between two screens which can go in both directions - from first screen to the second and back
A -> B and B -> A. The transition is more complex then just reversing the animator and setting value for alpha or something in other direction. I've got a button on each screen and use ActionTrigger.addTrigger(buttonA, animator) and ActionTrigger.addTrigger(buttonB, animator) to allow same animation (transition between screens) to be triggered from both screens.
Now in the begin() method I need to setup next screen and I need to know whether I'm about to do A -> B or B -> A transition. If I had the ActionEvent that triggered the animation start, I could easily figure it out. Without it, I'm stack to either have two separate animators, doing more less the same job just in other direction, or to add ActionListener for each of the buttons and set some flag on the parent class, etc. In essence without the event to tell me what to do next I can't have that code completely hidden inside of the TimingTarget implementation.

It seems to be fairly simple to propagate the event to the begin method.
- both fire() methods of the Trigger has to be extended to propage triggering event (or null in case of timing trigger)
[code]
protected void fire(TriggerEvent currentEvent, Object originalEvent) {
...
}
protected void fire(Object event) {
if (disarmed) {
return;
}
if (animator.isRunning()) {
animator.stop();
}
animator.start(event);
}
[/code]
- Animator.start() has to take that event and propagate it to all Targets in the begin()
[code]
public void start(Object event) {
this.event = event;
start();
}
private void begin() {
synchronized (targets) {
for (int i = 0; i < targets.size(); ++i) {
TimingTarget target = targets.get(i);
target.begin(event);
}
}
}
[/code]
- TimingTarget has to have a new method
[code]
begin(Object event);
[/code]
- TimingTargetAdapter can be extended to call original begin() method
[code]
public void begin(Object event) {
begin()
}
[/code]
so all the stuff that uses original begin() method still gets called and doesn't need to be modified. Anyone implementing TimingTarget by themselves would have to use begin(Object event) method.

It seems to work quite nicely and I get exactly what i need in the begin method - origin of the trigger without maintaining it manually outside. What I'm not sure is how it fits into what you have in mind with the framework or whether there is a better way. I've got all code modified locally including fixing all of your demos affected by the change. I can pack it and send it to you for review if you want.
Suggestions and opinions welcome.