From 6e7d053bf6047b83c601dc7a2777fa56fe7f2b12 Mon Sep 17 00:00:00 2001 From: "Samuel H. Kenyon" Date: Tue, 27 Aug 2013 20:10:50 -0400 Subject: [PATCH 1/5] Added icon size control to DataResultViewerThumbnail GUI and size changing mechanism in ThumbnailViewNode. --- .../DataResultViewerThumbnail.form | 18 +++++++ .../DataResultViewerThumbnail.java | 50 ++++++++++++++++--- .../corecomponents/ThumbnailViewNode.java | 26 +++++++++- 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form index 48d26daaa7..28f3146098 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form @@ -39,6 +39,8 @@ + + @@ -61,6 +63,7 @@ + @@ -196,5 +199,20 @@ + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index f63e4944c8..8a2ac90496 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -97,6 +97,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { filePathLabel = new javax.swing.JLabel(); goToPageLabel = new javax.swing.JLabel(); goToPageField = new javax.swing.JTextField(); + thumbnailSizeComboBox = new javax.swing.JComboBox(); thumbnailScrollPanel.setPreferredSize(new java.awt.Dimension(582, 348)); @@ -146,6 +147,14 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { } }); + thumbnailSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Small", "Medium", "Large" })); + thumbnailSizeComboBox.setSelectedIndex(1); + thumbnailSizeComboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + thumbnailSizeComboBoxActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -172,8 +181,10 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { .addGap(12, 12, 12) .addComponent(imagesLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(imagesRangeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) + .addComponent(imagesRangeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(thumbnailSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -189,7 +200,8 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { .addComponent(imagesLabel) .addComponent(imagesRangeLabel) .addComponent(goToPageLabel) - .addComponent(goToPageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(goToPageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(thumbnailSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, 0) .addComponent(thumbnailScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -209,6 +221,30 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { goToPage(goToPageField.getText()); }//GEN-LAST:event_goToPageFieldActionPerformed + private void thumbnailSizeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_thumbnailSizeComboBoxActionPerformed + + int newSize = ThumbnailViewNode.ICON_SIZE_MEDIUM; //default size + switch(thumbnailSizeComboBox.getSelectedIndex()) { + case 0: + newSize = ThumbnailViewNode.ICON_SIZE_SMALL; + break; + case 2: + newSize = ThumbnailViewNode.ICON_SIZE_LARGE; + break; + } + + ThumbnailViewNode.setIconSize(newSize); + + Node root = em.getRootContext(); + for (Node page : root.getChildren().getNodes()) { + for (Node node : page.getChildren().getNodes()) { + ThumbnailViewNode tn = (ThumbnailViewNode) node; + tn.setRefresh(true); + } + } + + }//GEN-LAST:event_thumbnailSizeComboBoxActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel filePathLabel; private javax.swing.JTextField goToPageField; @@ -221,6 +257,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { private javax.swing.JButton pagePrevButton; private javax.swing.JLabel pagesLabel; private javax.swing.JScrollPane thumbnailScrollPanel; + private javax.swing.JComboBox thumbnailSizeComboBox; // End of variables declaration//GEN-END:variables @Override @@ -247,7 +284,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { try { if (givenNode != null) { ThumbnailViewChildren childNode = new ThumbnailViewChildren(givenNode); - + final Node root = new AbstractNode(childNode); pageUpdater.setRoot(root); root.addNodeListener(pageUpdater); @@ -377,7 +414,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { progress.start(); progress.switchToIndeterminate(); Node root = em.getRootContext(); - Node pageNode = root.getChildren().getNodeAt(curPage - 1); + Node pageNode = root.getChildren().getNodeAt(curPage - 1); em.setExploredContext(pageNode); curPageImages = pageNode.getChildren().getNodesCount(); return null; @@ -387,8 +424,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { protected void done() { progress.finish(); setCursor(null); - updateControls(); - + updateControls(); } }.execute(); diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index ef562ae0c4..0415130541 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -52,6 +52,12 @@ class ThumbnailViewNode extends FilterNode { private SoftReference iconCache; private static final Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); private static final Logger logger = Logger.getLogger(ThumbnailViewNode.class.getName()); + static final int ICON_SIZE_SMALL = 50; + static final int ICON_SIZE_MEDIUM = 100; + static final int ICON_SIZE_LARGE = 200; + private static int iconWidth = ICON_SIZE_MEDIUM; + private static int iconHeight = ICON_SIZE_MEDIUM; + private boolean refresh = false; //private final BufferedImage defaultIconBI; /** @@ -74,6 +80,10 @@ class ThumbnailViewNode extends FilterNode { public Image getIcon(int type) { Image icon = null; + if (refresh) { + iconCache = null; + } + if (iconCache != null) { icon = iconCache.get(); } @@ -83,7 +93,7 @@ class ThumbnailViewNode extends FilterNode { Content content = this.getLookup().lookup(Content.class); if (content != null) { - if (getFile(content.getId()).exists()) { + if (getFile(content.getId()).exists() && !refresh) { try { icon = ImageIO.read(getFile(content.getId())); if (icon == null) { @@ -109,6 +119,7 @@ class ThumbnailViewNode extends FilterNode { } iconCache = new SoftReference(icon); + refresh = false; } return icon; @@ -127,7 +138,7 @@ class ThumbnailViewNode extends FilterNode { logger.log(Level.WARNING, "No image reader for file: " + content.getName()); return null; } - BufferedImage biScaled = ScalrWrapper.resizeFast(bi, 100, 100); + BufferedImage biScaled = ScalrWrapper.resizeFast(bi, iconWidth, iconHeight); return biScaled; }catch (OutOfMemoryError e) { logger.log(Level.WARNING, "Could not scale image (too large): " + content.getName(), e); @@ -151,4 +162,15 @@ class ThumbnailViewNode extends FilterNode { private static File getFile(long id) { return new File(Case.getCurrentCase().getCacheDirectory() + File.separator + id + ".jpg"); } + + public static void setIconSize(int pixelSize) { + iconWidth = pixelSize; + iconHeight = pixelSize; + //setRefresh(true); + } + + public void setRefresh(boolean flag) { + refresh = flag; + } + } From 5fd85d34938d8db6677242e03db2fa8a4e5d4bb6 Mon Sep 17 00:00:00 2001 From: "Samuel H. Kenyon" Date: Wed, 28 Aug 2013 15:41:08 -0400 Subject: [PATCH 2/5] Added workaround to force update of IconView when changing icon size. Also added "thumbnail" text to the drop-down. --- .../corecomponents/DataResultViewerThumbnail.form | 7 +++---- .../corecomponents/DataResultViewerThumbnail.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form index 28f3146098..fa43e09733 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form @@ -203,12 +203,11 @@ - - - + + + - diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index 8a2ac90496..a30d206cec 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -147,8 +147,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { } }); - thumbnailSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Small", "Medium", "Large" })); - thumbnailSizeComboBox.setSelectedIndex(1); + thumbnailSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Small Thumbnails", "Medium Thumbnails", "Large Thumbnails" })); thumbnailSizeComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { thumbnailSizeComboBoxActionPerformed(evt); @@ -241,8 +240,15 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { ThumbnailViewNode tn = (ThumbnailViewNode) node; tn.setRefresh(true); } - } - + } + + // Temporarily set the explored context to the root, instead of a child node. + // This is a workaround hack to convince org.openide.explorer.ExplorerManager to + // update even though the new and old Node values are identical. This in turn + // will cause the entire view to update completely. After this we + // immediately set the node back to the current child by calling switchPage(). + em.setExploredContext(root); + switchPage(); }//GEN-LAST:event_thumbnailSizeComboBoxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables From fc4b3c58cfadec61020b30157b69d6ebee494680 Mon Sep 17 00:00:00 2001 From: "Samuel H. Kenyon" Date: Wed, 28 Aug 2013 17:55:54 -0400 Subject: [PATCH 3/5] Fix issues with thumbnail page displays not being in sync with the current global user-selected thumnail size. --- .../DataResultViewerThumbnail.form | 1 + .../DataResultViewerThumbnail.java | 11 +- .../corecomponents/ThumbnailViewNode.java | 104 ++++++++++-------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form index fa43e09733..14aac889e5 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.form @@ -208,6 +208,7 @@ + diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index a30d206cec..2243e9ce1a 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -148,6 +148,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { }); thumbnailSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Small Thumbnails", "Medium Thumbnails", "Large Thumbnails" })); + thumbnailSizeComboBox.setSelectedIndex(1); thumbnailSizeComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { thumbnailSizeComboBoxActionPerformed(evt); @@ -234,14 +235,8 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { ThumbnailViewNode.setIconSize(newSize); - Node root = em.getRootContext(); - for (Node page : root.getChildren().getNodes()) { - for (Node node : page.getChildren().getNodes()) { - ThumbnailViewNode tn = (ThumbnailViewNode) node; - tn.setRefresh(true); - } - } - + Node root = em.getRootContext(); + // Temporarily set the explored context to the root, instead of a child node. // This is a workaround hack to convince org.openide.explorer.ExplorerManager to // update even though the new and old Node values are identical. This in turn diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index 0415130541..019543ae97 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -57,7 +57,8 @@ class ThumbnailViewNode extends FilterNode { static final int ICON_SIZE_LARGE = 200; private static int iconWidth = ICON_SIZE_MEDIUM; private static int iconHeight = ICON_SIZE_MEDIUM; - private boolean refresh = false; + private int curWidth = -1; + private int curHeight = -1; //private final BufferedImage defaultIconBI; /** @@ -79,52 +80,67 @@ class ThumbnailViewNode extends FilterNode { @Override public Image getIcon(int type) { Image icon = null; - - if (refresh) { - iconCache = null; - } - - if (iconCache != null) { - icon = iconCache.get(); - } - - - if (icon == null) { + + // If not the correct size, then make a new icon + if (curWidth != iconWidth) { Content content = this.getLookup().lookup(Content.class); - - if (content != null) { - if (getFile(content.getId()).exists() && !refresh) { - try { - icon = ImageIO.read(getFile(content.getId())); - if (icon == null) { - icon = ThumbnailViewNode.defaultIcon; - } - } catch (IOException ex) { - icon = ThumbnailViewNode.defaultIcon; - } - } else { - try { - icon = generateIcon(content); - if (icon == null) { - icon = ThumbnailViewNode.defaultIcon; - } else { - ImageIO.write((BufferedImage) icon, "jpg", getFile(content.getId())); - } - } catch (IOException ex) { - logger.log(Level.WARNING, "Could not write cache thumbnail: " + content, ex); - } - } - } else { - icon = ThumbnailViewNode.defaultIcon; + icon = generateAndSaveIcon(content); + iconCache = new SoftReference(icon); + } else { + + if (iconCache != null) { + icon = iconCache.get(); } - iconCache = new SoftReference(icon); - refresh = false; - } + if (icon == null) { + Content content = this.getLookup().lookup(Content.class); + + if (content != null) { + // If a thumbnail file is already saved locally + if (getFile(content.getId()).exists()) { + try { + icon = ImageIO.read(getFile(content.getId())); + if (icon == null) { + icon = ThumbnailViewNode.defaultIcon; + } + } catch (IOException ex) { + icon = ThumbnailViewNode.defaultIcon; + } + } else { // Make a new icon + icon = generateAndSaveIcon(content); + } + } else { + icon = ThumbnailViewNode.defaultIcon; + } + iconCache = new SoftReference(icon); + } + } + return icon; } + private Image generateAndSaveIcon(Content content) { + Image icon = null; + try { + icon = generateIcon(content); + if (icon == null) { + icon = ThumbnailViewNode.defaultIcon; + } else { + File f = getFile(content.getId()); + if (f.exists()) { + f.delete(); + } + ImageIO.write((BufferedImage) icon, "jpg", getFile(content.getId())); + curWidth = iconWidth; + curHeight = iconHeight; + } + } catch (IOException ex) { + logger.log(Level.WARNING, "Could not write cache thumbnail: " + content, ex); + } + return icon; + } + /* * Generate a scaled image */ @@ -139,6 +155,7 @@ class ThumbnailViewNode extends FilterNode { return null; } BufferedImage biScaled = ScalrWrapper.resizeFast(bi, iconWidth, iconHeight); + return biScaled; }catch (OutOfMemoryError e) { logger.log(Level.WARNING, "Could not scale image (too large): " + content.getName(), e); @@ -166,11 +183,6 @@ class ThumbnailViewNode extends FilterNode { public static void setIconSize(int pixelSize) { iconWidth = pixelSize; iconHeight = pixelSize; - //setRefresh(true); } - - public void setRefresh(boolean flag) { - refresh = flag; - } - + } From 76b53db1b039051d6286daa6739a20f9706855a8 Mon Sep 17 00:00:00 2001 From: "Samuel H. Kenyon" Date: Thu, 29 Aug 2013 16:49:26 -0400 Subject: [PATCH 4/5] Refactored so multiple instances of DataResultViewerThumbnail each maintain their own icon size. --- .../DataResultViewerThumbnail.java | 21 ++++-- .../corecomponents/ThumbnailViewChildren.java | 10 ++- .../corecomponents/ThumbnailViewNode.java | 74 +++++++++---------- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index 2243e9ce1a..728990334b 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -22,6 +22,7 @@ import java.awt.Color; import java.awt.Cursor; import java.awt.EventQueue; import java.beans.PropertyChangeEvent; +import java.util.Arrays; import java.util.logging.Level; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; @@ -58,6 +59,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { private int curPage; private int totalPages; private int curPageImages; + private int iconSize = ThumbnailViewNode.ICON_SIZE_MEDIUM; private final PageUpdater pageUpdater = new PageUpdater(); /** @@ -223,19 +225,26 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { private void thumbnailSizeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_thumbnailSizeComboBoxActionPerformed - int newSize = ThumbnailViewNode.ICON_SIZE_MEDIUM; //default size + iconSize = ThumbnailViewNode.ICON_SIZE_MEDIUM; //default size switch(thumbnailSizeComboBox.getSelectedIndex()) { case 0: - newSize = ThumbnailViewNode.ICON_SIZE_SMALL; + iconSize = ThumbnailViewNode.ICON_SIZE_SMALL; break; case 2: - newSize = ThumbnailViewNode.ICON_SIZE_LARGE; + iconSize = ThumbnailViewNode.ICON_SIZE_LARGE; break; } - ThumbnailViewNode.setIconSize(newSize); + Node root = em.getRootContext(); + for (Children c : Arrays.asList(root.getChildren()) ) { + ((ThumbnailViewChildren)c).setIconSize(iconSize); + } - Node root = em.getRootContext(); + for (Node page : root.getChildren().getNodes()) { + for (Node node : page.getChildren().getNodes()) { + ((ThumbnailViewNode)node).setIconSize(iconSize); + } + } // Temporarily set the explored context to the root, instead of a child node. // This is a workaround hack to convince org.openide.explorer.ExplorerManager to @@ -284,7 +293,7 @@ public final class DataResultViewerThumbnail extends AbstractDataResultViewer { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if (givenNode != null) { - ThumbnailViewChildren childNode = new ThumbnailViewChildren(givenNode); + ThumbnailViewChildren childNode = new ThumbnailViewChildren(givenNode, iconSize); final Node root = new AbstractNode(childNode); pageUpdater.setRoot(root); diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java index 3ad547d12a..7c4284cbf3 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java @@ -52,15 +52,17 @@ class ThumbnailViewChildren extends Children.Keys { private final HashMap> pages = new HashMap>(); private int totalImages = 0; private int totalPages = 0; + private int iconSize = ThumbnailViewNode.ICON_SIZE_MEDIUM; private static final Logger logger = Logger.getLogger(ThumbnailViewChildren.class.getName()); /** * the constructor */ - ThumbnailViewChildren(Node arg) { + ThumbnailViewChildren(Node arg, int iconSize) { super(true); //support lazy loading this.parent = arg; + this.iconSize = iconSize; // } @@ -153,6 +155,10 @@ class ThumbnailViewChildren extends Children.Keys { return false; } + public void setIconSize(int iconSize) { + this.iconSize = iconSize; + } + private static class IsSupportedContentVisitor extends ContentVisitor.Default { private final List SUPP_EXTENSIONS; @@ -255,7 +261,7 @@ class ThumbnailViewChildren extends Children.Keys { @Override protected Node[] createNodes(Node wrapped) { if (wrapped != null) { - final ThumbnailViewNode thumb = new ThumbnailViewNode(wrapped); + final ThumbnailViewNode thumb = new ThumbnailViewNode(wrapped, iconSize); return new Node[]{thumb}; } else { return new Node[]{}; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index 019543ae97..b69c7db3f5 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -49,23 +49,21 @@ import org.sleuthkit.datamodel.TskException; */ class ThumbnailViewNode extends FilterNode { - private SoftReference iconCache; + private SoftReference iconCache = null; private static final Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); private static final Logger logger = Logger.getLogger(ThumbnailViewNode.class.getName()); static final int ICON_SIZE_SMALL = 50; static final int ICON_SIZE_MEDIUM = 100; static final int ICON_SIZE_LARGE = 200; - private static int iconWidth = ICON_SIZE_MEDIUM; - private static int iconHeight = ICON_SIZE_MEDIUM; - private int curWidth = -1; - private int curHeight = -1; + private int iconSize = ICON_SIZE_MEDIUM; //private final BufferedImage defaultIconBI; /** * the constructor */ - ThumbnailViewNode(Node arg) { + ThumbnailViewNode(Node arg, int iconSize) { super(arg, Children.LEAF); + this.iconSize = iconSize; } @Override @@ -80,41 +78,37 @@ class ThumbnailViewNode extends FilterNode { @Override public Image getIcon(int type) { Image icon = null; - - // If not the correct size, then make a new icon - if (curWidth != iconWidth) { + + if (iconCache != null) { + icon = iconCache.get(); + } + + if (icon == null) { Content content = this.getLookup().lookup(Content.class); - icon = generateAndSaveIcon(content); - iconCache = new SoftReference(icon); - } else { - - if (iconCache != null) { - icon = iconCache.get(); - } - if (icon == null) { - Content content = this.getLookup().lookup(Content.class); - - if (content != null) { - // If a thumbnail file is already saved locally - if (getFile(content.getId()).exists()) { - try { - icon = ImageIO.read(getFile(content.getId())); - if (icon == null) { - icon = ThumbnailViewNode.defaultIcon; - } - } catch (IOException ex) { + if (content != null) { + // If a thumbnail file is already saved locally + if (getFile(content.getId()).exists()) { + try { + BufferedImage bicon = ImageIO.read(getFile(content.getId())); + if (bicon == null) { icon = ThumbnailViewNode.defaultIcon; + } else if (bicon.getWidth() != iconSize) { + icon = generateAndSaveIcon(content); + } else { + icon = bicon; } - } else { // Make a new icon - icon = generateAndSaveIcon(content); + } catch (IOException ex) { + icon = ThumbnailViewNode.defaultIcon; } - } else { - icon = ThumbnailViewNode.defaultIcon; + } else { // Make a new icon + icon = generateAndSaveIcon(content); } - - iconCache = new SoftReference(icon); + } else { + icon = ThumbnailViewNode.defaultIcon; } + + iconCache = new SoftReference(icon); } return icon; @@ -132,8 +126,6 @@ class ThumbnailViewNode extends FilterNode { f.delete(); } ImageIO.write((BufferedImage) icon, "jpg", getFile(content.getId())); - curWidth = iconWidth; - curHeight = iconHeight; } } catch (IOException ex) { logger.log(Level.WARNING, "Could not write cache thumbnail: " + content, ex); @@ -144,7 +136,7 @@ class ThumbnailViewNode extends FilterNode { /* * Generate a scaled image */ - static private BufferedImage generateIcon(Content content) { + private BufferedImage generateIcon(Content content) { InputStream inputStream = null; try { @@ -154,7 +146,7 @@ class ThumbnailViewNode extends FilterNode { logger.log(Level.WARNING, "No image reader for file: " + content.getName()); return null; } - BufferedImage biScaled = ScalrWrapper.resizeFast(bi, iconWidth, iconHeight); + BufferedImage biScaled = ScalrWrapper.resizeFast(bi, iconSize); return biScaled; }catch (OutOfMemoryError e) { @@ -180,9 +172,9 @@ class ThumbnailViewNode extends FilterNode { return new File(Case.getCurrentCase().getCacheDirectory() + File.separator + id + ".jpg"); } - public static void setIconSize(int pixelSize) { - iconWidth = pixelSize; - iconHeight = pixelSize; + public void setIconSize(int iconSize) { + this.iconSize = iconSize; + iconCache = null; } } From 96a5e5c7077c078b5d9edb650821f8536bb07549 Mon Sep 17 00:00:00 2001 From: "Samuel H. Kenyon" Date: Fri, 30 Aug 2013 15:38:55 -0400 Subject: [PATCH 5/5] Modified Case to not pull appName from Version statically; instead it now asks the MainWindow for its title and saves that as appName. --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 6c1d0d6db1..91c8a8ac5a 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -59,7 +59,7 @@ import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess; public class Case implements SleuthkitCase.ErrorObserver { private static final String autopsyVer = Version.getVersion(); // current version of autopsy. Change it when the version is changed - private static final String appName = Version.getName() + " " + autopsyVer; + private static String appName = null; /** * Property name that indicates the name of the current case has changed. * Fired with the case is renamed, and when the current case is @@ -507,6 +507,9 @@ public class Case implements SleuthkitCase.ErrorObserver { * @return appName */ public static String getAppName() { + if ((appName == null ) || appName.equals("")) { + appName = WindowManager.getDefault().getMainWindow().getTitle(); + } return appName; }