Skip to content

Commit

Permalink
reduce duplication in DataContentViewerMEdia and MediaViewImagePanel …
Browse files Browse the repository at this point in the history
…by moving common code to ImageUtils
  • Loading branch information
jmillman committed Jul 9, 2015
1 parent c9bcf48 commit e148978
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Core/nbproject/project.xml
Expand Up @@ -177,7 +177,7 @@
<compile-dependency/>
<run-dependency>
<release-version>3</release-version>
<specification-version>1.1</specification-version>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
Expand Down
Expand Up @@ -217,33 +217,7 @@ private boolean isVideoSupported(AbstractFile file) {
* @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
Expand Down
Expand Up @@ -18,16 +18,17 @@
*/
package org.sleuthkit.autopsy.corecomponents;

import com.google.common.collect.Lists;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
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;
Expand All @@ -45,6 +46,7 @@
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;
Expand All @@ -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<String> supportedMimes = new ArrayList<>();
static private final SortedSet<String> supportedMimes = ImageUtils.getSupportedMimeTypes();

/**
* extensions we should be able to display
*/
Expand All @@ -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)
}

/**
Expand Down Expand Up @@ -195,7 +196,7 @@ public void run() {
* @return supported mime types
*/
public List<String> getMimeTypes() {
return Collections.unmodifiableList(supportedMimes);
return Collections.unmodifiableList(Lists.newArrayList(supportedMimes));
}

/**
Expand Down
34 changes: 28 additions & 6 deletions Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java
Expand Up @@ -2,7 +2,7 @@
*
* Autopsy Forensic Browser
*
* Copyright 2012 Basis Technology Corp.
* Copyright 2012-15 Basis Technology Corp.
*
* Copyright 2012 42six Solutions.
* Contact: aebadirad <at> 42six <dot> com
Expand Down Expand Up @@ -30,11 +30,13 @@
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;
Expand All @@ -53,20 +55,31 @@
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<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 */
private static final Executor imageSaver = Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder().namingPattern("icon saver-%d").build());
Expand Down Expand Up @@ -107,7 +120,16 @@ public static boolean thumbnailSupported(Content content) {
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
Expand Down
2 changes: 1 addition & 1 deletion ImageGallery/nbproject/project.xml
Expand Up @@ -4,7 +4,7 @@
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.sleuthkit.autopsy.imagegallery</code-name-base>
<suite-component/>
<standalone/>
<module-dependencies>
<dependency>
<code-name-base>org.netbeans.api.progress</code-name-base>
Expand Down
@@ -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
Expand All @@ -8,4 +8,4 @@ SplashRunningTextBounds=0,289,538,18
SplashRunningTextColor=0x0
SplashRunningTextFontSize=19

currentVersion=Autopsy 3.1.3
currentVersion=Autopsy 3.1.2
@@ -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
145 changes: 106 additions & 39 deletions 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
Expand All @@ -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

4 changes: 1 addition & 3 deletions nbproject/project.properties
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e148978

Please sign in to comment.