|
1 /* |
|
2 * Copyright (c) 2014, 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 package sun.awt.image; |
|
26 |
|
27 import java.awt.Graphics; |
|
28 import java.awt.Image; |
|
29 import java.awt.image.*; |
|
30 |
|
31 /** |
|
32 * This class provides default implementations for the |
|
33 * <code>MultiResolutionImage</code> interface. The developer needs only |
|
34 * to subclass this abstract class and define the <code>getResolutionVariant</code>, |
|
35 * <code>getResolutionVariants</code>, and <code>getBaseImage</code> methods. |
|
36 * |
|
37 * |
|
38 * For example, |
|
39 * {@code |
|
40 * public class CustomMultiResolutionImage extends AbstractMultiResolutionImage { |
|
41 * |
|
42 * int baseImageIndex; |
|
43 * Image[] resolutionVariants; |
|
44 * |
|
45 * public CustomMultiResolutionImage(int baseImageIndex, |
|
46 * Image... resolutionVariants) { |
|
47 * this.baseImageIndex = baseImageIndex; |
|
48 * this.resolutionVariants = resolutionVariants; |
|
49 * } |
|
50 * |
|
51 * @Override |
|
52 * public Image getResolutionVariant(float logicalDPIX, float logicalDPIY, |
|
53 * float baseImageWidth, float baseImageHeight, |
|
54 * float destImageWidth, float destImageHeight) { |
|
55 * // return a resolution variant based on the given logical DPI, |
|
56 * // base image size, or destination image size |
|
57 * } |
|
58 * |
|
59 * @Override |
|
60 * public List<Image> getResolutionVariants() { |
|
61 * return Arrays.asList(resolutionVariants); |
|
62 * } |
|
63 * |
|
64 * protected Image getBaseImage() { |
|
65 * return resolutionVariants[baseImageIndex]; |
|
66 * } |
|
67 * } |
|
68 * } |
|
69 * |
|
70 * @see java.awt.Image |
|
71 * @see java.awt.image.MultiResolutionImage |
|
72 * |
|
73 * @since 1.9 |
|
74 */ |
|
75 public abstract class AbstractMultiResolutionImage extends java.awt.Image |
|
76 implements MultiResolutionImage { |
|
77 |
|
78 /** |
|
79 * @inheritDoc |
|
80 */ |
|
81 @Override |
|
82 public int getWidth(ImageObserver observer) { |
|
83 return getBaseImage().getWidth(null); |
|
84 } |
|
85 |
|
86 /** |
|
87 * @inheritDoc |
|
88 */ |
|
89 @Override |
|
90 public int getHeight(ImageObserver observer) { |
|
91 return getBaseImage().getHeight(null); |
|
92 } |
|
93 |
|
94 /** |
|
95 * @inheritDoc |
|
96 */ |
|
97 @Override |
|
98 public ImageProducer getSource() { |
|
99 return getBaseImage().getSource(); |
|
100 } |
|
101 |
|
102 /** |
|
103 * @inheritDoc |
|
104 */ |
|
105 @Override |
|
106 public Graphics getGraphics() { |
|
107 return getBaseImage().getGraphics(); |
|
108 |
|
109 } |
|
110 |
|
111 /** |
|
112 * @inheritDoc |
|
113 */ |
|
114 @Override |
|
115 public Object getProperty(String name, ImageObserver observer) { |
|
116 return getBaseImage().getProperty(name, observer); |
|
117 } |
|
118 |
|
119 /** |
|
120 * @return base image |
|
121 */ |
|
122 protected abstract Image getBaseImage(); |
|
123 } |