19 package org.sleuthkit.autopsy.corecomponents;
 
   21 import java.awt.Image;
 
   22 import java.awt.Toolkit;
 
   23 import java.awt.event.ActionEvent;
 
   24 import java.lang.ref.SoftReference;
 
   25 import java.util.concurrent.ExecutionException;
 
   26 import java.util.logging.Level;
 
   27 import javax.swing.SwingWorker;
 
   28 import javax.swing.Timer;
 
   29 import org.apache.commons.lang3.StringUtils;
 
   30 import org.netbeans.api.progress.ProgressHandle;
 
   31 import org.openide.nodes.FilterNode;
 
   32 import org.openide.nodes.Node;
 
   33 import org.openide.util.NbBundle;
 
   42 class ThumbnailViewNode 
extends FilterNode {
 
   44     static private final Image waitingIcon = Toolkit.getDefaultToolkit().createImage(ThumbnailViewNode.class.getResource(
"/org/sleuthkit/autopsy/images/working_spinner.gif"));
 
   46     private SoftReference<Image> iconCache = null;
 
   47     private int iconSize = ImageUtils.ICON_SIZE_MEDIUM;
 
   49     private SwingWorker<Image, Object> swingWorker;
 
   55     ThumbnailViewNode(Node arg, 
int iconSize) {
 
   56         super(arg, Children.LEAF);
 
   57         this.iconSize = iconSize;
 
   61     public String getDisplayName() {
 
   62         return StringUtils.abbreviate(super.getDisplayName(), 18);
 
   66     @NbBundle.Messages({
"# {0} - file name",
 
   67         "ThumbnailViewNode.progressHandle.text=Generating thumbnail for {0}"})
 
   68     public Image getIcon(
int type) {
 
   71         if (iconCache != null) {
 
   72             icon = iconCache.get();
 
   78             final Content content = this.getLookup().lookup(Content.class);
 
   79             if (content == null) {
 
   80                 return ImageUtils.getDefaultThumbnail();
 
   82             if (swingWorker == null || swingWorker.isDone()) {
 
   83                 swingWorker = 
new SwingWorker<Image, Object>() {
 
   84                     final private ProgressHandle progressHandle = ProgressHandle.createHandle(Bundle.ThumbnailViewNode_progressHandle_text(content.getName()));
 
   87                     protected Image doInBackground() throws Exception {
 
   88                         progressHandle.start();
 
   89                         return ImageUtils.getThumbnail(content, iconSize);
 
   93                     protected void done() {
 
   96                             iconCache = 
new SoftReference<>(super.get());
 
   98                         } 
catch (InterruptedException | ExecutionException ex) {
 
   99                             Logger.getLogger(ThumbnailViewNode.class.getName()).log(Level.SEVERE, 
"Error getting thumbnail icon for " + content.getName(), ex); 
 
  101                             progressHandle.finish();
 
  111                 swingWorker.execute();
 
  114                 timer = 
new Timer(100, (ActionEvent e) -> {
 
  123     public void setIconSize(
int iconSize) {
 
  124         this.iconSize = iconSize;