reduce duplication in DataContentViewerMEdia and MediaViewImagePanel by moving common code to ImageUtils

This commit is contained in:
jmillman 2015-07-09 17:43:22 -04:00
parent c9bcf48acc
commit e148978437
9 changed files with 149 additions and 87 deletions

View File

@ -177,7 +177,7 @@
<compile-dependency/> <compile-dependency/>
<run-dependency> <run-dependency>
<release-version>3</release-version> <release-version>3</release-version>
<specification-version>1.1</specification-version> <specification-version>1.0</specification-version>
</run-dependency> </run-dependency>
</dependency> </dependency>
</module-dependencies> </module-dependencies>

View File

@ -217,33 +217,7 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
* @return True if an image file that can be displayed * @return True if an image file that can be displayed
*/ */
private boolean isImageSupported(AbstractFile file) { private boolean isImageSupported(AbstractFile file) {
String name = file.getNameExtension(); return ImageUtils.thumbnailSupported(file);
// 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);
} }
@Override @Override

View File

@ -18,6 +18,7 @@
*/ */
package org.sleuthkit.autopsy.corecomponents; package org.sleuthkit.autopsy.corecomponents;
import com.google.common.collect.Lists;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -25,9 +26,9 @@ import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.SortedSet;
import java.util.logging.Level; import java.util.logging.Level;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.embed.swing.JFXPanel; import javafx.embed.swing.JFXPanel;
@ -45,6 +46,7 @@ import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.ImageUtils;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.coreutils.ThreadConfined; 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 * mime types we shoul dbe able to display. if the mimetype is unknown we
* will fall back on extension (and jpg/png header * will fall back on extension (and jpg/png header
*/ */
static private final List<String> supportedMimes = new ArrayList<>(); static private final SortedSet<String> supportedMimes = ImageUtils.getSupportedMimeTypes();
/** /**
* extensions we should be able to display * extensions we should be able to display
*/ */
@ -84,8 +87,6 @@ public class MediaViewImagePanel extends JPanel {
for (String suffix : ImageIO.getReaderFileSuffixes()) { for (String suffix : ImageIO.getReaderFileSuffixes()) {
supportedExtensions.add("." + suffix); 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 * @return supported mime types
*/ */
public List<String> getMimeTypes() { public List<String> getMimeTypes() {
return Collections.unmodifiableList(supportedMimes); return Collections.unmodifiableList(Lists.newArrayList(supportedMimes));
} }
/** /**

View File

@ -2,7 +2,7 @@
* *
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2012 Basis Technology Corp. * Copyright 2012-15 Basis Technology Corp.
* *
* Copyright 2012 42six Solutions. * Copyright 2012 42six Solutions.
* Contact: aebadirad <at> 42six <dot> com * Contact: aebadirad <at> 42six <dot> com
@ -30,11 +30,13 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static java.util.Objects.isNull; import static java.util.Objects.isNull;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.logging.Level; import java.util.logging.Level;
@ -53,20 +55,31 @@ import org.sleuthkit.datamodel.ReadContentInputStream;
import org.sleuthkit.datamodel.TskCoreException; 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 { public class ImageUtils {
private static final Logger LOGGER = Logger.getLogger(ImageUtils.class.getName());
/** save thumbnails to disk as this format */ /** save thumbnails to disk as this format */
private static final String FORMAT = "png"; private static final String FORMAT = "png";
public static final int ICON_SIZE_SMALL = 50; public static final int ICON_SIZE_SMALL = 50;
public static final int ICON_SIZE_MEDIUM = 100; public static final int ICON_SIZE_MEDIUM = 100;
public static final int ICON_SIZE_LARGE = 200; 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 Image DEFAULT_ICON = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); //NON-NLS
private static final List<String> SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes()); private static final List<String> SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes());
private static final List<String> SUPP_MIME_TYPES = new ArrayList<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
public static List<String> getSupportedExtensions() {
return SUPP_EXTENSIONS;
}
public static SortedSet<String> getSupportedMimeTypes() {
return Collections.unmodifiableSortedSet(SUPP_MIME_TYPES);
}
private static final TreeSet<String> SUPP_MIME_TYPES = new TreeSet<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
/** thread that saves generated thumbnails to disk for use later */ /** 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()); 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); return SUPP_MIME_TYPES.contains(mimeType);
} }
} catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) { } 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 // if we have an extension, check it

View File

@ -4,7 +4,7 @@
<configuration> <configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.sleuthkit.autopsy.imagegallery</code-name-base> <code-name-base>org.sleuthkit.autopsy.imagegallery</code-name-base>
<suite-component/> <standalone/>
<module-dependencies> <module-dependencies>
<dependency> <dependency>
<code-name-base>org.netbeans.api.progress</code-name-base> <code-name-base>org.netbeans.api.progress</code-name-base>

View File

@ -1,5 +1,5 @@
#Updated by build script #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 LBL_splash_window_title=Starting Autopsy
SPLASH_HEIGHT=314 SPLASH_HEIGHT=314
SPLASH_WIDTH=538 SPLASH_WIDTH=538
@ -8,4 +8,4 @@ SplashRunningTextBounds=0,289,538,18
SplashRunningTextColor=0x0 SplashRunningTextColor=0x0
SplashRunningTextFontSize=19 SplashRunningTextFontSize=19
currentVersion=Autopsy 3.1.3 currentVersion=Autopsy 3.1.2

View File

@ -1,5 +1,5 @@
#Updated by build script #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=Autopsy 3.1.2
CTL_MainWindow_Title_No_Project=Autopsy 3.1.3 CTL_MainWindow_Title_No_Project=Autopsy 3.1.2

View File

@ -1,5 +1,4 @@
branding.token=autopsy branding.token=autopsy
nbjdk.active=JDK_1.8_45_x64
# Version of platform that is automatically downloaded # Version of platform that is automatically downloaded
# Note build.xml has similar definitions that should be kept in sync (manually) # Note build.xml has similar definitions that should be kept in sync (manually)
netbeans-plat-version=7.3.1 netbeans-plat-version=7.3.1
@ -14,43 +13,111 @@ cluster.path=\
${nbplatform.active.dir}/java:\ ${nbplatform.active.dir}/java:\
${nbplatform.active.dir}/platform ${nbplatform.active.dir}/platform
disabled.modules=\ disabled.modules=\
org.jdesktop.layout,\ org.apache.tools.ant.module,\
org.netbeans.api.search,\ org.netbeans.api.debugger.jpda,\
org.netbeans.core.execution,\ org.netbeans.api.java,\
org.netbeans.core.io.ui,\ org.netbeans.lib.nbjavac,\
org.netbeans.core.nativeaccess,\ org.netbeans.libs.cglib,\
org.netbeans.core.netigso,\ org.netbeans.libs.javacapi,\
org.netbeans.core.osgi,\ org.netbeans.libs.javacimpl,\
org.netbeans.core.ui,\ org.netbeans.libs.springframework,\
org.netbeans.libs.felix,\ org.netbeans.modules.ant.browsetask,\
org.netbeans.libs.jna,\ org.netbeans.modules.ant.debugger,\
org.netbeans.libs.jsr223,\ org.netbeans.modules.ant.freeform,\
org.netbeans.libs.osgi,\ org.netbeans.modules.ant.grammar,\
org.netbeans.libs.testng,\ org.netbeans.modules.ant.kit,\
org.netbeans.modules.applemenu,\ org.netbeans.modules.beans,\
org.netbeans.modules.autoupdate.cli,\ org.netbeans.modules.classfile,\
org.netbeans.modules.autoupdate.services,\ org.netbeans.modules.dbschema,\
org.netbeans.modules.autoupdate.ui,\ org.netbeans.modules.debugger.jpda,\
org.netbeans.modules.core.kit,\ org.netbeans.modules.debugger.jpda.ant,\
org.netbeans.modules.editor.mimelookup.impl,\ org.netbeans.modules.debugger.jpda.kit,\
org.netbeans.modules.favorites,\ org.netbeans.modules.debugger.jpda.projects,\
org.netbeans.modules.javahelp,\ org.netbeans.modules.debugger.jpda.ui,\
org.netbeans.modules.jellytools.java,\ 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.junit,\
org.netbeans.modules.junitlib,\ org.netbeans.modules.maven,\
org.netbeans.modules.keyring.impl,\ org.netbeans.modules.maven.checkstyle,\
org.netbeans.modules.masterfs,\ org.netbeans.modules.maven.coverage,\
org.netbeans.modules.masterfs.linux,\ org.netbeans.modules.maven.embedder,\
org.netbeans.modules.masterfs.macosx,\ org.netbeans.modules.maven.grammar,\
org.netbeans.modules.masterfs.solaris,\ org.netbeans.modules.maven.graph,\
org.netbeans.modules.masterfs.windows,\ org.netbeans.modules.maven.hints,\
org.netbeans.modules.netbinox,\ org.netbeans.modules.maven.indexer,\
org.netbeans.modules.print,\ org.netbeans.modules.maven.junit,\
org.netbeans.modules.progress.ui,\ org.netbeans.modules.maven.kit,\
org.netbeans.modules.spi.actions,\ org.netbeans.modules.maven.model,\
org.netbeans.modules.whitelist,\ org.netbeans.modules.maven.osgi,\
org.openide.compat,\ org.netbeans.modules.maven.persistence,\
org.openide.execution,\ org.netbeans.modules.maven.refactoring,\
org.openide.options,\ org.netbeans.modules.maven.repository,\
org.openide.util.enumerations 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

View File

@ -10,7 +10,6 @@ app.version=3.1.3
#build.type=RELEASE #build.type=RELEASE
build.type=DEVELOPMENT build.type=DEVELOPMENT
project.org.sleuthkit.autopsy.imagegallery=ImageGallery
update_versions=false update_versions=false
#custom JVM options #custom JVM options
#Note: can be higher on 64 bit systems, should be in sync with build.xml #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.testing}:\
${project.org.sleuthkit.autopsy.thunderbirdparser}:\ ${project.org.sleuthkit.autopsy.thunderbirdparser}:\
${project.org.sleuthkit.autopsy.core}:\ ${project.org.sleuthkit.autopsy.core}:\
${project.org.sleuthkit.autopsy.corelibs}:\ ${project.org.sleuthkit.autopsy.corelibs}
${project.org.sleuthkit.autopsy.imagegallery}
project.org.sleuthkit.autopsy.core=Core project.org.sleuthkit.autopsy.core=Core
project.org.sleuthkit.autopsy.corelibs=CoreLibs project.org.sleuthkit.autopsy.corelibs=CoreLibs
project.org.sleuthkit.autopsy.keywordsearch=KeywordSearch project.org.sleuthkit.autopsy.keywordsearch=KeywordSearch