public void generateThumbnail() {
      ext = file.getName().substring(file.getName().lastIndexOf('.')+1).toLowerCase();

      double size = 9.5367e-7*file.length();
      DecimalFormat df = new DecimalFormat("#.##");
      tSize.setText(df.format(size) + " MiB");

      //IMAGES
      if(ext.equals("jpg") || ext.equals("png") || ext.equals("gif")) {
        
        Image image = Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath());
        final MediaTracker tracker = new MediaTracker(new Container());
        tracker.addImage(image, 0);
        try {
           tracker.waitForID(0);
        } catch (InterruptedException e) {
           System.out.println("Interrupted getting thumb");
        }
        
        if(rotateThumb != 0) image = rotateThumbnail(image, rotateThumb);

        final int width = image.getWidth(null);
        final int height = image.getHeight(null);

        if ((width > 0) && (width * height < 54000000)) {
          float ratio = (float)width/(float)height;

          int thumbHeight = 100;
          int thumbWidth = (int)(100.0*(ratio));
          if(thumbWidth>150) {
              thumbHeight = (int)(thumbHeight*(150.0/thumbWidth));
              thumbWidth = 150;
          }

          BufferedImage scaledImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);

          Graphics2D g2dBuffer = scaledImage.createGraphics();
          g2dBuffer.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
          g2dBuffer.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);

          tThumb.setBackground(Color.black);
          tThumb.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(scaledImage.getSource())));
          scaledImage.flush();
          image.flush();
          g2dBuffer = null;
          
          tSize.setText("<html><body>" + width + " x " + height + " (" + df.format((width*height)/1000000.0) + " Mpix)<br>" +
            df.format(size) + " MiB");

        } else
            tThumb.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cuploader/resources/document-32.png")));
        
        lFilename.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cuploader/resources/document-image.png")));
        lFilename.setToolTipText(bundle.getString("file-image") + " (." + ext + ")");
        
      } else if(ext.equals("svg")) {
          tThumb.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cuploader/resources/document-32.png")));
      } else {
          tThumb.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cuploader/resources/document-32.png")));
      }
    }