FileDocCategorySizeDatePackage
LinearAnimator.javaAPI DocAzureus 3.0.3.42842Tue Feb 14 07:02:40 GMT 2006org.gudy.azureus2.ui.swt.animations.shell

LinearAnimator

public class LinearAnimator extends org.gudy.azureus2.ui.swt.animations.Animator
author
Olivier Chalouhi

Fields Summary
private AnimableShell
shell
private org.eclipse.swt.widgets.Display
display
private int
startX
private int
startY
private int
endX
private int
endY
private int
nbSteps
private int
period
private boolean
interrupted
Constructors Summary
public LinearAnimator(AnimableShell shell, org.eclipse.swt.graphics.Point start, org.eclipse.swt.graphics.Point end, int nbSteps, int period)

    super("Linear Shell Animator");
    if(period < 20) period = 20;
    if(nbSteps <= 0) nbSteps = 1;
    this.shell = shell;
    this.display = shell.getShell().getDisplay();
    
    this.startX = start.x;
    this.startY = start.y;
    
    this.endX = end.x;
    this.endY = end.y;
    
    this.nbSteps = nbSteps;
    this.period = period;    
    
    this.interrupted = false;
  
Methods Summary
public voidinterrupt()

    this.interrupted = true;
  
public voidrunSupport()

  	try {
	    shell.animationStarted(this);
	    int step = 0;
	    while(step <= nbSteps && !interrupted) {
	      setShellAtStep(step);
	      shell.reportPercent(100 * step  /nbSteps);
	      step++;
	      try {
	        Thread.sleep(period);
	      } catch(Exception e) {
	        //Stop animating
	        step = nbSteps;
	      }
	    }
  	} finally {
  		shell.animationEnded(this);
  	}
  
private voidsetShellAtStep(int step)

    if(display == null || display.isDisposed())
      return;
    final int x = startX + ((endX - startX) * step ) / nbSteps;
    final int y = startY + ((endY - startY) * step ) / nbSteps;
    display.asyncExec(new AERunnable() {
      public void runSupport() {
        if(shell == null || shell.getShell() == null || shell.getShell().isDisposed())
          return;
        shell.getShell().setLocation(x,y);
      }    
    });