1 /*
2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
174 * The parameter defines the current position with the animation. At the
175 * start, the fraction will be {@code 0.0} and at the end it will be
176 * {@code 1.0}. How the parameter increases, depends on the
177 * {@link #interpolatorProperty() interpolator}, e.g. if the
178 * {@code interpolator} is {@link Interpolator#LINEAR}, the fraction will
179 * increase linear.
180 *
181 * This method must not be called by the user directly.
182 *
183 * @param frac
184 * The relative position
185 */
186 protected abstract void interpolate(double frac);
187
188 private double calculateFraction(long currentTicks, long cycleTicks) {
189 final double frac = cycleTicks <= 0 ? 1.0 : (double) currentTicks / cycleTicks;
190 return cachedInterpolator.interpolate(0.0, 1.0, frac);
191 }
192
193 @Override
194 boolean impl_startable(boolean forceSync) {
195 return super.impl_startable(forceSync)
196 && ((getInterpolator() != null) || (!forceSync && (cachedInterpolator != null)));
197 }
198
199 @Override
200 void impl_sync(boolean forceSync) {
201 super.impl_sync(forceSync);
202 if (forceSync || (cachedInterpolator == null)) {
203 cachedInterpolator = getInterpolator();
204 }
205 }
206
207 @Override
208 void impl_playTo(long currentTicks, long cycleTicks) {
209 impl_setCurrentTicks(currentTicks);
210 interpolate(calculateFraction(currentTicks, cycleTicks));
211 }
212
213 @Override
214 void impl_jumpTo(long currentTicks, long cycleTicks, boolean forceJump) {
215 impl_setCurrentTicks(currentTicks);
216 if (getStatus() != Status.STOPPED || forceJump) {
217 impl_sync(false);
218 interpolate(calculateFraction(currentTicks, cycleTicks));
219 }
220 }
221 }
|
1 /*
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
174 * The parameter defines the current position with the animation. At the
175 * start, the fraction will be {@code 0.0} and at the end it will be
176 * {@code 1.0}. How the parameter increases, depends on the
177 * {@link #interpolatorProperty() interpolator}, e.g. if the
178 * {@code interpolator} is {@link Interpolator#LINEAR}, the fraction will
179 * increase linear.
180 *
181 * This method must not be called by the user directly.
182 *
183 * @param frac
184 * The relative position
185 */
186 protected abstract void interpolate(double frac);
187
188 private double calculateFraction(long currentTicks, long cycleTicks) {
189 final double frac = cycleTicks <= 0 ? 1.0 : (double) currentTicks / cycleTicks;
190 return cachedInterpolator.interpolate(0.0, 1.0, frac);
191 }
192
193 @Override
194 boolean startable(boolean forceSync) {
195 return super.startable(forceSync)
196 && ((getInterpolator() != null) || (!forceSync && (cachedInterpolator != null)));
197 }
198
199 @Override
200 void sync(boolean forceSync) {
201 super.sync(forceSync);
202 if (forceSync || (cachedInterpolator == null)) {
203 cachedInterpolator = getInterpolator();
204 }
205 }
206
207 @Override
208 void doPlayTo(long currentTicks, long cycleTicks) {
209 setCurrentTicks(currentTicks);
210 interpolate(calculateFraction(currentTicks, cycleTicks));
211 }
212
213 @Override
214 void doJumpTo(long currentTicks, long cycleTicks, boolean forceJump) {
215 setCurrentTicks(currentTicks);
216 if (getStatus() != Status.STOPPED || forceJump) {
217 sync(false);
218 interpolate(calculateFraction(currentTicks, cycleTicks));
219 }
220 }
221 }
|