From e148978437ac7811fd00b84bd3c768f0736fb845 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 9 Jul 2015 17:43:22 -0400 Subject: [PATCH] reduce duplication in DataContentViewerMEdia and MediaViewImagePanel by moving common code to ImageUtils --- Core/nbproject/project.xml | 2 +- .../DataContentViewerMedia.java | 28 +--- .../corecomponents/MediaViewImagePanel.java | 11 +- .../autopsy/coreutils/ImageUtils.java | 34 +++- ImageGallery/nbproject/project.xml | 2 +- .../netbeans/core/startup/Bundle.properties | 4 +- .../core/windows/view/ui/Bundle.properties | 6 +- nbproject/platform.properties | 145 +++++++++++++----- nbproject/project.properties | 4 +- 9 files changed, 149 insertions(+), 87 deletions(-) diff --git a/Core/nbproject/project.xml b/Core/nbproject/project.xml index 2e0bf14ac4..463e1c1903 100644 --- a/Core/nbproject/project.xml +++ b/Core/nbproject/project.xml @@ -177,7 +177,7 @@ 3 - 1.1 + 1.0 diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerMedia.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerMedia.java index e3ea57d314..b5c560d082 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerMedia.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerMedia.java @@ -217,33 +217,7 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo * @return True if an image file that can be displayed */ private boolean isImageSupported(AbstractFile file) { - String name = file.getNameExtension(); - - // blackboard - try { - String mimeType = new FileTypeDetector().getFileType(file); - if (nonNull(mimeType)) { - return imageMimes.contains(mimeType); - } - } catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) { - logger.log(Level.WARNING, "Failed to look up mimetype for " + file.getName() + " using FileTypeDetector. Fallingback on AbstractFile.isMimeType", ex); - if (!imageMimes.isEmpty()) { - MimeMatchEnum mimeMatch = file.isMimeType(imageMimes); - if (mimeMatch == MimeMatchEnum.TRUE) { - return true; - } else if (mimeMatch == MimeMatchEnum.FALSE) { - return false; - } - } - } - - // extension - if (imageExtensions.contains("." + name)) { - return true; - } - - // our own signature checks for important types - return ImageUtils.isJpegFileHeader(file) || ImageUtils.isPngFileHeader(file); + return ImageUtils.thumbnailSupported(file); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MediaViewImagePanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MediaViewImagePanel.java index 73fdac25f1..cf89c28180 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MediaViewImagePanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MediaViewImagePanel.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.corecomponents; +import com.google.common.collect.Lists; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.image.BufferedImage; @@ -25,9 +26,9 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.SortedSet; import java.util.logging.Level; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; @@ -45,6 +46,7 @@ import javax.swing.JPanel; import javax.swing.SwingUtilities; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.ThreadConfined; @@ -69,7 +71,8 @@ public class MediaViewImagePanel extends JPanel { * mime types we shoul dbe able to display. if the mimetype is unknown we * will fall back on extension (and jpg/png header */ - static private final List supportedMimes = new ArrayList<>(); + static private final SortedSet supportedMimes = ImageUtils.getSupportedMimeTypes(); + /** * extensions we should be able to display */ @@ -84,8 +87,6 @@ public class MediaViewImagePanel extends JPanel { for (String suffix : ImageIO.getReaderFileSuffixes()) { supportedExtensions.add("." + suffix); } - supportedMimes.addAll(Arrays.asList(ImageIO.getReaderMIMETypes())); - supportedMimes.add("image/x-ms-bmp"); //NON-NLS) } /** @@ -195,7 +196,7 @@ public class MediaViewImagePanel extends JPanel { * @return supported mime types */ public List getMimeTypes() { - return Collections.unmodifiableList(supportedMimes); + return Collections.unmodifiableList(Lists.newArrayList(supportedMimes)); } /** diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index 406ada920d..7db63ceaef 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -2,7 +2,7 @@ * * Autopsy Forensic Browser * - * Copyright 2012 Basis Technology Corp. + * Copyright 2012-15 Basis Technology Corp. * * Copyright 2012 42six Solutions. * Contact: aebadirad 42six com @@ -30,11 +30,13 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import static java.util.Objects.isNull; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.logging.Level; @@ -53,20 +55,31 @@ import org.sleuthkit.datamodel.ReadContentInputStream; import org.sleuthkit.datamodel.TskCoreException; /** - * Utilities for creating and manipulating thumbnail and icon images. + * Utilities for working with Images and creating thumbnails. Reuses thumbnails + * by storing them in the case's cache directory. */ public class ImageUtils { + private static final Logger LOGGER = Logger.getLogger(ImageUtils.class.getName()); /** save thumbnails to disk as this format */ private static final String FORMAT = "png"; public static final int ICON_SIZE_SMALL = 50; public static final int ICON_SIZE_MEDIUM = 100; public static final int ICON_SIZE_LARGE = 200; - private static final Logger LOGGER = Logger.getLogger(ImageUtils.class.getName()); + private static final Image DEFAULT_ICON = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); //NON-NLS + private static final List SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes()); - private static final List SUPP_MIME_TYPES = new ArrayList<>(Arrays.asList(ImageIO.getReaderMIMETypes())); + + public static List getSupportedExtensions() { + return SUPP_EXTENSIONS; + } + + public static SortedSet getSupportedMimeTypes() { + return Collections.unmodifiableSortedSet(SUPP_MIME_TYPES); + } + private static final TreeSet SUPP_MIME_TYPES = new TreeSet<>(Arrays.asList(ImageIO.getReaderMIMETypes())); /** thread that saves generated thumbnails to disk for use later */ private static final Executor imageSaver = Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder().namingPattern("icon saver-%d").build()); @@ -107,7 +120,16 @@ public class ImageUtils { return SUPP_MIME_TYPES.contains(mimeType); } } catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) { - LOGGER.log(Level.WARNING, "Error while getting file signature from blackboard.", ex); //NON-NLS + + LOGGER.log(Level.WARNING, "Failed to look up mimetype for " + file.getName() + " using FileTypeDetector. Fallingback on AbstractFile.isMimeType", ex); + if (!SUPP_MIME_TYPES.isEmpty()) { + AbstractFile.MimeMatchEnum mimeMatch = file.isMimeType(SUPP_MIME_TYPES); + if (mimeMatch == AbstractFile.MimeMatchEnum.TRUE) { + return true; + } else if (mimeMatch == AbstractFile.MimeMatchEnum.FALSE) { + return false; + } + } } // if we have an extension, check it diff --git a/ImageGallery/nbproject/project.xml b/ImageGallery/nbproject/project.xml index 2a28ce3deb..ab6cd75280 100644 --- a/ImageGallery/nbproject/project.xml +++ b/ImageGallery/nbproject/project.xml @@ -4,7 +4,7 @@ org.sleuthkit.autopsy.imagegallery - + org.netbeans.api.progress diff --git a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties index fa4b5fa2cd..09b8822c3f 100644 --- a/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties +++ b/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties @@ -1,5 +1,5 @@ #Updated by build script -#Thu, 09 Jul 2015 12:49:41 -0400 +#Wed, 15 Apr 2015 18:11:08 -0400 LBL_splash_window_title=Starting Autopsy SPLASH_HEIGHT=314 SPLASH_WIDTH=538 @@ -8,4 +8,4 @@ SplashRunningTextBounds=0,289,538,18 SplashRunningTextColor=0x0 SplashRunningTextFontSize=19 -currentVersion=Autopsy 3.1.3 +currentVersion=Autopsy 3.1.2 diff --git a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties index 33f711d800..4bfb72271d 100644 --- a/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties +++ b/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -1,5 +1,5 @@ #Updated by build script -#Thu, 09 Jul 2015 12:49:41 -0400 +#Wed, 15 Apr 2015 18:11:08 -0400 -CTL_MainWindow_Title=Autopsy 3.1.3 -CTL_MainWindow_Title_No_Project=Autopsy 3.1.3 +CTL_MainWindow_Title=Autopsy 3.1.2 +CTL_MainWindow_Title_No_Project=Autopsy 3.1.2 diff --git a/nbproject/platform.properties b/nbproject/platform.properties index 4cfc404047..1554e42acf 100644 --- a/nbproject/platform.properties +++ b/nbproject/platform.properties @@ -1,5 +1,4 @@ branding.token=autopsy -nbjdk.active=JDK_1.8_45_x64 # Version of platform that is automatically downloaded # Note build.xml has similar definitions that should be kept in sync (manually) netbeans-plat-version=7.3.1 @@ -14,43 +13,111 @@ cluster.path=\ ${nbplatform.active.dir}/java:\ ${nbplatform.active.dir}/platform disabled.modules=\ - org.jdesktop.layout,\ - org.netbeans.api.search,\ - org.netbeans.core.execution,\ - org.netbeans.core.io.ui,\ - org.netbeans.core.nativeaccess,\ - org.netbeans.core.netigso,\ - org.netbeans.core.osgi,\ - org.netbeans.core.ui,\ - org.netbeans.libs.felix,\ - org.netbeans.libs.jna,\ - org.netbeans.libs.jsr223,\ - org.netbeans.libs.osgi,\ - org.netbeans.libs.testng,\ - org.netbeans.modules.applemenu,\ - org.netbeans.modules.autoupdate.cli,\ - org.netbeans.modules.autoupdate.services,\ - org.netbeans.modules.autoupdate.ui,\ - org.netbeans.modules.core.kit,\ - org.netbeans.modules.editor.mimelookup.impl,\ - org.netbeans.modules.favorites,\ - org.netbeans.modules.javahelp,\ - org.netbeans.modules.jellytools.java,\ + org.apache.tools.ant.module,\ + org.netbeans.api.debugger.jpda,\ + org.netbeans.api.java,\ + org.netbeans.lib.nbjavac,\ + org.netbeans.libs.cglib,\ + org.netbeans.libs.javacapi,\ + org.netbeans.libs.javacimpl,\ + org.netbeans.libs.springframework,\ + org.netbeans.modules.ant.browsetask,\ + org.netbeans.modules.ant.debugger,\ + org.netbeans.modules.ant.freeform,\ + org.netbeans.modules.ant.grammar,\ + org.netbeans.modules.ant.kit,\ + org.netbeans.modules.beans,\ + org.netbeans.modules.classfile,\ + org.netbeans.modules.dbschema,\ + org.netbeans.modules.debugger.jpda,\ + org.netbeans.modules.debugger.jpda.ant,\ + org.netbeans.modules.debugger.jpda.kit,\ + org.netbeans.modules.debugger.jpda.projects,\ + org.netbeans.modules.debugger.jpda.ui,\ + org.netbeans.modules.debugger.jpda.visual,\ + org.netbeans.modules.findbugs.installer,\ + org.netbeans.modules.form,\ + org.netbeans.modules.form.binding,\ + org.netbeans.modules.form.j2ee,\ + org.netbeans.modules.form.kit,\ + org.netbeans.modules.form.nb,\ + org.netbeans.modules.form.refactoring,\ + org.netbeans.modules.hibernate,\ + org.netbeans.modules.hibernatelib,\ + org.netbeans.modules.hudson.ant,\ + org.netbeans.modules.hudson.maven,\ + org.netbeans.modules.i18n,\ + org.netbeans.modules.i18n.form,\ + org.netbeans.modules.j2ee.core.utilities,\ + org.netbeans.modules.j2ee.eclipselink,\ + org.netbeans.modules.j2ee.eclipselinkmodelgen,\ + org.netbeans.modules.j2ee.jpa.refactoring,\ + org.netbeans.modules.j2ee.jpa.verification,\ + org.netbeans.modules.j2ee.metadata,\ + org.netbeans.modules.j2ee.metadata.model.support,\ + org.netbeans.modules.j2ee.persistence,\ + org.netbeans.modules.j2ee.persistence.kit,\ + org.netbeans.modules.j2ee.persistenceapi,\ + org.netbeans.modules.java.api.common,\ + org.netbeans.modules.java.debug,\ + org.netbeans.modules.java.editor,\ + org.netbeans.modules.java.editor.lib,\ + org.netbeans.modules.java.examples,\ + org.netbeans.modules.java.freeform,\ + org.netbeans.modules.java.guards,\ + org.netbeans.modules.java.helpset,\ + org.netbeans.modules.java.hints,\ + org.netbeans.modules.java.hints.declarative,\ + org.netbeans.modules.java.hints.declarative.test,\ + org.netbeans.modules.java.hints.legacy.spi,\ + org.netbeans.modules.java.hints.test,\ + org.netbeans.modules.java.hints.ui,\ + org.netbeans.modules.java.j2seplatform,\ + org.netbeans.modules.java.j2seproject,\ + org.netbeans.modules.java.kit,\ + org.netbeans.modules.java.lexer,\ + org.netbeans.modules.java.navigation,\ + org.netbeans.modules.java.platform,\ + org.netbeans.modules.java.preprocessorbridge,\ + org.netbeans.modules.java.project,\ + org.netbeans.modules.java.source,\ + org.netbeans.modules.java.source.ant,\ + org.netbeans.modules.java.source.queries,\ + org.netbeans.modules.java.source.queriesimpl,\ + org.netbeans.modules.java.sourceui,\ + org.netbeans.modules.java.testrunner,\ + org.netbeans.modules.javadoc,\ + org.netbeans.modules.javawebstart,\ org.netbeans.modules.junit,\ - org.netbeans.modules.junitlib,\ - org.netbeans.modules.keyring.impl,\ - org.netbeans.modules.masterfs,\ - org.netbeans.modules.masterfs.linux,\ - org.netbeans.modules.masterfs.macosx,\ - org.netbeans.modules.masterfs.solaris,\ - org.netbeans.modules.masterfs.windows,\ - org.netbeans.modules.netbinox,\ - org.netbeans.modules.print,\ - org.netbeans.modules.progress.ui,\ - org.netbeans.modules.spi.actions,\ - org.netbeans.modules.whitelist,\ - org.openide.compat,\ - org.openide.execution,\ - org.openide.options,\ - org.openide.util.enumerations + org.netbeans.modules.maven,\ + org.netbeans.modules.maven.checkstyle,\ + org.netbeans.modules.maven.coverage,\ + org.netbeans.modules.maven.embedder,\ + org.netbeans.modules.maven.grammar,\ + org.netbeans.modules.maven.graph,\ + org.netbeans.modules.maven.hints,\ + org.netbeans.modules.maven.indexer,\ + org.netbeans.modules.maven.junit,\ + org.netbeans.modules.maven.kit,\ + org.netbeans.modules.maven.model,\ + org.netbeans.modules.maven.osgi,\ + org.netbeans.modules.maven.persistence,\ + org.netbeans.modules.maven.refactoring,\ + org.netbeans.modules.maven.repository,\ + org.netbeans.modules.maven.search,\ + org.netbeans.modules.maven.spring,\ + org.netbeans.modules.projectimport.eclipse.core,\ + org.netbeans.modules.projectimport.eclipse.j2se,\ + org.netbeans.modules.refactoring.java,\ + org.netbeans.modules.spellchecker.bindings.java,\ + org.netbeans.modules.spring.beans,\ + org.netbeans.modules.testng,\ + org.netbeans.modules.testng.ant,\ + org.netbeans.modules.testng.maven,\ + org.netbeans.modules.websvc.jaxws21,\ + org.netbeans.modules.websvc.jaxws21api,\ + org.netbeans.modules.websvc.saas.codegen.java,\ + org.netbeans.modules.xml.jaxb,\ + org.netbeans.modules.xml.tools.java,\ + org.netbeans.spi.java.hints diff --git a/nbproject/project.properties b/nbproject/project.properties index f80c2ec8a8..d46c65d75a 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -10,7 +10,6 @@ app.version=3.1.3 #build.type=RELEASE build.type=DEVELOPMENT -project.org.sleuthkit.autopsy.imagegallery=ImageGallery update_versions=false #custom JVM options #Note: can be higher on 64 bit systems, should be in sync with build.xml @@ -28,8 +27,7 @@ modules=\ ${project.org.sleuthkit.autopsy.testing}:\ ${project.org.sleuthkit.autopsy.thunderbirdparser}:\ ${project.org.sleuthkit.autopsy.core}:\ - ${project.org.sleuthkit.autopsy.corelibs}:\ - ${project.org.sleuthkit.autopsy.imagegallery} + ${project.org.sleuthkit.autopsy.corelibs} project.org.sleuthkit.autopsy.core=Core project.org.sleuthkit.autopsy.corelibs=CoreLibs project.org.sleuthkit.autopsy.keywordsearch=KeywordSearch