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
23 * questions.
24 */
25
26 package javafx.animation;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertNull;
31 import static org.junit.Assert.assertTrue;
32 import javafx.scene.Node;
33 import javafx.scene.shape.Rectangle;
34 import javafx.util.Duration;
35
36 import org.junit.Before;
37 import org.junit.Test;
38
39 public class TranslateTransitionTest {
40
41 private static Duration DEFAULT_DURATION = Duration.millis(400);
42 private static Interpolator DEFAULT_INTERPOLATOR = Interpolator.EASE_BOTH;
43
44 private static double EPSILON = 1e-12;
45 private static Duration ONE_SEC = Duration.millis(1000);
46 private static Duration TWO_SECS = Duration.millis(2000);
47
148 assertTrue(Double.isNaN(t2.toYProperty().get()));
149 assertTrue(Double.isNaN(t2.toZProperty().get()));
150 assertEquals(0.0, t2.byXProperty().get(), EPSILON);
151 assertEquals(0.0, t2.byYProperty().get(), EPSILON);
152 assertEquals(0.0, t2.byZProperty().get(), EPSILON);
153 assertEquals(node, t2.nodeProperty().get());
154 assertEquals(DEFAULT_INTERPOLATOR, t2.interpolatorProperty().get());
155 assertNull(t2.onFinishedProperty().get());
156 }
157
158 @Test
159 public void testInterpolate() {
160 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
161 t0.setFromX(0.5);
162 t0.setToX(1.0);
163 t0.setFromY(1.5);
164 t0.setToY(2.0);
165 t0.setFromZ(1.5);
166 t0.setToZ(0.5);
167
168 assertTrue(t0.impl_startable(true));
169 t0.impl_start(true);
170 t0.interpolate(0.0);
171 assertEquals(0.5, node.getTranslateX(), EPSILON);
172 assertEquals(1.5, node.getTranslateY(), EPSILON);
173 assertEquals(1.5, node.getTranslateZ(), EPSILON);
174 t0.interpolate(0.4);
175 assertEquals(0.7, node.getTranslateX(), EPSILON);
176 assertEquals(1.7, node.getTranslateY(), EPSILON);
177 assertEquals(1.1, node.getTranslateZ(), EPSILON);
178 t0.interpolate(1.0);
179 assertEquals(1.0, node.getTranslateX(), EPSILON);
180 assertEquals(2.0, node.getTranslateY(), EPSILON);
181 assertEquals(0.5, node.getTranslateZ(), EPSILON);
182 t0.impl_finished();
183 }
184
185 @Test
186 public void testXValueCombinations() {
187 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
188 final double originalValue = 0.6;
189 final double fromValue = 0.4;
190 final double toValue = 0.9;
191 final double byValue = -0.2;
192
193 // no value set
194 node.setTranslateX(originalValue);
195 t0.setFromX(Double.NaN);
196 t0.setToX(Double.NaN);
197 t0.setByX(0.0);
198 assertTrue(t0.impl_startable(true));
199 t0.impl_start(true);
200 t0.interpolate(0.0);
201 assertEquals(originalValue, node.getTranslateX(), EPSILON);
202 t0.interpolate(1.0);
203 assertEquals(originalValue, node.getTranslateX(), EPSILON);
204 t0.impl_finished();
205
206 // only from-value set
207 node.setTranslateX(originalValue);
208 t0.setFromX(fromValue);
209 t0.setToX(Double.NaN);
210 t0.setByX(0.0);
211 assertTrue(t0.impl_startable(true));
212 t0.impl_start(true);
213 t0.interpolate(0.0);
214 assertEquals(fromValue, node.getTranslateX(), EPSILON);
215 t0.interpolate(1.0);
216 assertEquals(fromValue, node.getTranslateX(), EPSILON);
217 t0.impl_finished();
218
219 // only to-value set
220 node.setTranslateX(originalValue);
221 t0.setFromX(Double.NaN);
222 t0.setToX(toValue);
223 t0.setByX(0.0);
224 assertTrue(t0.impl_startable(true));
225 t0.impl_start(true);
226 t0.interpolate(0.0);
227 assertEquals(originalValue, node.getTranslateX(), EPSILON);
228 t0.interpolate(1.0);
229 assertEquals(toValue, node.getTranslateX(), EPSILON);
230 t0.impl_finished();
231
232 // only by-value set
233 node.setTranslateX(originalValue);
234 t0.setFromX(Double.NaN);
235 t0.setToX(Double.NaN);
236 t0.setByX(byValue);
237 assertTrue(t0.impl_startable(true));
238 t0.impl_start(true);
239 t0.interpolate(0.0);
240 assertEquals(originalValue, node.getTranslateX(), EPSILON);
241 t0.interpolate(1.0);
242 assertEquals(originalValue + byValue, node.getTranslateX(), EPSILON);
243 t0.impl_finished();
244
245 // from- and to-values set
246 node.setTranslateX(originalValue);
247 t0.setFromX(fromValue);
248 t0.setToX(toValue);
249 t0.setByX(0.0);
250 assertTrue(t0.impl_startable(true));
251 t0.impl_start(true);
252 t0.interpolate(0.0);
253 assertEquals(fromValue, node.getTranslateX(), EPSILON);
254 t0.interpolate(1.0);
255 assertEquals(toValue, node.getTranslateX(), EPSILON);
256 t0.impl_finished();
257
258 // from- and by-values set
259 node.setTranslateX(originalValue);
260 t0.setFromX(fromValue);
261 t0.setToX(Double.NaN);
262 t0.setByX(byValue);
263 assertTrue(t0.impl_startable(true));
264 t0.impl_start(true);
265 t0.interpolate(0.0);
266 assertEquals(fromValue, node.getTranslateX(), EPSILON);
267 t0.interpolate(1.0);
268 assertEquals(fromValue + byValue, node.getTranslateX(), EPSILON);
269 t0.impl_finished();
270
271 // to- and by-values set
272 node.setTranslateX(originalValue);
273 t0.setFromX(Double.NaN);
274 t0.setToX(toValue);
275 t0.setByX(byValue);
276 assertTrue(t0.impl_startable(true));
277 t0.impl_start(true);
278 t0.interpolate(0.0);
279 assertEquals(originalValue, node.getTranslateX(), EPSILON);
280 t0.interpolate(1.0);
281 assertEquals(toValue, node.getTranslateX(), EPSILON);
282 t0.impl_finished();
283
284 // all values set
285 node.setTranslateX(originalValue);
286 t0.setFromX(fromValue);
287 t0.setToX(toValue);
288 t0.setByX(byValue);
289 assertTrue(t0.impl_startable(true));
290 t0.impl_start(true);
291 t0.interpolate(0.0);
292 assertEquals(fromValue, node.getTranslateX(), EPSILON);
293 t0.interpolate(1.0);
294 assertEquals(toValue, node.getTranslateX(), EPSILON);
295 t0.impl_finished();
296 }
297
298 @Test
299 public void testYValueCombinations() {
300 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
301 final double originalValue = 0.6;
302 final double fromValue = 0.4;
303 final double toValue = 0.9;
304 final double byValue = -0.2;
305
306 // no value set
307 node.setTranslateY(originalValue);
308 t0.setFromY(Double.NaN);
309 t0.setToY(Double.NaN);
310 t0.setByY(0.0);
311 assertTrue(t0.impl_startable(true));
312 t0.impl_start(true);
313 t0.interpolate(0.0);
314 assertEquals(originalValue, node.getTranslateY(), EPSILON);
315 t0.interpolate(1.0);
316 assertEquals(originalValue, node.getTranslateY(), EPSILON);
317 t0.impl_finished();
318
319 // only from-value set
320 node.setTranslateY(originalValue);
321 t0.setFromY(fromValue);
322 t0.setToY(Double.NaN);
323 t0.setByY(0.0);
324 assertTrue(t0.impl_startable(true));
325 t0.impl_start(true);
326 t0.interpolate(0.0);
327 assertEquals(fromValue, node.getTranslateY(), EPSILON);
328 t0.interpolate(1.0);
329 assertEquals(fromValue, node.getTranslateY(), EPSILON);
330 t0.impl_finished();
331
332 // only to-value set
333 node.setTranslateY(originalValue);
334 t0.setFromY(Double.NaN);
335 t0.setToY(toValue);
336 t0.setByY(0.0);
337 assertTrue(t0.impl_startable(true));
338 t0.impl_start(true);
339 t0.interpolate(0.0);
340 assertEquals(originalValue, node.getTranslateY(), EPSILON);
341 t0.interpolate(1.0);
342 assertEquals(toValue, node.getTranslateY(), EPSILON);
343 t0.impl_finished();
344
345 // only by-value set
346 node.setTranslateY(originalValue);
347 t0.setFromY(Double.NaN);
348 t0.setToY(Double.NaN);
349 t0.setByY(byValue);
350 assertTrue(t0.impl_startable(true));
351 t0.impl_start(true);
352 t0.interpolate(0.0);
353 assertEquals(originalValue, node.getTranslateY(), EPSILON);
354 t0.interpolate(1.0);
355 assertEquals(originalValue + byValue, node.getTranslateY(), EPSILON);
356 t0.impl_finished();
357
358 // from- and to-values set
359 node.setTranslateY(originalValue);
360 t0.setFromY(fromValue);
361 t0.setToY(toValue);
362 t0.setByY(0.0);
363 assertTrue(t0.impl_startable(true));
364 t0.impl_start(true);
365 t0.interpolate(0.0);
366 assertEquals(fromValue, node.getTranslateY(), EPSILON);
367 t0.interpolate(1.0);
368 assertEquals(toValue, node.getTranslateY(), EPSILON);
369 t0.impl_finished();
370
371 // from- and by-values set
372 node.setTranslateY(originalValue);
373 t0.setFromY(fromValue);
374 t0.setToY(Double.NaN);
375 t0.setByY(byValue);
376 assertTrue(t0.impl_startable(true));
377 t0.impl_start(true);
378 t0.interpolate(0.0);
379 assertEquals(fromValue, node.getTranslateY(), EPSILON);
380 t0.interpolate(1.0);
381 assertEquals(fromValue + byValue, node.getTranslateY(), EPSILON);
382 t0.impl_finished();
383
384 // to- and by-values set
385 node.setTranslateY(originalValue);
386 t0.setFromY(Double.NaN);
387 t0.setToY(toValue);
388 t0.setByY(byValue);
389 assertTrue(t0.impl_startable(true));
390 t0.impl_start(true);
391 t0.interpolate(0.0);
392 assertEquals(originalValue, node.getTranslateY(), EPSILON);
393 t0.interpolate(1.0);
394 assertEquals(toValue, node.getTranslateY(), EPSILON);
395 t0.impl_finished();
396
397 // all values set
398 node.setTranslateY(originalValue);
399 t0.setFromY(fromValue);
400 t0.setToY(toValue);
401 t0.setByY(byValue);
402 assertTrue(t0.impl_startable(true));
403 t0.impl_start(true);
404 t0.interpolate(0.0);
405 assertEquals(fromValue, node.getTranslateY(), EPSILON);
406 t0.interpolate(1.0);
407 assertEquals(toValue, node.getTranslateY(), EPSILON);
408 t0.impl_finished();
409 }
410
411 @Test
412 public void testZValueCombinations() {
413 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
414 final double originalValue = 0.6;
415 final double fromValue = 0.4;
416 final double toValue = 0.9;
417 final double byValue = -0.2;
418
419 // no value set
420 node.setTranslateZ(originalValue);
421 t0.setFromZ(Double.NaN);
422 t0.setToZ(Double.NaN);
423 t0.setByZ(0.0);
424 assertTrue(t0.impl_startable(true));
425 t0.impl_start(true);
426 t0.interpolate(0.0);
427 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
428 t0.interpolate(1.0);
429 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
430 t0.impl_finished();
431
432 // only from-value set
433 node.setTranslateZ(originalValue);
434 t0.setFromZ(fromValue);
435 t0.setToZ(Double.NaN);
436 t0.setByZ(0.0);
437 assertTrue(t0.impl_startable(true));
438 t0.impl_start(true);
439 t0.interpolate(0.0);
440 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
441 t0.interpolate(1.0);
442 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
443 t0.impl_finished();
444
445 // only to-value set
446 node.setTranslateZ(originalValue);
447 t0.setFromZ(Double.NaN);
448 t0.setToZ(toValue);
449 t0.setByZ(0.0);
450 assertTrue(t0.impl_startable(true));
451 t0.impl_start(true);
452 t0.interpolate(0.0);
453 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
454 t0.interpolate(1.0);
455 assertEquals(toValue, node.getTranslateZ(), EPSILON);
456 t0.impl_finished();
457
458 // only by-value set
459 node.setTranslateZ(originalValue);
460 t0.setFromZ(Double.NaN);
461 t0.setToZ(Double.NaN);
462 t0.setByZ(byValue);
463 assertTrue(t0.impl_startable(true));
464 t0.impl_start(true);
465 t0.interpolate(0.0);
466 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
467 t0.interpolate(1.0);
468 assertEquals(originalValue + byValue, node.getTranslateZ(), EPSILON);
469 t0.impl_finished();
470
471 // from- and to-values set
472 node.setTranslateZ(originalValue);
473 t0.setFromZ(fromValue);
474 t0.setToZ(toValue);
475 t0.setByZ(0.0);
476 assertTrue(t0.impl_startable(true));
477 t0.impl_start(true);
478 t0.interpolate(0.0);
479 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
480 t0.interpolate(1.0);
481 assertEquals(toValue, node.getTranslateZ(), EPSILON);
482 t0.impl_finished();
483
484 // from- and by-values set
485 node.setTranslateZ(originalValue);
486 t0.setFromZ(fromValue);
487 t0.setToZ(Double.NaN);
488 t0.setByZ(byValue);
489 assertTrue(t0.impl_startable(true));
490 t0.impl_start(true);
491 t0.interpolate(0.0);
492 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
493 t0.interpolate(1.0);
494 assertEquals(fromValue + byValue, node.getTranslateZ(), EPSILON);
495 t0.impl_finished();
496
497 // to- and by-values set
498 node.setTranslateZ(originalValue);
499 t0.setFromZ(Double.NaN);
500 t0.setToZ(toValue);
501 t0.setByZ(byValue);
502 assertTrue(t0.impl_startable(true));
503 t0.impl_start(true);
504 t0.interpolate(0.0);
505 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
506 t0.interpolate(1.0);
507 assertEquals(toValue, node.getTranslateZ(), EPSILON);
508 t0.impl_finished();
509
510 // all values set
511 node.setTranslateZ(originalValue);
512 t0.setFromZ(fromValue);
513 t0.setToZ(toValue);
514 t0.setByZ(byValue);
515 assertTrue(t0.impl_startable(true));
516 t0.impl_start(true);
517 t0.interpolate(0.0);
518 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
519 t0.interpolate(1.0);
520 assertEquals(toValue, node.getTranslateZ(), EPSILON);
521 t0.impl_finished();
522 }
523
524 @Test
525 public void testGetTargetNode() {
526 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
527 t0.setInterpolator(Interpolator.LINEAR);
528 t0.setFromX(0.5);
529 t0.setToX(1.0);
530 final Rectangle node2 = new Rectangle();
531 final ParallelTransition pt = new ParallelTransition();
532 pt.getChildren().add(t0);
533 pt.setNode(node2);
534
535 // node set, parent set
536 assertTrue(t0.impl_startable(true));
537 t0.impl_start(true);
538 t0.interpolate(0.5);
539 assertEquals(0.75, node.getTranslateX(), EPSILON);
540 assertEquals(0.0, node2.getTranslateX(), EPSILON);
541 t0.impl_finished();
542
543 // node null, parent set
544 t0.setNode(null);
545 assertTrue(t0.impl_startable(true));
546 t0.impl_start(true);
547 t0.interpolate(0.4);
548 assertEquals(0.75, node.getTranslateX(), EPSILON);
549 assertEquals(0.7, node2.getTranslateX(), EPSILON);
550 t0.impl_finished();
551
552 // node null, parent null
553 pt.setNode(null);
554 assertFalse(t0.impl_startable(true));
555 }
556
557 @Test
558 public void testCachedValues() {
559 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
560 t0.setInterpolator(Interpolator.LINEAR);
561 t0.setFromX(0.5);
562 t0.setToX(1.0);
563 t0.setFromY(1.5);
564 t0.setToY(2.0);
565 t0.setFromZ(1.5);
566 t0.setToZ(0.5);
567
568 // start
569 assertTrue(t0.impl_startable(true));
570 t0.impl_start(true);
571 t0.setFromX(0.0);
572 t0.setFromY(-1.0);
573 t0.setFromZ(0.5);
574 t0.interpolate(0.5);
575 assertEquals(0.75, node.getTranslateX(), EPSILON);
576 assertEquals(1.75, node.getTranslateY(), EPSILON);
577 assertEquals(1.0, node.getTranslateZ(), EPSILON);
578 t0.impl_finished();
579 t0.setFromX(0.5);
580 t0.setFromY(1.5);
581 t0.setFromZ(1.5);
582
583 // end
584 assertTrue(t0.impl_startable(true));
585 t0.impl_start(true);
586 t0.setToX(0.0);
587 t0.setFromY(-1.0);
588 t0.setFromZ(1.5);
589 t0.interpolate(0.2);
590 assertEquals(0.6, node.getTranslateX(), EPSILON);
591 assertEquals(1.6, node.getTranslateY(), EPSILON);
592 assertEquals(1.3, node.getTranslateZ(), EPSILON);
593 t0.impl_finished();
594 t0.setToX(1.0);
595 t0.setToY(2.0);
596 t0.setToZ(0.5);
597
598 // node
599 assertTrue(t0.impl_startable(true));
600 t0.impl_start(true);
601 t0.setNode(null);
602 t0.interpolate(0.7);
603 assertEquals(0.85, node.getTranslateX(), EPSILON);
604 t0.impl_finished();
605 t0.setNode(node);
606
607 // interpolator
608 assertTrue(t0.impl_startable(true));
609 t0.impl_start(true);
610 t0.setInterpolator(null);
611 t0.interpolate(0.1);
612 assertEquals(0.55, node.getTranslateX(), EPSILON);
613 t0.impl_finished();
614 t0.setInterpolator(Interpolator.LINEAR);
615 }
616
617 @Test
618 public void testStartable() {
619 final TranslateTransition t0 = new TranslateTransition(Duration.ONE, node);
620 assertTrue(t0.impl_startable(true));
621
622 // duration is 0
623 t0.setDuration(Duration.ZERO);
624 assertFalse(t0.impl_startable(true));
625 t0.setDuration(Duration.ONE);
626 assertTrue(t0.impl_startable(true));
627
628 // node is null
629 t0.setNode(null);
630 assertFalse(t0.impl_startable(true));
631 t0.setNode(node);
632 assertTrue(t0.impl_startable(true));
633
634 // interpolator is null
635 t0.setInterpolator(null);
636 assertFalse(t0.impl_startable(true));
637 t0.setInterpolator(Interpolator.LINEAR);
638 assertTrue(t0.impl_startable(true));
639 }
640
641 @Test
642 public void testEvaluateStartValue() {
643 final TranslateTransition t0 = new TranslateTransition(Duration.INDEFINITE, node);
644 t0.setToX(2.0);
645 t0.setToY(2.0);
646 t0.setToZ(2.0);
647
648 // first run
649 node.setTranslateX( 0.6);
650 node.setTranslateY( 1.6);
651 node.setTranslateZ(-0.6);
652 assertTrue(t0.impl_startable(true));
653 t0.impl_start(true);
654 node.setTranslateX(0.8);
655 node.setTranslateY(0.8);
656 node.setTranslateZ(0.8);
657 t0.interpolate(0.0);
658 assertEquals( 0.6, node.getTranslateX(), EPSILON);
659 assertEquals( 1.6, node.getTranslateY(), EPSILON);
660 assertEquals(-0.6, node.getTranslateZ(), EPSILON);
661 t0.impl_finished();
662
663 // second run
664 node.setTranslateX( 0.2);
665 node.setTranslateY(-2.2);
666 node.setTranslateZ(11.2);
667 assertTrue(t0.impl_startable(true));
668 t0.impl_start(true);
669 node.setTranslateX(0.8);
670 node.setTranslateY(0.8);
671 node.setTranslateZ(0.8);
672 t0.interpolate(0.0);
673 assertEquals( 0.2, node.getTranslateX(), EPSILON);
674 assertEquals(-2.2, node.getTranslateY(), EPSILON);
675 assertEquals(11.2, node.getTranslateZ(), EPSILON);
676 t0.impl_finished();
677 }
678
679 }
|
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
23 * questions.
24 */
25
26 package test.javafx.animation;
27
28 import javafx.animation.AnimationShim;
29 import javafx.animation.Interpolator;
30 import javafx.animation.ParallelTransition;
31 import javafx.animation.TransitionShim;
32 import javafx.animation.TranslateTransition;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertNull;
36 import static org.junit.Assert.assertTrue;
37 import javafx.scene.Node;
38 import javafx.scene.shape.Rectangle;
39 import javafx.util.Duration;
40
41 import org.junit.Before;
42 import org.junit.Test;
43
44 public class TranslateTransitionTest {
45
46 private static Duration DEFAULT_DURATION = Duration.millis(400);
47 private static Interpolator DEFAULT_INTERPOLATOR = Interpolator.EASE_BOTH;
48
49 private static double EPSILON = 1e-12;
50 private static Duration ONE_SEC = Duration.millis(1000);
51 private static Duration TWO_SECS = Duration.millis(2000);
52
153 assertTrue(Double.isNaN(t2.toYProperty().get()));
154 assertTrue(Double.isNaN(t2.toZProperty().get()));
155 assertEquals(0.0, t2.byXProperty().get(), EPSILON);
156 assertEquals(0.0, t2.byYProperty().get(), EPSILON);
157 assertEquals(0.0, t2.byZProperty().get(), EPSILON);
158 assertEquals(node, t2.nodeProperty().get());
159 assertEquals(DEFAULT_INTERPOLATOR, t2.interpolatorProperty().get());
160 assertNull(t2.onFinishedProperty().get());
161 }
162
163 @Test
164 public void testInterpolate() {
165 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
166 t0.setFromX(0.5);
167 t0.setToX(1.0);
168 t0.setFromY(1.5);
169 t0.setToY(2.0);
170 t0.setFromZ(1.5);
171 t0.setToZ(0.5);
172
173 assertTrue(AnimationShim.impl_startable(t0,true));
174 AnimationShim.impl_start(t0,true);
175 TransitionShim.interpolate(t0,0.0);
176 assertEquals(0.5, node.getTranslateX(), EPSILON);
177 assertEquals(1.5, node.getTranslateY(), EPSILON);
178 assertEquals(1.5, node.getTranslateZ(), EPSILON);
179 TransitionShim.interpolate(t0,0.4);
180 assertEquals(0.7, node.getTranslateX(), EPSILON);
181 assertEquals(1.7, node.getTranslateY(), EPSILON);
182 assertEquals(1.1, node.getTranslateZ(), EPSILON);
183 TransitionShim.interpolate(t0,1.0);
184 assertEquals(1.0, node.getTranslateX(), EPSILON);
185 assertEquals(2.0, node.getTranslateY(), EPSILON);
186 assertEquals(0.5, node.getTranslateZ(), EPSILON);
187 AnimationShim.impl_finished(t0);
188 }
189
190 @Test
191 public void testXValueCombinations() {
192 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
193 final double originalValue = 0.6;
194 final double fromValue = 0.4;
195 final double toValue = 0.9;
196 final double byValue = -0.2;
197
198 // no value set
199 node.setTranslateX(originalValue);
200 t0.setFromX(Double.NaN);
201 t0.setToX(Double.NaN);
202 t0.setByX(0.0);
203 assertTrue(AnimationShim.impl_startable(t0,true));
204 AnimationShim.impl_start(t0,true);
205 TransitionShim.interpolate(t0,0.0);
206 assertEquals(originalValue, node.getTranslateX(), EPSILON);
207 TransitionShim.interpolate(t0,1.0);
208 assertEquals(originalValue, node.getTranslateX(), EPSILON);
209 AnimationShim.impl_finished(t0);
210
211 // only from-value set
212 node.setTranslateX(originalValue);
213 t0.setFromX(fromValue);
214 t0.setToX(Double.NaN);
215 t0.setByX(0.0);
216 assertTrue(AnimationShim.impl_startable(t0,true));
217 AnimationShim.impl_start(t0,true);
218 TransitionShim.interpolate(t0,0.0);
219 assertEquals(fromValue, node.getTranslateX(), EPSILON);
220 TransitionShim.interpolate(t0,1.0);
221 assertEquals(fromValue, node.getTranslateX(), EPSILON);
222 AnimationShim.impl_finished(t0);
223
224 // only to-value set
225 node.setTranslateX(originalValue);
226 t0.setFromX(Double.NaN);
227 t0.setToX(toValue);
228 t0.setByX(0.0);
229 assertTrue(AnimationShim.impl_startable(t0,true));
230 AnimationShim.impl_start(t0,true);
231 TransitionShim.interpolate(t0,0.0);
232 assertEquals(originalValue, node.getTranslateX(), EPSILON);
233 TransitionShim.interpolate(t0,1.0);
234 assertEquals(toValue, node.getTranslateX(), EPSILON);
235 AnimationShim.impl_finished(t0);
236
237 // only by-value set
238 node.setTranslateX(originalValue);
239 t0.setFromX(Double.NaN);
240 t0.setToX(Double.NaN);
241 t0.setByX(byValue);
242 assertTrue(AnimationShim.impl_startable(t0,true));
243 AnimationShim.impl_start(t0,true);
244 TransitionShim.interpolate(t0,0.0);
245 assertEquals(originalValue, node.getTranslateX(), EPSILON);
246 TransitionShim.interpolate(t0,1.0);
247 assertEquals(originalValue + byValue, node.getTranslateX(), EPSILON);
248 AnimationShim.impl_finished(t0);
249
250 // from- and to-values set
251 node.setTranslateX(originalValue);
252 t0.setFromX(fromValue);
253 t0.setToX(toValue);
254 t0.setByX(0.0);
255 assertTrue(AnimationShim.impl_startable(t0,true));
256 AnimationShim.impl_start(t0,true);
257 TransitionShim.interpolate(t0,0.0);
258 assertEquals(fromValue, node.getTranslateX(), EPSILON);
259 TransitionShim.interpolate(t0,1.0);
260 assertEquals(toValue, node.getTranslateX(), EPSILON);
261 AnimationShim.impl_finished(t0);
262
263 // from- and by-values set
264 node.setTranslateX(originalValue);
265 t0.setFromX(fromValue);
266 t0.setToX(Double.NaN);
267 t0.setByX(byValue);
268 assertTrue(AnimationShim.impl_startable(t0,true));
269 AnimationShim.impl_start(t0,true);
270 TransitionShim.interpolate(t0,0.0);
271 assertEquals(fromValue, node.getTranslateX(), EPSILON);
272 TransitionShim.interpolate(t0,1.0);
273 assertEquals(fromValue + byValue, node.getTranslateX(), EPSILON);
274 AnimationShim.impl_finished(t0);
275
276 // to- and by-values set
277 node.setTranslateX(originalValue);
278 t0.setFromX(Double.NaN);
279 t0.setToX(toValue);
280 t0.setByX(byValue);
281 assertTrue(AnimationShim.impl_startable(t0,true));
282 AnimationShim.impl_start(t0,true);
283 TransitionShim.interpolate(t0,0.0);
284 assertEquals(originalValue, node.getTranslateX(), EPSILON);
285 TransitionShim.interpolate(t0,1.0);
286 assertEquals(toValue, node.getTranslateX(), EPSILON);
287 AnimationShim.impl_finished(t0);
288
289 // all values set
290 node.setTranslateX(originalValue);
291 t0.setFromX(fromValue);
292 t0.setToX(toValue);
293 t0.setByX(byValue);
294 assertTrue(AnimationShim.impl_startable(t0,true));
295 AnimationShim.impl_start(t0,true);
296 TransitionShim.interpolate(t0,0.0);
297 assertEquals(fromValue, node.getTranslateX(), EPSILON);
298 TransitionShim.interpolate(t0,1.0);
299 assertEquals(toValue, node.getTranslateX(), EPSILON);
300 AnimationShim.impl_finished(t0);
301 }
302
303 @Test
304 public void testYValueCombinations() {
305 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
306 final double originalValue = 0.6;
307 final double fromValue = 0.4;
308 final double toValue = 0.9;
309 final double byValue = -0.2;
310
311 // no value set
312 node.setTranslateY(originalValue);
313 t0.setFromY(Double.NaN);
314 t0.setToY(Double.NaN);
315 t0.setByY(0.0);
316 assertTrue(AnimationShim.impl_startable(t0,true));
317 AnimationShim.impl_start(t0,true);
318 TransitionShim.interpolate(t0,0.0);
319 assertEquals(originalValue, node.getTranslateY(), EPSILON);
320 TransitionShim.interpolate(t0,1.0);
321 assertEquals(originalValue, node.getTranslateY(), EPSILON);
322 AnimationShim.impl_finished(t0);
323
324 // only from-value set
325 node.setTranslateY(originalValue);
326 t0.setFromY(fromValue);
327 t0.setToY(Double.NaN);
328 t0.setByY(0.0);
329 assertTrue(AnimationShim.impl_startable(t0,true));
330 AnimationShim.impl_start(t0,true);
331 TransitionShim.interpolate(t0,0.0);
332 assertEquals(fromValue, node.getTranslateY(), EPSILON);
333 TransitionShim.interpolate(t0,1.0);
334 assertEquals(fromValue, node.getTranslateY(), EPSILON);
335 AnimationShim.impl_finished(t0);
336
337 // only to-value set
338 node.setTranslateY(originalValue);
339 t0.setFromY(Double.NaN);
340 t0.setToY(toValue);
341 t0.setByY(0.0);
342 assertTrue(AnimationShim.impl_startable(t0,true));
343 AnimationShim.impl_start(t0,true);
344 TransitionShim.interpolate(t0,0.0);
345 assertEquals(originalValue, node.getTranslateY(), EPSILON);
346 TransitionShim.interpolate(t0,1.0);
347 assertEquals(toValue, node.getTranslateY(), EPSILON);
348 AnimationShim.impl_finished(t0);
349
350 // only by-value set
351 node.setTranslateY(originalValue);
352 t0.setFromY(Double.NaN);
353 t0.setToY(Double.NaN);
354 t0.setByY(byValue);
355 assertTrue(AnimationShim.impl_startable(t0,true));
356 AnimationShim.impl_start(t0,true);
357 TransitionShim.interpolate(t0,0.0);
358 assertEquals(originalValue, node.getTranslateY(), EPSILON);
359 TransitionShim.interpolate(t0,1.0);
360 assertEquals(originalValue + byValue, node.getTranslateY(), EPSILON);
361 AnimationShim.impl_finished(t0);
362
363 // from- and to-values set
364 node.setTranslateY(originalValue);
365 t0.setFromY(fromValue);
366 t0.setToY(toValue);
367 t0.setByY(0.0);
368 assertTrue(AnimationShim.impl_startable(t0,true));
369 AnimationShim.impl_start(t0,true);
370 TransitionShim.interpolate(t0,0.0);
371 assertEquals(fromValue, node.getTranslateY(), EPSILON);
372 TransitionShim.interpolate(t0,1.0);
373 assertEquals(toValue, node.getTranslateY(), EPSILON);
374 AnimationShim.impl_finished(t0);
375
376 // from- and by-values set
377 node.setTranslateY(originalValue);
378 t0.setFromY(fromValue);
379 t0.setToY(Double.NaN);
380 t0.setByY(byValue);
381 assertTrue(AnimationShim.impl_startable(t0,true));
382 AnimationShim.impl_start(t0,true);
383 TransitionShim.interpolate(t0,0.0);
384 assertEquals(fromValue, node.getTranslateY(), EPSILON);
385 TransitionShim.interpolate(t0,1.0);
386 assertEquals(fromValue + byValue, node.getTranslateY(), EPSILON);
387 AnimationShim.impl_finished(t0);
388
389 // to- and by-values set
390 node.setTranslateY(originalValue);
391 t0.setFromY(Double.NaN);
392 t0.setToY(toValue);
393 t0.setByY(byValue);
394 assertTrue(AnimationShim.impl_startable(t0,true));
395 AnimationShim.impl_start(t0,true);
396 TransitionShim.interpolate(t0,0.0);
397 assertEquals(originalValue, node.getTranslateY(), EPSILON);
398 TransitionShim.interpolate(t0,1.0);
399 assertEquals(toValue, node.getTranslateY(), EPSILON);
400 AnimationShim.impl_finished(t0);
401
402 // all values set
403 node.setTranslateY(originalValue);
404 t0.setFromY(fromValue);
405 t0.setToY(toValue);
406 t0.setByY(byValue);
407 assertTrue(AnimationShim.impl_startable(t0,true));
408 AnimationShim.impl_start(t0,true);
409 TransitionShim.interpolate(t0,0.0);
410 assertEquals(fromValue, node.getTranslateY(), EPSILON);
411 TransitionShim.interpolate(t0,1.0);
412 assertEquals(toValue, node.getTranslateY(), EPSILON);
413 AnimationShim.impl_finished(t0);
414 }
415
416 @Test
417 public void testZValueCombinations() {
418 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
419 final double originalValue = 0.6;
420 final double fromValue = 0.4;
421 final double toValue = 0.9;
422 final double byValue = -0.2;
423
424 // no value set
425 node.setTranslateZ(originalValue);
426 t0.setFromZ(Double.NaN);
427 t0.setToZ(Double.NaN);
428 t0.setByZ(0.0);
429 assertTrue(AnimationShim.impl_startable(t0,true));
430 AnimationShim.impl_start(t0,true);
431 TransitionShim.interpolate(t0,0.0);
432 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
433 TransitionShim.interpolate(t0,1.0);
434 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
435 AnimationShim.impl_finished(t0);
436
437 // only from-value set
438 node.setTranslateZ(originalValue);
439 t0.setFromZ(fromValue);
440 t0.setToZ(Double.NaN);
441 t0.setByZ(0.0);
442 assertTrue(AnimationShim.impl_startable(t0,true));
443 AnimationShim.impl_start(t0,true);
444 TransitionShim.interpolate(t0,0.0);
445 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
446 TransitionShim.interpolate(t0,1.0);
447 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
448 AnimationShim.impl_finished(t0);
449
450 // only to-value set
451 node.setTranslateZ(originalValue);
452 t0.setFromZ(Double.NaN);
453 t0.setToZ(toValue);
454 t0.setByZ(0.0);
455 assertTrue(AnimationShim.impl_startable(t0,true));
456 AnimationShim.impl_start(t0,true);
457 TransitionShim.interpolate(t0,0.0);
458 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
459 TransitionShim.interpolate(t0,1.0);
460 assertEquals(toValue, node.getTranslateZ(), EPSILON);
461 AnimationShim.impl_finished(t0);
462
463 // only by-value set
464 node.setTranslateZ(originalValue);
465 t0.setFromZ(Double.NaN);
466 t0.setToZ(Double.NaN);
467 t0.setByZ(byValue);
468 assertTrue(AnimationShim.impl_startable(t0,true));
469 AnimationShim.impl_start(t0,true);
470 TransitionShim.interpolate(t0,0.0);
471 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
472 TransitionShim.interpolate(t0,1.0);
473 assertEquals(originalValue + byValue, node.getTranslateZ(), EPSILON);
474 AnimationShim.impl_finished(t0);
475
476 // from- and to-values set
477 node.setTranslateZ(originalValue);
478 t0.setFromZ(fromValue);
479 t0.setToZ(toValue);
480 t0.setByZ(0.0);
481 assertTrue(AnimationShim.impl_startable(t0,true));
482 AnimationShim.impl_start(t0,true);
483 TransitionShim.interpolate(t0,0.0);
484 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
485 TransitionShim.interpolate(t0,1.0);
486 assertEquals(toValue, node.getTranslateZ(), EPSILON);
487 AnimationShim.impl_finished(t0);
488
489 // from- and by-values set
490 node.setTranslateZ(originalValue);
491 t0.setFromZ(fromValue);
492 t0.setToZ(Double.NaN);
493 t0.setByZ(byValue);
494 assertTrue(AnimationShim.impl_startable(t0,true));
495 AnimationShim.impl_start(t0,true);
496 TransitionShim.interpolate(t0,0.0);
497 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
498 TransitionShim.interpolate(t0,1.0);
499 assertEquals(fromValue + byValue, node.getTranslateZ(), EPSILON);
500 AnimationShim.impl_finished(t0);
501
502 // to- and by-values set
503 node.setTranslateZ(originalValue);
504 t0.setFromZ(Double.NaN);
505 t0.setToZ(toValue);
506 t0.setByZ(byValue);
507 assertTrue(AnimationShim.impl_startable(t0,true));
508 AnimationShim.impl_start(t0,true);
509 TransitionShim.interpolate(t0,0.0);
510 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
511 TransitionShim.interpolate(t0,1.0);
512 assertEquals(toValue, node.getTranslateZ(), EPSILON);
513 AnimationShim.impl_finished(t0);
514
515 // all values set
516 node.setTranslateZ(originalValue);
517 t0.setFromZ(fromValue);
518 t0.setToZ(toValue);
519 t0.setByZ(byValue);
520 assertTrue(AnimationShim.impl_startable(t0,true));
521 AnimationShim.impl_start(t0,true);
522 TransitionShim.interpolate(t0,0.0);
523 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
524 TransitionShim.interpolate(t0,1.0);
525 assertEquals(toValue, node.getTranslateZ(), EPSILON);
526 AnimationShim.impl_finished(t0);
527 }
528
529 @Test
530 public void testGetTargetNode() {
531 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
532 t0.setInterpolator(Interpolator.LINEAR);
533 t0.setFromX(0.5);
534 t0.setToX(1.0);
535 final Rectangle node2 = new Rectangle();
536 final ParallelTransition pt = new ParallelTransition();
537 pt.getChildren().add(t0);
538 pt.setNode(node2);
539
540 // node set, parent set
541 assertTrue(AnimationShim.impl_startable(t0,true));
542 AnimationShim.impl_start(t0,true);
543 TransitionShim.interpolate(t0,0.5);
544 assertEquals(0.75, node.getTranslateX(), EPSILON);
545 assertEquals(0.0, node2.getTranslateX(), EPSILON);
546 AnimationShim.impl_finished(t0);
547
548 // node null, parent set
549 t0.setNode(null);
550 assertTrue(AnimationShim.impl_startable(t0,true));
551 AnimationShim.impl_start(t0,true);
552 TransitionShim.interpolate(t0,0.4);
553 assertEquals(0.75, node.getTranslateX(), EPSILON);
554 assertEquals(0.7, node2.getTranslateX(), EPSILON);
555 AnimationShim.impl_finished(t0);
556
557 // node null, parent null
558 pt.setNode(null);
559 assertFalse(AnimationShim.impl_startable(t0,true));
560 }
561
562 @Test
563 public void testCachedValues() {
564 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
565 t0.setInterpolator(Interpolator.LINEAR);
566 t0.setFromX(0.5);
567 t0.setToX(1.0);
568 t0.setFromY(1.5);
569 t0.setToY(2.0);
570 t0.setFromZ(1.5);
571 t0.setToZ(0.5);
572
573 // start
574 assertTrue(AnimationShim.impl_startable(t0,true));
575 AnimationShim.impl_start(t0,true);
576 t0.setFromX(0.0);
577 t0.setFromY(-1.0);
578 t0.setFromZ(0.5);
579 TransitionShim.interpolate(t0,0.5);
580 assertEquals(0.75, node.getTranslateX(), EPSILON);
581 assertEquals(1.75, node.getTranslateY(), EPSILON);
582 assertEquals(1.0, node.getTranslateZ(), EPSILON);
583 AnimationShim.impl_finished(t0);
584 t0.setFromX(0.5);
585 t0.setFromY(1.5);
586 t0.setFromZ(1.5);
587
588 // end
589 assertTrue(AnimationShim.impl_startable(t0,true));
590 AnimationShim.impl_start(t0,true);
591 t0.setToX(0.0);
592 t0.setFromY(-1.0);
593 t0.setFromZ(1.5);
594 TransitionShim.interpolate(t0,0.2);
595 assertEquals(0.6, node.getTranslateX(), EPSILON);
596 assertEquals(1.6, node.getTranslateY(), EPSILON);
597 assertEquals(1.3, node.getTranslateZ(), EPSILON);
598 AnimationShim.impl_finished(t0);
599 t0.setToX(1.0);
600 t0.setToY(2.0);
601 t0.setToZ(0.5);
602
603 // node
604 assertTrue(AnimationShim.impl_startable(t0,true));
605 AnimationShim.impl_start(t0,true);
606 t0.setNode(null);
607 TransitionShim.interpolate(t0,0.7);
608 assertEquals(0.85, node.getTranslateX(), EPSILON);
609 AnimationShim.impl_finished(t0);
610 t0.setNode(node);
611
612 // interpolator
613 assertTrue(AnimationShim.impl_startable(t0,true));
614 AnimationShim.impl_start(t0,true);
615 t0.setInterpolator(null);
616 TransitionShim.interpolate(t0,0.1);
617 assertEquals(0.55, node.getTranslateX(), EPSILON);
618 AnimationShim.impl_finished(t0);
619 t0.setInterpolator(Interpolator.LINEAR);
620 }
621
622 @Test
623 public void testStartable() {
624 final TranslateTransition t0 = new TranslateTransition(Duration.ONE, node);
625 assertTrue(AnimationShim.impl_startable(t0,true));
626
627 // duration is 0
628 t0.setDuration(Duration.ZERO);
629 assertFalse(AnimationShim.impl_startable(t0,true));
630 t0.setDuration(Duration.ONE);
631 assertTrue(AnimationShim.impl_startable(t0,true));
632
633 // node is null
634 t0.setNode(null);
635 assertFalse(AnimationShim.impl_startable(t0,true));
636 t0.setNode(node);
637 assertTrue(AnimationShim.impl_startable(t0,true));
638
639 // interpolator is null
640 t0.setInterpolator(null);
641 assertFalse(AnimationShim.impl_startable(t0,true));
642 t0.setInterpolator(Interpolator.LINEAR);
643 assertTrue(AnimationShim.impl_startable(t0,true));
644 }
645
646 @Test
647 public void testEvaluateStartValue() {
648 final TranslateTransition t0 = new TranslateTransition(Duration.INDEFINITE, node);
649 t0.setToX(2.0);
650 t0.setToY(2.0);
651 t0.setToZ(2.0);
652
653 // first run
654 node.setTranslateX( 0.6);
655 node.setTranslateY( 1.6);
656 node.setTranslateZ(-0.6);
657 assertTrue(AnimationShim.impl_startable(t0,true));
658 AnimationShim.impl_start(t0,true);
659 node.setTranslateX(0.8);
660 node.setTranslateY(0.8);
661 node.setTranslateZ(0.8);
662 TransitionShim.interpolate(t0,0.0);
663 assertEquals( 0.6, node.getTranslateX(), EPSILON);
664 assertEquals( 1.6, node.getTranslateY(), EPSILON);
665 assertEquals(-0.6, node.getTranslateZ(), EPSILON);
666 AnimationShim.impl_finished(t0);
667
668 // second run
669 node.setTranslateX( 0.2);
670 node.setTranslateY(-2.2);
671 node.setTranslateZ(11.2);
672 assertTrue(AnimationShim.impl_startable(t0,true));
673 AnimationShim.impl_start(t0,true);
674 node.setTranslateX(0.8);
675 node.setTranslateY(0.8);
676 node.setTranslateZ(0.8);
677 TransitionShim.interpolate(t0,0.0);
678 assertEquals( 0.2, node.getTranslateX(), EPSILON);
679 assertEquals(-2.2, node.getTranslateY(), EPSILON);
680 assertEquals(11.2, node.getTranslateZ(), EPSILON);
681 AnimationShim.impl_finished(t0);
682 }
683
684 }
|