01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx.motion;
21 
22 import js.Disposable;
23 
24 /**
25  * <p>An abstract base class for motion definitions.</p>
26  * <p>A motion object provides stepping data after a total number of steps is initialized.</p> 
27  * <p>An object of this abstract class comes more specifically from several quite different 
28  * sources. Subclasses of the abstract {@link Regular} class are used to define a motion 
29  * object based on a basic and regular mathematical function or a combination of the regular 
30  * functions; Subclasses of the abstract {@link Interpolator} class defines a motion on a 
31  * series of sample data provided manually, with a certain interpolation method; The {@link Speed} 
32  * class defines a motion by treating an existing motion as speeds.</p>
33  * <p>The motion model is intuitive and conceptual. Its uses are not limited in animation 
34  * or visual effects. For example, using it in drawing curves of mathematics function could 
35  * be very handy.</p>
36  * 
37  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
38  * @see jsx.ui.fx.Effects
39  */
40 public abstract class Motion extends Disposable
41 {
42     private int steps;
43 
44     /**
45      * <p>The default constructor doing nothing but being invoked from a subclass.</p>
46      * @since 1.0
47      */
48     protected Motion() {}
49 
50     /**
51      * <p>Gets the datum of a float number for the specified step.</p>
52      * @param i The step number. It must be within the number of steps previously initialized 
53      * with the method {@link #init(int)}.
54      * @return The float datum for the <tt>i</tt>th step.
55      * @since 1.0
56      */
57     public abstract double get(int i);
58 
59     /**
60      * <p>Resets the motion object to provide data for a specified number of steps.</p>
61      * @param steps The total number of steps in which this motion object will provide 
62      * stepping data.
63      * @since 1.0
64      */
65     public void init(int steps) {
66         this.steps = steps;
67     }
68 
69     /**
70      * <p>Gets the total number of steps in which the specified motion object is providing 
71      * stepping data.</p>
72      * @param m The current motion object. 
73      * @return The total number of steps in which this motion object is providing data.
74      * @since 1.0
75      */
76     protected static final int steps(Motion m) {
77         return m.steps;
78     }
79 }