Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JThequeImage |
|
| 1.6666666666666667;1.667 |
1 | package org.jtheque.core.managers.resource; | |
2 | ||
3 | import javax.swing.ImageIcon; | |
4 | import java.awt.image.BufferedImage; | |
5 | import java.lang.ref.SoftReference; | |
6 | ||
7 | /* | |
8 | * This file is part of JTheque. | |
9 | * | |
10 | * JTheque is free software: you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation, either version 3 of the License. | |
13 | * | |
14 | * JTheque is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
21 | */ | |
22 | ||
23 | /** | |
24 | * An image container. This image container stock the image as a SoftReference. | |
25 | * | |
26 | * @author Baptiste Wicht | |
27 | * @see SoftReference | |
28 | */ | |
29 | final class JThequeImage { | |
30 | private final SoftReference<BufferedImage> image; | |
31 | ||
32 | /** | |
33 | * Construct a new JTheque Image. | |
34 | * | |
35 | * @param image The buffered image. | |
36 | */ | |
37 | JThequeImage(BufferedImage image) { | |
38 | 0 | super(); |
39 | ||
40 | 0 | this.image = new SoftReference<BufferedImage>(image); |
41 | 0 | } |
42 | ||
43 | /** | |
44 | * Return the JThequeImage as an ImageIcon. | |
45 | * | |
46 | * @return The ImageIcon value of the image. | |
47 | */ | |
48 | public ImageIcon asIcon() { | |
49 | 0 | return get() == null ? null : new ImageIcon(get()); |
50 | } | |
51 | ||
52 | /** | |
53 | * Return the buffered image. | |
54 | * | |
55 | * @return The buffered image. | |
56 | */ | |
57 | public BufferedImage get() { | |
58 | 0 | return image == null ? null : image.get(); |
59 | } | |
60 | } |