1 /*
   2  * Copyright (c) 2011, 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 com.sun.javafx.pgstub;
  27 
  28 import com.sun.javafx.tk.ImageLoader;
  29 import com.sun.javafx.tk.PlatformImage;
  30 
  31 public final class StubImageLoader implements ImageLoader {
  32     private final Object source;
  33 
  34     private final StubPlatformImageInfo imageInfo;
  35     private final int loadWidth;
  36     private final int loadHeight;
  37     private final boolean preserveRatio;
  38     private final boolean smooth;
  39 
  40     private final PlatformImage[] frames;
  41 
  42     public StubImageLoader(final Object source,
  43                            final StubPlatformImageInfo imageInfo,
  44                            final int loadWidth,
  45                            final int loadHeight,
  46                            final boolean preserveRatio,
  47                            final boolean smooth) {
  48         this.source = source;
  49         
  50         this.imageInfo = imageInfo;
  51         this.loadWidth = loadWidth;
  52         this.loadHeight = loadHeight;
  53         this.preserveRatio = preserveRatio;
  54         this.smooth = smooth;
  55 
  56         frames = new PlatformImage[imageInfo.getFrameCount()];
  57         for (int i = 0; i < frames.length; ++i) {
  58             frames[i] = source instanceof PlatformImage ? (PlatformImage) source : new StubPlatformImage(this, i);
  59         }
  60     }
  61 
  62     public Object getSource() {
  63         return source;
  64     }
  65 
  66     @Override
  67     public Exception getException() {
  68         return null;
  69     }
  70 
  71     @Override
  72     public int getFrameCount() {
  73         return frames.length;
  74     }
  75 
  76     @Override
  77     public PlatformImage getFrame(final int i) {
  78         return frames[i];
  79     }
  80 
  81     @Override
  82     public int getFrameDelay(final int i) {
  83         return imageInfo.getFrameDelay(i);
  84     }
  85 
  86     @Override
  87     public int getLoopCount() {
  88         return imageInfo.getLoopCount();
  89     }
  90 
  91     @Override
  92     public int getWidth() {
  93         return imageInfo.getWidth();
  94     }
  95 
  96     @Override
  97     public int getHeight() {
  98         return imageInfo.getHeight();
  99     }
 100 
 101     public StubPlatformImageInfo getImageInfo() {
 102         return imageInfo;
 103     }
 104 
 105     public int getLoadHeight() {
 106         return loadHeight;
 107     }
 108 
 109     public int getLoadWidth() {
 110         return loadWidth;
 111     }
 112 
 113     public boolean getPreserveRatio() {
 114         return preserveRatio;
 115     }
 116 
 117     public boolean getSmooth() {
 118         return smooth;
 119     }
 120 }