-class AltosCacheImage {
- Component component;
- File file;
- VolatileImage image;
- int width;
- int height;
- long used;
-
- public void load_image() throws IOException {
- BufferedImage bimg = ImageIO.read(file);
- if (bimg == null)
- throw new IOException("Can't load image file");
- Graphics2D g = image.createGraphics();
- g.drawImage(bimg, 0, 0, null);
- bimg.flush();
- bimg = null;
- }
-
- public Image validate() {
- int returnCode;
-
- if (image != null)
- returnCode = image.validate(component.getGraphicsConfiguration());
- else
- returnCode = VolatileImage.IMAGE_INCOMPATIBLE;
- if (returnCode == VolatileImage.IMAGE_RESTORED) {
- try {
- load_image();
- } catch (IOException e) {
- return null;
- }
- } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
- image = component.createVolatileImage(width, height);
- try {
- load_image();
- } catch (IOException e) {
- return null;
- }
- }
- return image;
- }
-
- public void flush() {
- image.flush();
- }
-
- public AltosCacheImage(Component component, File file, int w, int h) throws IOException {
- this.component = component;
- this.file = file;
- width = w;
- height = h;
- image = component.createVolatileImage(w, h);
- used = 0;
- }
-}
-