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.netbeans.api.progress.ProgressHandleFactory;
32 import org.openide.nodes.FilterNode;
33 import org.openide.nodes.Node;
34 import org.openide.util.NbBundle;
43 class ThumbnailViewNode
extends FilterNode {
45 static private final Image waitingIcon = Toolkit.getDefaultToolkit().createImage(ThumbnailViewNode.class.getResource(
"/org/sleuthkit/autopsy/images/working_spinner.gif"));
47 private SoftReference<Image> iconCache = null;
48 private int iconSize = ImageUtils.ICON_SIZE_MEDIUM;
50 private SwingWorker<Image, Object> swingWorker;
56 ThumbnailViewNode(Node arg,
int iconSize) {
57 super(arg, Children.LEAF);
58 this.iconSize = iconSize;
62 public String getDisplayName() {
63 return StringUtils.abbreviate(super.getDisplayName(), 18);
67 @NbBundle.Messages({
"# {0} - file name",
68 "ThumbnailViewNode.progressHandle.text=Generating thumbnail for {0}"})
69 public Image getIcon(
int type) {
72 if (iconCache != null) {
73 icon = iconCache.get();
79 final Content content = this.getLookup().lookup(Content.class);
80 if (content == null) {
81 return ImageUtils.getDefaultThumbnail();
83 if (swingWorker == null || swingWorker.isDone()) {
84 swingWorker =
new SwingWorker<Image, Object>() {
85 final private ProgressHandle progressHandle = ProgressHandleFactory.createHandle(Bundle.ThumbnailViewNode_progressHandle_text(content.getName()));
88 protected Image doInBackground() throws Exception {
89 progressHandle.start();
90 return ImageUtils.getThumbnail(content, iconSize);
94 protected void done() {
97 iconCache =
new SoftReference<>(super.get());
99 }
catch (InterruptedException | ExecutionException ex) {
100 Logger.getLogger(ThumbnailViewNode.class.getName()).log(Level.SEVERE,
"Error getting thumbnail icon for " + content.getName(), ex);
102 progressHandle.finish();
112 swingWorker.execute();
115 timer =
new Timer(100, (ActionEvent e) -> {
124 public void setIconSize(
int iconSize) {
125 this.iconSize = iconSize;