1 /* 2 * Copyright (c) 2010, 2015, 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 23 * questions. 24 */ 25 26 package test.javafx.scene.image; 27 28 import test.com.sun.javafx.pgstub.StubImageLoaderFactory; 29 import test.com.sun.javafx.pgstub.StubPlatformImageInfo; 30 import test.com.sun.javafx.pgstub.StubToolkit; 31 import com.sun.javafx.tk.Toolkit; 32 import javafx.scene.image.Image; 33 import javafx.scene.image.ImageShim; 34 35 public final class TestImages { 36 public static final Image TEST_IMAGE_0x100; 37 public static final Image TEST_IMAGE_100x0; 38 public static final Image TEST_IMAGE_100x200; 39 public static final Image TEST_IMAGE_200x100; 40 41 public static final Image TEST_IMAGE_32x32; 42 public static final Image TEST_IMAGE_32x64; 43 public static final Image TEST_IMAGE_64x32; 44 public static final Image TEST_IMAGE_64x64; 45 46 public static final Image TEST_ERROR_IMAGE; 47 48 private static final StubImageLoaderFactory imageLoaderFactory; 49 50 private TestImages() { 51 } 52 53 static { 54 imageLoaderFactory = 55 ((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory(); 56 57 TEST_IMAGE_0x100 = createTestImage(0, 100); 58 TEST_IMAGE_100x0 = createTestImage(100, 0); 59 TEST_IMAGE_100x200 = createTestImage(100, 200); 60 TEST_IMAGE_200x100 = createTestImage(200, 100); 61 62 TEST_IMAGE_32x32 = createTestImage(32, 32); 63 TEST_IMAGE_32x64 = createTestImage(32, 64); 64 TEST_IMAGE_64x32 = createTestImage(64, 32); 65 TEST_IMAGE_64x64 = createTestImage(64, 64); 66 67 TEST_ERROR_IMAGE = new Image("file:error.png"); 68 } 69 70 public static Image createTestImage( 71 final int width, 72 final int height) { 73 final String url = "file:testImg_" + width + "x" + height + ".png"; 74 imageLoaderFactory.registerImage( 75 url, new StubPlatformImageInfo(width, height)); 76 77 return new Image(url); 78 } 79 80 public static Image createAnimatedTestImage( 81 final int width, 82 final int height, 83 final int loopCount, final int... frameDelays) { 84 final String url = "file:testAnimImg_" + width + "x" + height + ".png"; 85 final StubPlatformImageInfo spii = 86 new StubPlatformImageInfo(width, height, frameDelays, loopCount); 87 imageLoaderFactory.registerImage(url, spii); 88 89 return new Image(url); 90 } 91 92 /** 93 * Stops animation timeline on the image. Used to prevent problems with 94 * rewiding animation time. 95 * 96 * @param image the animated image to dispose 97 */ 98 public static void disposeAnimatedImage(final Image image) { 99 ImageShim.dispose(image); 100 } 101 }