KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > task > DisplayScalingTask


1 /*
2  * DisplayScalingTask.java
3  *
4  * Created on 9 June 2003, 15:21
5  */

6
7 package com.thoughtriver.open.vectorvisuals.task;
8
9 import com.thoughtriver.open.vectorvisuals.*;
10
11 /**
12  * This task can be used to make a <CODE>VVDisplay</CODE>'s view of the
13  * vector world scale to a specific amount over a set period of time.
14  *
15  * @author Brandon Franklin
16  * @version $Date: 2006/11/25 09:15:42 $
17  */

18 public class DisplayScalingTask extends AnimationTask {
19
20     /** The <CODE>VVDisplay</CODE> that will be scaled by this task */
21     private final VVDisplay target;
22
23     /** The scale to seek */
24     private final double scale;
25
26     /** The starting scale of the view */
27     private double startingScale = 0;
28
29     /**
30      * Creates a new instance of <CODE>DisplayScalingTask</CODE> with the
31      * specified <CODE>VVDisplay</CODE> as its target, and with the supplied
32      * end-scale and duration settings.
33      *
34      * @param target the <CODE>VVDisplay</CODE> whose view will be scaled by
35      * this task
36      * @param scale the scale to end up with
37      * @param duration the number of milliseconds over which the task should
38      * occur
39      */

40     public DisplayScalingTask(final VVDisplay target, final double scale, final int duration) {
41         super(duration);
42         this.target = target;
43         this.scale = scale;
44     }
45
46     /**
47      * Called just before the first call to <CODE>update</CODE>. In this
48      * case, the method is overridden to grab the current scale of the world
49      * view.
50      */

51     @Override JavaDoc
52     protected void init() {
53         startingScale = target.getWorldViewScale();
54     }
55
56     /**
57      * Causes the task to change its state to reflect the amount of progress
58      * reported. The parameter is a double with valid values between 0.0 and
59      * 1.0.
60      *
61      * @param progress the amount of progress this <CODE>AnimationTask</CODE>
62      * should be changed to reflect
63      */

64     @Override JavaDoc
65     protected void update(final double progress) {
66         double scaleDiff = scale - startingScale;
67         target.setWorldViewScale((scaleDiff * progress) + startingScale);
68     }
69
70 }
71
Popular Tags