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