33 /** 34 * This class is an array-based implementation of 35 * the {@code AbstractMultiResolutionImage} class. 36 * 37 * This class will implement the 38 * {@code getResolutionVariant(double destImageWidth, double destImageHeight)} 39 * method using a simple algorithm which will return the first image variant 40 * in the array that is large enough to satisfy the rendering request. The 41 * last image in the array will be returned if no suitable image is found 42 * that is as large as the rendering request. 43 * <p> 44 * For best effect the array of images should be sorted with each image being 45 * both wider and taller than the previous image. The base image need not be 46 * the first image in the array. No exception will be thrown if the images 47 * are not sorted as suggested. 48 * 49 * @see java.awt.Image 50 * @see java.awt.image.MultiResolutionImage 51 * @see java.awt.image.AbstractMultiResolutionImage 52 * 53 * @since 1.9 54 */ 55 public class BaseMultiResolutionImage extends AbstractMultiResolutionImage { 56 57 private final int baseImageIndex; 58 private final Image[] resolutionVariants; 59 60 /** 61 * Creates a multi-resolution image with the given resolution variants. 62 * The first resolution variant is used as the base image. 63 * 64 * @param resolutionVariants array of resolution variants sorted by image size 65 * @throws IllegalArgumentException if null or zero-length array is passed 66 * @throws NullPointerException if the specified {@code resolutionVariants} 67 * contains one or more null elements 68 * 69 * @since 1.9 70 */ 71 public BaseMultiResolutionImage(Image... resolutionVariants) { 72 this(0, resolutionVariants); 73 } 74 75 /** 76 * Creates a multi-resolution image with the given base image index and 77 * resolution variants. 78 * 79 * @param baseImageIndex the index of base image in the resolution variants 80 * array 81 * @param resolutionVariants array of resolution variants sorted by image size 82 * @throws IllegalArgumentException if null or zero-length array is passed 83 * @throws NullPointerException if the specified {@code resolutionVariants} 84 * contains one or more null elements 85 * @throws IndexOutOfBoundsException if {@code baseImageIndex} is 86 * negative or greater than or equal to {@code resolutionVariants} 87 * length. 88 * 89 * @since 1.9 90 */ 91 public BaseMultiResolutionImage(int baseImageIndex, 92 Image... resolutionVariants) { 93 94 if (resolutionVariants == null || resolutionVariants.length == 0) { 95 throw new IllegalArgumentException( 96 "Null or zero-length array is passed"); 97 } 98 99 if (baseImageIndex < 0 || baseImageIndex >= resolutionVariants.length) { 100 throw new IndexOutOfBoundsException("Invalid base image index: " 101 + baseImageIndex); 102 } 103 104 this.baseImageIndex = baseImageIndex; 105 this.resolutionVariants = Arrays.copyOf(resolutionVariants, 106 resolutionVariants.length); 107 108 for (Image resolutionVariant : this.resolutionVariants) { 109 Objects.requireNonNull(resolutionVariant, | 33 /** 34 * This class is an array-based implementation of 35 * the {@code AbstractMultiResolutionImage} class. 36 * 37 * This class will implement the 38 * {@code getResolutionVariant(double destImageWidth, double destImageHeight)} 39 * method using a simple algorithm which will return the first image variant 40 * in the array that is large enough to satisfy the rendering request. The 41 * last image in the array will be returned if no suitable image is found 42 * that is as large as the rendering request. 43 * <p> 44 * For best effect the array of images should be sorted with each image being 45 * both wider and taller than the previous image. The base image need not be 46 * the first image in the array. No exception will be thrown if the images 47 * are not sorted as suggested. 48 * 49 * @see java.awt.Image 50 * @see java.awt.image.MultiResolutionImage 51 * @see java.awt.image.AbstractMultiResolutionImage 52 * 53 * @since 9 54 */ 55 public class BaseMultiResolutionImage extends AbstractMultiResolutionImage { 56 57 private final int baseImageIndex; 58 private final Image[] resolutionVariants; 59 60 /** 61 * Creates a multi-resolution image with the given resolution variants. 62 * The first resolution variant is used as the base image. 63 * 64 * @param resolutionVariants array of resolution variants sorted by image size 65 * @throws IllegalArgumentException if null or zero-length array is passed 66 * @throws NullPointerException if the specified {@code resolutionVariants} 67 * contains one or more null elements 68 * 69 * @since 9 70 */ 71 public BaseMultiResolutionImage(Image... resolutionVariants) { 72 this(0, resolutionVariants); 73 } 74 75 /** 76 * Creates a multi-resolution image with the given base image index and 77 * resolution variants. 78 * 79 * @param baseImageIndex the index of base image in the resolution variants 80 * array 81 * @param resolutionVariants array of resolution variants sorted by image size 82 * @throws IllegalArgumentException if null or zero-length array is passed 83 * @throws NullPointerException if the specified {@code resolutionVariants} 84 * contains one or more null elements 85 * @throws IndexOutOfBoundsException if {@code baseImageIndex} is 86 * negative or greater than or equal to {@code resolutionVariants} 87 * length. 88 * 89 * @since 9 90 */ 91 public BaseMultiResolutionImage(int baseImageIndex, 92 Image... resolutionVariants) { 93 94 if (resolutionVariants == null || resolutionVariants.length == 0) { 95 throw new IllegalArgumentException( 96 "Null or zero-length array is passed"); 97 } 98 99 if (baseImageIndex < 0 || baseImageIndex >= resolutionVariants.length) { 100 throw new IndexOutOfBoundsException("Invalid base image index: " 101 + baseImageIndex); 102 } 103 104 this.baseImageIndex = baseImageIndex; 105 this.resolutionVariants = Arrays.copyOf(resolutionVariants, 106 resolutionVariants.length); 107 108 for (Image resolutionVariant : this.resolutionVariants) { 109 Objects.requireNonNull(resolutionVariant, |