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 FadeTransitionTest {
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
108 assertEquals(DEFAULT_INTERPOLATOR, t1.interpolatorProperty().get());
109 assertNull(t1.onFinishedProperty().get());
110
111 // duration and node
112 final FadeTransition t2 = new FadeTransition(TWO_SECS, node);
113 assertEquals(TWO_SECS, t2.durationProperty().get());
114 assertTrue(Double.isNaN(t2.fromValueProperty().get()));
115 assertTrue(Double.isNaN(t2.toValueProperty().get()));
116 assertEquals(0.0, t2.byValueProperty().get(), EPSILON);
117 assertEquals(node, t2.nodeProperty().get());
118 assertEquals(DEFAULT_INTERPOLATOR, t2.interpolatorProperty().get());
119 assertNull(t2.onFinishedProperty().get());
120 }
121
122 @Test
123 public void testInterpolate() {
124 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
125 t0.setFromValue(0.5);
126 t0.setToValue(1.0);
127
128 assertTrue(t0.impl_startable(true));
129 t0.impl_start(true);
130 t0.interpolate(0.0);
131 assertEquals(0.5, node.getOpacity(), EPSILON);
132 t0.interpolate(0.4);
133 assertEquals(0.7, node.getOpacity(), EPSILON);
134 t0.interpolate(1.0);
135 assertEquals(1.0, node.getOpacity(), EPSILON);
136 t0.impl_finished();
137 }
138
139 @Test
140 public void testValueCombinations() {
141 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
142 final double originalValue = 0.6;
143 final double fromValue = 0.4;
144 final double toValue = 0.9;
145 final double byValue = -0.2;
146
147 // no value set
148 node.setOpacity(originalValue);
149 t0.setFromValue(Double.NaN);
150 t0.setToValue(Double.NaN);
151 t0.setByValue(0.0);
152 assertTrue(t0.impl_startable(true));
153 t0.impl_start(true);
154 t0.interpolate(0.0);
155 assertEquals(originalValue, node.getOpacity(), EPSILON);
156 t0.interpolate(1.0);
157 assertEquals(originalValue, node.getOpacity(), EPSILON);
158 t0.impl_finished();
159
160 // only from-value set
161 node.setOpacity(originalValue);
162 t0.setFromValue(fromValue);
163 t0.setToValue(Double.NaN);
164 t0.setByValue(0.0);
165 assertTrue(t0.impl_startable(true));
166 t0.impl_start(true);
167 t0.interpolate(0.0);
168 assertEquals(fromValue, node.getOpacity(), EPSILON);
169 t0.interpolate(1.0);
170 assertEquals(fromValue, node.getOpacity(), EPSILON);
171 t0.impl_finished();
172
173 // only to-value set
174 node.setOpacity(originalValue);
175 t0.setFromValue(Double.NaN);
176 t0.setToValue(toValue);
177 t0.setByValue(0.0);
178 assertTrue(t0.impl_startable(true));
179 t0.impl_start(true);
180 t0.interpolate(0.0);
181 assertEquals(originalValue, node.getOpacity(), EPSILON);
182 t0.interpolate(1.0);
183 assertEquals(toValue, node.getOpacity(), EPSILON);
184 t0.impl_finished();
185
186 // only by-value set
187 node.setOpacity(originalValue);
188 t0.setFromValue(Double.NaN);
189 t0.setToValue(Double.NaN);
190 t0.setByValue(byValue);
191 assertTrue(t0.impl_startable(true));
192 t0.impl_start(true);
193 t0.interpolate(0.0);
194 assertEquals(originalValue, node.getOpacity(), EPSILON);
195 t0.interpolate(1.0);
196 assertEquals(originalValue + byValue, node.getOpacity(), EPSILON);
197 t0.impl_finished();
198
199 // from- and to-values set
200 node.setOpacity(originalValue);
201 t0.setFromValue(fromValue);
202 t0.setToValue(toValue);
203 t0.setByValue(0.0);
204 assertTrue(t0.impl_startable(true));
205 t0.impl_start(true);
206 t0.interpolate(0.0);
207 assertEquals(fromValue, node.getOpacity(), EPSILON);
208 t0.interpolate(1.0);
209 assertEquals(toValue, node.getOpacity(), EPSILON);
210 t0.impl_finished();
211
212 // from- and by-values set
213 node.setOpacity(originalValue);
214 t0.setFromValue(fromValue);
215 t0.setToValue(Double.NaN);
216 t0.setByValue(byValue);
217 assertTrue(t0.impl_startable(true));
218 t0.impl_start(true);
219 t0.interpolate(0.0);
220 assertEquals(fromValue, node.getOpacity(), EPSILON);
221 t0.interpolate(1.0);
222 assertEquals(fromValue + byValue, node.getOpacity(), EPSILON);
223 t0.impl_finished();
224
225 // to- and by-values set
226 node.setOpacity(originalValue);
227 t0.setFromValue(Double.NaN);
228 t0.setToValue(toValue);
229 t0.setByValue(byValue);
230 assertTrue(t0.impl_startable(true));
231 t0.impl_start(true);
232 t0.interpolate(0.0);
233 assertEquals(originalValue, node.getOpacity(), EPSILON);
234 t0.interpolate(1.0);
235 assertEquals(toValue, node.getOpacity(), EPSILON);
236 t0.impl_finished();
237
238 // all values set
239 node.setOpacity(originalValue);
240 t0.setFromValue(fromValue);
241 t0.setToValue(toValue);
242 t0.setByValue(byValue);
243 assertTrue(t0.impl_startable(true));
244 t0.impl_start(true);
245 t0.interpolate(0.0);
246 assertEquals(fromValue, node.getOpacity(), EPSILON);
247 t0.interpolate(1.0);
248 assertEquals(toValue, node.getOpacity(), EPSILON);
249 t0.impl_finished();
250 }
251
252 @Test
253 public void testOutOfBoundValues() {
254 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
255 t0.setInterpolator(Interpolator.LINEAR);
256
257 // start < 0.0
258 t0.setFromValue(-0.4);
259 t0.setToValue(0.6);
260 assertTrue(t0.impl_startable(true));
261 t0.impl_start(true);
262 t0.interpolate(0.0);
263 assertEquals(0.0, node.getOpacity(), EPSILON);
264 t0.interpolate(0.5);
265 assertEquals(0.3, node.getOpacity(), EPSILON);
266 t0.interpolate(1.0);
267 assertEquals(0.6, node.getOpacity(), EPSILON);
268 t0.impl_finished();
269
270 // start > 1.0
271 t0.setFromValue(1.3);
272 t0.setToValue(0.3);
273 assertTrue(t0.impl_startable(true));
274 t0.impl_start(true);
275 t0.interpolate(0.0);
276 assertEquals(1.0, node.getOpacity(), EPSILON);
277 t0.interpolate(0.5);
278 assertEquals(0.65, node.getOpacity(), EPSILON);
279 t0.interpolate(1.0);
280 assertEquals(0.3, node.getOpacity(), EPSILON);
281 t0.impl_finished();
282
283 // end < 0.0
284 t0.setFromValue(0.2);
285 t0.setToValue(-1.2);
286 assertTrue(t0.impl_startable(true));
287 t0.impl_start(true);
288 t0.interpolate(0.0);
289 assertEquals(0.2, node.getOpacity(), EPSILON);
290 t0.interpolate(0.5);
291 assertEquals(0.1, node.getOpacity(), EPSILON);
292 t0.interpolate(1.0);
293 assertEquals(0.0, node.getOpacity(), EPSILON);
294 t0.impl_finished();
295
296 // end > 1.0
297 t0.setFromValue(0.9);
298 t0.setToValue(1.9);
299 assertTrue(t0.impl_startable(true));
300 t0.impl_start(true);
301 t0.interpolate(0.0);
302 assertEquals(0.9, node.getOpacity(), EPSILON);
303 t0.interpolate(0.5);
304 assertEquals(0.95, node.getOpacity(), EPSILON);
305 t0.interpolate(1.0);
306 assertEquals(1.0, node.getOpacity(), EPSILON);
307 t0.impl_finished();
308 }
309
310 @Test
311 public void testGetTargetNode() {
312 final FadeTransition ft = new FadeTransition(ONE_SEC, node);
313 ft.setInterpolator(Interpolator.LINEAR);
314 ft.setFromValue(0.5);
315 ft.setToValue(1.0);
316 final Rectangle node2 = new Rectangle();
317 final ParallelTransition pt = new ParallelTransition();
318 pt.getChildren().add(ft);
319 pt.setNode(node2);
320
321 // node set, parent set
322 assertTrue(ft.impl_startable(true));
323 ft.impl_start(true);
324 ft.interpolate(0.5);
325 assertEquals(0.75, node.getOpacity(), EPSILON);
326 assertEquals(1.0, node2.getOpacity(), EPSILON);
327 ft.impl_finished();
328
329 // node null, parent set
330 ft.setNode(null);
331 assertTrue(ft.impl_startable(true));
332 ft.impl_start(true);
333 ft.interpolate(0.4);
334 assertEquals(0.75, node.getOpacity(), EPSILON);
335 assertEquals(0.7, node2.getOpacity(), EPSILON);
336 ft.impl_finished();
337
338 // node null, parent null
339 pt.setNode(null);
340 assertFalse(ft.impl_startable(true));
341 }
342
343 @Test
344 public void testCachedValues() {
345 final FadeTransition ft = new FadeTransition(ONE_SEC, node);
346 ft.setInterpolator(Interpolator.LINEAR);
347 ft.setFromValue(0.5);
348 ft.setToValue(1.0);
349
350 // start
351 assertTrue(ft.impl_startable(true));
352 ft.impl_start(true);
353 ft.setFromValue(0.0);
354 ft.interpolate(0.5);
355 assertEquals(0.75, node.getOpacity(), EPSILON);
356 ft.impl_finished();
357 ft.setFromValue(0.5);
358
359 // end
360 assertTrue(ft.impl_startable(true));
361 ft.impl_start(true);
362 ft.setToValue(0.0);
363 ft.interpolate(0.2);
364 assertEquals(0.6, node.getOpacity(), EPSILON);
365 ft.impl_finished();
366 ft.setToValue(1.0);
367
368 // node
369 assertTrue(ft.impl_startable(true));
370 ft.impl_start(true);
371 ft.setNode(null);
372 ft.interpolate(0.7);
373 assertEquals(0.85, node.getOpacity(), EPSILON);
374 ft.impl_finished();
375 ft.setNode(node);
376
377 // interpolator
378 assertTrue(ft.impl_startable(true));
379 ft.impl_start(true);
380 ft.setInterpolator(null);
381 ft.interpolate(0.1);
382 assertEquals(0.55, node.getOpacity(), EPSILON);
383 ft.impl_finished();
384 ft.setInterpolator(Interpolator.LINEAR);
385 }
386
387 @Test
388 public void testStartable() {
389 final FadeTransition t0 = new FadeTransition(Duration.ONE, node);
390 assertTrue(t0.impl_startable(true));
391
392 // duration is 0
393 t0.setDuration(Duration.ZERO);
394 assertFalse(t0.impl_startable(true));
395 t0.setDuration(Duration.ONE);
396 assertTrue(t0.impl_startable(true));
397
398 // node is null
399 t0.setNode(null);
400 assertFalse(t0.impl_startable(true));
401 t0.setNode(node);
402 assertTrue(t0.impl_startable(true));
403
404 // interpolator is null
405 t0.setInterpolator(null);
406 assertFalse(t0.impl_startable(true));
407 t0.setInterpolator(Interpolator.LINEAR);
408 assertTrue(t0.impl_startable(true));
409 }
410
411 @Test
412 public void testEvaluateStartValue() {
413 final FadeTransition t0 = new FadeTransition(Duration.INDEFINITE, node);
414
415 // first run
416 node.setOpacity(0.6);
417 assertTrue(t0.impl_startable(true));
418 t0.impl_start(true);
419 node.setOpacity(0.8);
420 t0.interpolate(0.0);
421 assertEquals(0.6, node.getOpacity(), EPSILON);
422 t0.impl_finished();
423
424 // second run
425 node.setOpacity(0.2);
426 assertTrue(t0.impl_startable(true));
427 t0.impl_start(true);
428 node.setOpacity(0.8);
429 t0.interpolate(0.0);
430 assertEquals(0.2, node.getOpacity(), EPSILON);
431 t0.impl_finished();
432 }
433
434 }
|
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.FadeTransition;
30 import javafx.animation.Interpolator;
31 import javafx.animation.ParallelTransition;
32 import javafx.animation.TransitionShim;
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 FadeTransitionTest {
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
113 assertEquals(DEFAULT_INTERPOLATOR, t1.interpolatorProperty().get());
114 assertNull(t1.onFinishedProperty().get());
115
116 // duration and node
117 final FadeTransition t2 = new FadeTransition(TWO_SECS, node);
118 assertEquals(TWO_SECS, t2.durationProperty().get());
119 assertTrue(Double.isNaN(t2.fromValueProperty().get()));
120 assertTrue(Double.isNaN(t2.toValueProperty().get()));
121 assertEquals(0.0, t2.byValueProperty().get(), EPSILON);
122 assertEquals(node, t2.nodeProperty().get());
123 assertEquals(DEFAULT_INTERPOLATOR, t2.interpolatorProperty().get());
124 assertNull(t2.onFinishedProperty().get());
125 }
126
127 @Test
128 public void testInterpolate() {
129 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
130 t0.setFromValue(0.5);
131 t0.setToValue(1.0);
132
133 assertTrue(AnimationShim.impl_startable(t0,true));
134 AnimationShim.impl_start(t0,true);
135 TransitionShim.interpolate(t0,0.0);
136 assertEquals(0.5, node.getOpacity(), EPSILON);
137 TransitionShim.interpolate(t0,0.4);
138 assertEquals(0.7, node.getOpacity(), EPSILON);
139 TransitionShim.interpolate(t0,1.0);
140 assertEquals(1.0, node.getOpacity(), EPSILON);
141 AnimationShim.impl_finished(t0);
142 }
143
144 @Test
145 public void testValueCombinations() {
146 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
147 final double originalValue = 0.6;
148 final double fromValue = 0.4;
149 final double toValue = 0.9;
150 final double byValue = -0.2;
151
152 // no value set
153 node.setOpacity(originalValue);
154 t0.setFromValue(Double.NaN);
155 t0.setToValue(Double.NaN);
156 t0.setByValue(0.0);
157 assertTrue(AnimationShim.impl_startable(t0,true));
158 AnimationShim.impl_start(t0,true);
159 TransitionShim.interpolate(t0,0.0);
160 assertEquals(originalValue, node.getOpacity(), EPSILON);
161 TransitionShim.interpolate(t0,1.0);
162 assertEquals(originalValue, node.getOpacity(), EPSILON);
163 AnimationShim.impl_finished(t0);
164
165 // only from-value set
166 node.setOpacity(originalValue);
167 t0.setFromValue(fromValue);
168 t0.setToValue(Double.NaN);
169 t0.setByValue(0.0);
170 assertTrue(AnimationShim.impl_startable(t0,true));
171 AnimationShim.impl_start(t0,true);
172 TransitionShim.interpolate(t0,0.0);
173 assertEquals(fromValue, node.getOpacity(), EPSILON);
174 TransitionShim.interpolate(t0,1.0);
175 assertEquals(fromValue, node.getOpacity(), EPSILON);
176 AnimationShim.impl_finished(t0);
177
178 // only to-value set
179 node.setOpacity(originalValue);
180 t0.setFromValue(Double.NaN);
181 t0.setToValue(toValue);
182 t0.setByValue(0.0);
183 assertTrue(AnimationShim.impl_startable(t0,true));
184 AnimationShim.impl_start(t0,true);
185 TransitionShim.interpolate(t0,0.0);
186 assertEquals(originalValue, node.getOpacity(), EPSILON);
187 TransitionShim.interpolate(t0,1.0);
188 assertEquals(toValue, node.getOpacity(), EPSILON);
189 AnimationShim.impl_finished(t0);
190
191 // only by-value set
192 node.setOpacity(originalValue);
193 t0.setFromValue(Double.NaN);
194 t0.setToValue(Double.NaN);
195 t0.setByValue(byValue);
196 assertTrue(AnimationShim.impl_startable(t0,true));
197 AnimationShim.impl_start(t0,true);
198 TransitionShim.interpolate(t0,0.0);
199 assertEquals(originalValue, node.getOpacity(), EPSILON);
200 TransitionShim.interpolate(t0,1.0);
201 assertEquals(originalValue + byValue, node.getOpacity(), EPSILON);
202 AnimationShim.impl_finished(t0);
203
204 // from- and to-values set
205 node.setOpacity(originalValue);
206 t0.setFromValue(fromValue);
207 t0.setToValue(toValue);
208 t0.setByValue(0.0);
209 assertTrue(AnimationShim.impl_startable(t0,true));
210 AnimationShim.impl_start(t0,true);
211 TransitionShim.interpolate(t0,0.0);
212 assertEquals(fromValue, node.getOpacity(), EPSILON);
213 TransitionShim.interpolate(t0,1.0);
214 assertEquals(toValue, node.getOpacity(), EPSILON);
215 AnimationShim.impl_finished(t0);
216
217 // from- and by-values set
218 node.setOpacity(originalValue);
219 t0.setFromValue(fromValue);
220 t0.setToValue(Double.NaN);
221 t0.setByValue(byValue);
222 assertTrue(AnimationShim.impl_startable(t0,true));
223 AnimationShim.impl_start(t0,true);
224 TransitionShim.interpolate(t0,0.0);
225 assertEquals(fromValue, node.getOpacity(), EPSILON);
226 TransitionShim.interpolate(t0,1.0);
227 assertEquals(fromValue + byValue, node.getOpacity(), EPSILON);
228 AnimationShim.impl_finished(t0);
229
230 // to- and by-values set
231 node.setOpacity(originalValue);
232 t0.setFromValue(Double.NaN);
233 t0.setToValue(toValue);
234 t0.setByValue(byValue);
235 assertTrue(AnimationShim.impl_startable(t0,true));
236 AnimationShim.impl_start(t0,true);
237 TransitionShim.interpolate(t0,0.0);
238 assertEquals(originalValue, node.getOpacity(), EPSILON);
239 TransitionShim.interpolate(t0,1.0);
240 assertEquals(toValue, node.getOpacity(), EPSILON);
241 AnimationShim.impl_finished(t0);
242
243 // all values set
244 node.setOpacity(originalValue);
245 t0.setFromValue(fromValue);
246 t0.setToValue(toValue);
247 t0.setByValue(byValue);
248 assertTrue(AnimationShim.impl_startable(t0,true));
249 AnimationShim.impl_start(t0,true);
250 TransitionShim.interpolate(t0,0.0);
251 assertEquals(fromValue, node.getOpacity(), EPSILON);
252 TransitionShim.interpolate(t0,1.0);
253 assertEquals(toValue, node.getOpacity(), EPSILON);
254 AnimationShim.impl_finished(t0);
255 }
256
257 @Test
258 public void testOutOfBoundValues() {
259 final FadeTransition t0 = new FadeTransition(ONE_SEC, node);
260 t0.setInterpolator(Interpolator.LINEAR);
261
262 // start < 0.0
263 t0.setFromValue(-0.4);
264 t0.setToValue(0.6);
265 assertTrue(AnimationShim.impl_startable(t0,true));
266 AnimationShim.impl_start(t0,true);
267 TransitionShim.interpolate(t0,0.0);
268 assertEquals(0.0, node.getOpacity(), EPSILON);
269 TransitionShim.interpolate(t0,0.5);
270 assertEquals(0.3, node.getOpacity(), EPSILON);
271 TransitionShim.interpolate(t0,1.0);
272 assertEquals(0.6, node.getOpacity(), EPSILON);
273 AnimationShim.impl_finished(t0);
274
275 // start > 1.0
276 t0.setFromValue(1.3);
277 t0.setToValue(0.3);
278 assertTrue(AnimationShim.impl_startable(t0,true));
279 AnimationShim.impl_start(t0,true);
280 TransitionShim.interpolate(t0,0.0);
281 assertEquals(1.0, node.getOpacity(), EPSILON);
282 TransitionShim.interpolate(t0,0.5);
283 assertEquals(0.65, node.getOpacity(), EPSILON);
284 TransitionShim.interpolate(t0,1.0);
285 assertEquals(0.3, node.getOpacity(), EPSILON);
286 AnimationShim.impl_finished(t0);
287
288 // end < 0.0
289 t0.setFromValue(0.2);
290 t0.setToValue(-1.2);
291 assertTrue(AnimationShim.impl_startable(t0,true));
292 AnimationShim.impl_start(t0,true);
293 TransitionShim.interpolate(t0,0.0);
294 assertEquals(0.2, node.getOpacity(), EPSILON);
295 TransitionShim.interpolate(t0,0.5);
296 assertEquals(0.1, node.getOpacity(), EPSILON);
297 TransitionShim.interpolate(t0,1.0);
298 assertEquals(0.0, node.getOpacity(), EPSILON);
299 AnimationShim.impl_finished(t0);
300
301 // end > 1.0
302 t0.setFromValue(0.9);
303 t0.setToValue(1.9);
304 assertTrue(AnimationShim.impl_startable(t0,true));
305 AnimationShim.impl_start(t0,true);
306 TransitionShim.interpolate(t0,0.0);
307 assertEquals(0.9, node.getOpacity(), EPSILON);
308 TransitionShim.interpolate(t0,0.5);
309 assertEquals(0.95, node.getOpacity(), EPSILON);
310 TransitionShim.interpolate(t0,1.0);
311 assertEquals(1.0, node.getOpacity(), EPSILON);
312 AnimationShim.impl_finished(t0);
313 }
314
315 @Test
316 public void testGetTargetNode() {
317 final FadeTransition ft = new FadeTransition(ONE_SEC, node);
318 ft.setInterpolator(Interpolator.LINEAR);
319 ft.setFromValue(0.5);
320 ft.setToValue(1.0);
321 final Rectangle node2 = new Rectangle();
322 final ParallelTransition pt = new ParallelTransition();
323 pt.getChildren().add(ft);
324 pt.setNode(node2);
325
326 // node set, parent set
327 assertTrue(AnimationShim.impl_startable(ft,true));
328 AnimationShim.impl_start(ft,true);
329 TransitionShim.interpolate(ft,0.5);
330 assertEquals(0.75, node.getOpacity(), EPSILON);
331 assertEquals(1.0, node2.getOpacity(), EPSILON);
332 AnimationShim.impl_finished(ft);
333
334 // node null, parent set
335 ft.setNode(null);
336 assertTrue(AnimationShim.impl_startable(ft,true));
337 AnimationShim.impl_start(ft,true);
338 TransitionShim.interpolate(ft,0.4);
339 assertEquals(0.75, node.getOpacity(), EPSILON);
340 assertEquals(0.7, node2.getOpacity(), EPSILON);
341 AnimationShim.impl_finished(ft);
342
343 // node null, parent null
344 pt.setNode(null);
345 assertFalse(AnimationShim.impl_startable(ft,true));
346 }
347
348 @Test
349 public void testCachedValues() {
350 final FadeTransition ft = new FadeTransition(ONE_SEC, node);
351 ft.setInterpolator(Interpolator.LINEAR);
352 ft.setFromValue(0.5);
353 ft.setToValue(1.0);
354
355 // start
356 assertTrue(AnimationShim.impl_startable(ft,true));
357 AnimationShim.impl_start(ft,true);
358 ft.setFromValue(0.0);
359 TransitionShim.interpolate(ft,0.5);
360 assertEquals(0.75, node.getOpacity(), EPSILON);
361 AnimationShim.impl_finished(ft);
362 ft.setFromValue(0.5);
363
364 // end
365 assertTrue(AnimationShim.impl_startable(ft,true));
366 AnimationShim.impl_start(ft,true);
367 ft.setToValue(0.0);
368 TransitionShim.interpolate(ft,0.2);
369 assertEquals(0.6, node.getOpacity(), EPSILON);
370 AnimationShim.impl_finished(ft);
371 ft.setToValue(1.0);
372
373 // node
374 assertTrue(AnimationShim.impl_startable(ft,true));
375 AnimationShim.impl_start(ft,true);
376 ft.setNode(null);
377 TransitionShim.interpolate(ft,0.7);
378 assertEquals(0.85, node.getOpacity(), EPSILON);
379 AnimationShim.impl_finished(ft);
380 ft.setNode(node);
381
382 // interpolator
383 assertTrue(AnimationShim.impl_startable(ft,true));
384 AnimationShim.impl_start(ft,true);
385 ft.setInterpolator(null);
386 TransitionShim.interpolate(ft,0.1);
387 assertEquals(0.55, node.getOpacity(), EPSILON);
388 AnimationShim.impl_finished(ft);
389 ft.setInterpolator(Interpolator.LINEAR);
390 }
391
392 @Test
393 public void testStartable() {
394 final FadeTransition t0 = new FadeTransition(Duration.ONE, node);
395 assertTrue(AnimationShim.impl_startable(t0,true));
396
397 // duration is 0
398 t0.setDuration(Duration.ZERO);
399 assertFalse(AnimationShim.impl_startable(t0,true));
400 t0.setDuration(Duration.ONE);
401 assertTrue(AnimationShim.impl_startable(t0,true));
402
403 // node is null
404 t0.setNode(null);
405 assertFalse(AnimationShim.impl_startable(t0,true));
406 t0.setNode(node);
407 assertTrue(AnimationShim.impl_startable(t0,true));
408
409 // interpolator is null
410 t0.setInterpolator(null);
411 assertFalse(AnimationShim.impl_startable(t0,true));
412 t0.setInterpolator(Interpolator.LINEAR);
413 assertTrue(AnimationShim.impl_startable(t0,true));
414 }
415
416 @Test
417 public void testEvaluateStartValue() {
418 final FadeTransition t0 = new FadeTransition(Duration.INDEFINITE, node);
419
420 // first run
421 node.setOpacity(0.6);
422 assertTrue(AnimationShim.impl_startable(t0,true));
423 AnimationShim.impl_start(t0,true);
424 node.setOpacity(0.8);
425 TransitionShim.interpolate(t0,0.0);
426 assertEquals(0.6, node.getOpacity(), EPSILON);
427 AnimationShim.impl_finished(t0);
428
429 // second run
430 node.setOpacity(0.2);
431 assertTrue(AnimationShim.impl_startable(t0,true));
432 AnimationShim.impl_start(t0,true);
433 node.setOpacity(0.8);
434 TransitionShim.interpolate(t0,0.0);
435 assertEquals(0.2, node.getOpacity(), EPSILON);
436 AnimationShim.impl_finished(t0);
437 }
438
439 }
|