Search |
||
Java Dock with a better bouncing effectPosted by elevy on July 27, 2007 at 7:26 AM PDT
In my last blog I explained how I built a Dock bar using the Timing Framework and the Glass pane. This one is a continuation, where I explain briefly a slight improvement on the bouncing effect.
You can try the new version with Java Web Start: (again jdk 1.6+).Here is the source code under GPL. The improvement is to get the icons to bounce lower and lower after each cycle. I am pretty sure that I could have gone overboard and use some physics equations here. However, I followed the keep-it-simple principle. Instead of having one Animator object that repeats itself 6 times - 3 bounces - I created 3 different animator object. Each one goes from 0 to a different height. Then I used the Triggers available in the Timing Framework for starting the next animator after the current one is finished. I was surprised of the simplicity of the API.
TimingTrigger.addTrigger(animator[0], animator[1],
TimingTriggerEvent.STOP);
TimingTrigger.addTrigger(animator[1], animator[2],
TimingTriggerEvent.STOP);
TimingTrigger.addTrigger(animator[2], animator[3],
TimingTriggerEvent.STOP);
The other improvement I added was that after the bouncing animation is completed, I get the bar to animated into the standby state, instead of what I was doing before, which was to make the glass pane not visible. In this way it has a more smooth transition.
animator[3].addTarget(new TimingTarget() {
public void begin() {}
public void end() {
glass.disolve();
}
public void repeat() {}
public void timingEvent(float arg0) {}
});
Here you can see the disolve method:
public void disolve() {
if ((disolver == null) || (!disolver.isRunning())) {
for (int i = 0; i < iconsOnBar.size(); ++i) {
IconOnBar iconOnBar = iconsOnBar.get(i);
iconOnBar.setMouseLocation(MOUSE_OUT);
}
disolver = PropertySetter.createAnimator(500, glass,
"progress", 0f, 1f);
disolver.setAcceleration(0.3f);
disolver.setDeceleration(0.2f);
disolver.addTarget(new TimingTarget() {
public void begin() {}
public void end() {
glass.setVisible(false);
}
public void repeat() {}
public void timingEvent(float t) {}
});
disolver.start();
}
}
We just make sure that there is no other disolver animation in the works, we update the state of all the icons to be "mouse out" and start the animation. »
Related Topics >>
Java Desktop Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|