src/share/classes/sun/awt/image/MultiResolutionToolkitImage.java

Print this page




   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 package sun.awt.image;
  26 
  27 import java.awt.Image;
  28 import java.awt.image.ImageObserver;

  29 import java.util.Arrays;
  30 import java.util.List;
  31 import sun.misc.SoftCache;
  32 
  33 public class MultiResolutionToolkitImage extends ToolkitImage implements MultiResolutionImage {

  34 
  35     Image resolutionVariant;

  36 
  37     public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {







  38         super(lowResolutionImage.getSource());
  39         this.resolutionVariant = resolutionVariant;

  40     }
  41 
  42     @Override
  43     public Image getResolutionVariant(int width, int height) {









  44         return ((width <= getWidth() && height <= getHeight()))
  45                 ? this : resolutionVariant;
  46     }
  47 
  48     public Image getResolutionVariant() {
  49         return resolutionVariant;
  50     }
  51 
  52     @Override
  53     public List<Image> getResolutionVariants() {
  54         return Arrays.<Image>asList(this, resolutionVariant);
  55     }
  56 
  57     private static final int BITS_INFO = ImageObserver.SOMEBITS
  58             | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS;
  59 
  60     private static class ObserverCache {
  61 
  62         static final SoftCache INSTANCE = new SoftCache();
  63     }




   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 package sun.awt.image;
  26 
  27 import java.awt.Image;
  28 import java.awt.image.ImageObserver;
  29 import java.awt.image.MultiResolutionImage;
  30 import java.util.Arrays;
  31 import java.util.List;
  32 import sun.misc.SoftCache;
  33 
  34 public class MultiResolutionToolkitImage extends ToolkitImage
  35         implements MultiResolutionImage {
  36 
  37     private final Image resolutionVariant;
  38     private final ImageResolutionHelper imageResolutionHelper;
  39 
  40     public MultiResolutionToolkitImage(Image lowResolutionImage,
  41             Image resolutionVariant) {
  42         this(lowResolutionImage, resolutionVariant,
  43                 ImageResolutionHelperType.getPlatformHelper());
  44     }
  45 
  46     public MultiResolutionToolkitImage(Image lowResolutionImage,
  47             Image resolutionVariant, ImageResolutionHelper imageResolutionHelper) {
  48         super(lowResolutionImage.getSource());
  49         this.resolutionVariant = resolutionVariant;
  50         this.imageResolutionHelper = imageResolutionHelper;
  51     }
  52 
  53     @Override
  54     public Image getResolutionVariant(float logicalDPIX, float logicalDPIY,
  55             float baseWidth, float baseHeight, float destWidth, float destHeight) {
  56         float hiDPIWidth = imageResolutionHelper.getHiDPISize(logicalDPIX,
  57                 baseWidth, destWidth);
  58         float hiDPIHeight = imageResolutionHelper.getHiDPISize(logicalDPIY,
  59                 baseHeight, destHeight);
  60         return getResolutionVariant(hiDPIWidth, hiDPIHeight);
  61     }
  62 
  63     private Image getResolutionVariant(float width, float height) {
  64         return ((width <= getWidth() && height <= getHeight()))
  65                 ? this : resolutionVariant;
  66     }
  67 
  68     public Image getResolutionVariant() {
  69         return resolutionVariant;
  70     }
  71 
  72     @Override
  73     public List<Image> getResolutionVariants() {
  74         return Arrays.<Image>asList(this, resolutionVariant);
  75     }
  76 
  77     private static final int BITS_INFO = ImageObserver.SOMEBITS
  78             | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS;
  79 
  80     private static class ObserverCache {
  81 
  82         static final SoftCache INSTANCE = new SoftCache();
  83     }