public EncodedImage adaptImage(
     EncodedImage downloadedImage, EncodedImage placeholderImage) {
   if (downloadedImage.getWidth() != placeholderImage.getWidth()
       || downloadedImage.getHeight() != placeholderImage.getHeight()) {
     throw new RuntimeException("Invalid image size");
   }
   return downloadedImage;
 }
 private URLImage(
     EncodedImage placeholder,
     String url,
     ImageAdapter adapter,
     String storageFile,
     String fileSystemFile) {
   super(placeholder.getWidth(), placeholder.getHeight());
   this.placeholder = placeholder;
   this.url = url;
   this.adapter = adapter;
   this.storageFile = storageFile;
   this.fileSystemFile = fileSystemFile;
 }
 public void actionPerformed(ActionEvent evt) {
   if (adapter != null) {
     try {
       byte[] d;
       InputStream is;
       if (storageFile != null) {
         d = new byte[Storage.getInstance().entrySize(storageFile + IMAGE_SUFFIX)];
         is = Storage.getInstance().createInputStream(storageFile + IMAGE_SUFFIX);
       } else {
         d =
             new byte
                 [(int)
                     FileSystemStorage.getInstance().getLength(fileSystemFile + IMAGE_SUFFIX)];
         is = FileSystemStorage.getInstance().openInputStream(fileSystemFile + IMAGE_SUFFIX);
       }
       Util.readFully(is, d);
       EncodedImage img = EncodedImage.create(d);
       EncodedImage adapted;
       if (adapter.isAsyncAdapter()) {
         adapt = img;
         Display.getInstance().invokeAndBlock(this);
         adapted = adaptedIns;
         adaptedIns = null;
         adapt = null;
       } else {
         adapted = adapter.adaptImage(img, placeholder);
       }
       if (storageFile != null) {
         OutputStream o = Storage.getInstance().createOutputStream(storageFile);
         o.write(adapted.getImageData());
         o.close();
         Storage.getInstance().deleteStorageFile(storageFile + IMAGE_SUFFIX);
       } else {
         OutputStream o = FileSystemStorage.getInstance().openOutputStream(fileSystemFile);
         o.write(adapted.getImageData());
         o.close();
         FileSystemStorage.getInstance().delete(fileSystemFile + IMAGE_SUFFIX);
       }
     } catch (IOException ex) {
       ex.printStackTrace();
       return;
     }
   }
   fetching = false;
   // invoke fetch again to load the local files
   fetch();
 }
 public EncodedImage adaptImage(
     EncodedImage downloadedImage, EncodedImage placeholderImage) {
   if (downloadedImage.getWidth() != placeholderImage.getWidth()
       || downloadedImage.getHeight() != placeholderImage.getHeight()) {
     return downloadedImage.scaledEncoded(
         placeholderImage.getWidth(), placeholderImage.getHeight());
   }
   return downloadedImage;
 }
 public EncodedImage adaptImage(EncodedImage downloadedImage, EncodedImage placeholderImage) {
   if (downloadedImage.getWidth() != placeholderImage.getWidth()
       || downloadedImage.getHeight() != placeholderImage.getHeight()) {
     Image tmp =
         downloadedImage
             .getInternal()
             .scaledLargerRatio(placeholderImage.getWidth(), placeholderImage.getHeight());
     if (tmp.getWidth() > placeholderImage.getWidth()) {
       int diff = tmp.getWidth() - placeholderImage.getWidth();
       int x = diff / 2;
       tmp =
           tmp.subImage(
               x,
               0,
               Math.min(placeholderImage.getWidth(), tmp.getWidth()),
               Math.min(placeholderImage.getHeight(), tmp.getHeight()),
               true);
     } else {
       if (tmp.getHeight() > placeholderImage.getHeight()) {
         int diff = tmp.getHeight() - placeholderImage.getHeight();
         int y = diff / 2;
         tmp =
             tmp.subImage(
                 0,
                 y,
                 Math.min(placeholderImage.getWidth(), tmp.getWidth()),
                 Math.min(placeholderImage.getHeight(), tmp.getHeight()),
                 true);
       }
     }
     tmp = postProcess(tmp);
     return EncodedImage.createFromImage(tmp, tmp.isOpaque());
   }
   return downloadedImage;
 }
 /** {@inheritDoc} */
 public byte[] getImageData() {
   if (imageData != null) {
     return imageData;
   }
   return placeholder.getImageData();
 }
 /**
  * Retrieves a random predefined image
  *
  * @return The hard coded photo image
  */
 public static EncodedImage getRandomPhotoImage() {
   String pictureName = "photo/" + PICTURES[_random.nextInt(PICTURES.length)];
   return EncodedImage.getEncodedImageResource(pictureName);
 }