SAT – SWT Animation Toolkit

SWT Animation toolkit is a simple library/set of plugins which provide ready-to-use visual effects for SWT, JFace or RCP applications.

This toolkit is now part of the Eclipse Nebula project. See package org.eclipse.nebula.animation in the Nebula Gallery widget : 0.5.2 release notes, Javadoc.


Download :
Binary packages are not yet available, but you can easily add effects to your applications by downloading the code from CVS (see below)

Try it !:
The SAT Demo is available with JavaWebstart. (OSX / Tiger is not supported by SWT+JavaWebstart, sorry Mac users). Please not e that this demo is probably outdated. Check out the code to try the newer version.

Get it :

This animation toolkit is currently included in the Eclipse Nebula Gallery widget. It can be downloaded from the Nebula downloads page : just grab or use the update site.

The code is also available from Eclipse Nebula CVS :

Project: org.eclipse.swt.nebula/
Usage :

Basic example (make a shell fade in) :

new AnimationRunner().runEffect(new AlphaEffect(shell, 0 /*initial value*/, 255 /*final value*/, 4000 /*duration*/, new ExpoOut() /*movement*/, null /*run on stop*/, null /*run on cancel*/));

An AnimationRunner can run a single effect using AnimationRunner#runEffect( IEffect ). Running another effect cancels the current effect then start the new one. If you need to run several effects in parallel, just create a new AnimationRunner for each one :

// Create a AnimationRunner using the default FPS
AnimationRunner sr = new AnimationRunner();

// Create a AnimationRunner using a custom FPS
AnimationRunner sr = new AnimationRunner(25);

A movement implements a function that goes from A to B (float values). Depending of the implementations, this can be a simple movement or something that looks like an elastic.

Supported movements are :

  • LinearInOut (from A to B)
  • ExpoOut (from A to B)
  • BouceOut (from A to B)
  • ElasticOut (from A to B)
  • SinusVariation (from A to A)
  • SinusDecreaseVariation (from A to A)

Most movement can be create using a simple new the passed as parameter to an effect.

An effect implements a an action, like setting control size, alpha value; or scrollbar value.

Supported effects are :

  • AlphaEffect – Sets alpha on a Shell
  • GrowEffect – Set Control size, while keeping its center at the same place
  • MoveControlEffect – Set Control position
  • MoveScrollBarEffect – Set Scrollbar value
  • ResizeEffect – Set Control size
  • SetBoundsEffect – Both resize and move
  • SetBoundsEffect – Both resize and move
  • ShakeEffect – Shake a control, going from left to right several times

An effect usually requires several parameters, such as the control to be modified, the initial value, the target value, the duration, the movement to be used, and runnables that will be run when the effect is stopped or canceled.

Ready-to-use effects
Some effect classes provide ready-to-use effects :

// Fade Shell on close
AlphaEffect.fadeOnClose(s /*Shell*/, 2000 /*duration*/, new ExpoOut() /*movement*/);

Scrolling smoother usage:
This class replaces the standard mousewheel behavior by a nice progressive movement. Every SWT Controls is not compatible. The scrolling smoother is known to work with the following controls : Canvas, Shell, StyledText, Gallery, …

// Smooth scrolling
ScrollingSmoother s = new ScrollingSmoother(c /*control*/, new ExpoOut() /*movement*/);

// Enable custom scrolling

// Custom scrolling can be disabled later using :
// s.smoothControl(false);

To do:
Steve Northover pointed out in one of my posts about SAT, that e4 (eclipse next gen) already provides an animation API. Some work has to be done to ensure SAT and e4 API will work the same way (use e4 API for SAT if it fits). Contributions are welcome. Don’t hesitate to send me patchs or comments.