1 package net.sf.openrocket.gui.help.tours;
3 import java.awt.image.BufferedImage;
4 import java.io.IOException;
5 import java.lang.ref.SoftReference;
8 import javax.imageio.ImageIO;
10 import net.sf.openrocket.util.BugException;
13 * An individual slide in a guided tour. It contains a image (or reference to an
14 * image file) plus a text description (in HTML).
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
19 private static final String NO_IMAGE = "none";
21 private final String imageFile;
22 private SoftReference<BufferedImage> imageReference = null;
24 private final String text;
28 public Slide(String imageFile, String text) {
29 this.imageFile = imageFile;
35 public BufferedImage getImage() {
37 if (imageFile.equals(NO_IMAGE)) {
38 return new BufferedImage(0, 0, BufferedImage.TYPE_INT_ARGB);
42 if (imageReference != null) {
43 BufferedImage image = imageReference.get();
49 // Otherwise load and cache
50 BufferedImage image = loadImage();
51 imageReference = new SoftReference<BufferedImage>(image);
56 public String getText() {
62 private BufferedImage loadImage() {
66 URL url = ClassLoader.getSystemResource(imageFile);
68 img = ImageIO.read(url);
70 throw new BugException("Could not find image " + imageFile);
72 } catch (IOException e) {
73 throw new BugException("Error reading image " + imageFile, e);