5979 populate document preview for file discovery

This commit is contained in:
William Schaefer 2020-01-29 16:09:08 -05:00
parent 765e4187cc
commit a0de456782
3 changed files with 53 additions and 7 deletions

View File

@ -124,6 +124,9 @@
</Properties> </Properties>
</Component> </Component>
<Container class="javax.swing.JScrollPane" name="previewScrollPane"> <Container class="javax.swing.JScrollPane" name="previewScrollPane">
<Properties>
<Property name="verticalScrollBarPolicy" type="int" value="21"/>
</Properties>
<AuxValues> <AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues> </AuxValues>
@ -135,10 +138,13 @@
<Property name="editable" type="boolean" value="false"/> <Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/> <Property name="columns" type="int" value="20"/>
<Property name="lineWrap" type="boolean" value="true"/> <Property name="lineWrap" type="boolean" value="true"/>
<Property name="rows" type="int" value="4"/> <Property name="rows" type="int" value="5"/>
<Property name="wrapStyleWord" type="boolean" value="true"/> <Property name="wrapStyleWord" type="boolean" value="true"/>
<Property name="enabled" type="boolean" value="false"/> <Property name="enabled" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/> <Property name="focusable" type="boolean" value="false"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[164, 94]"/>
</Property>
</Properties> </Properties>
</Component> </Component>
</SubComponents> </SubComponents>

View File

@ -89,13 +89,16 @@ public class DocumentPanel extends javax.swing.JPanel implements ListCellRendere
org.openide.awt.Mnemonics.setLocalizedText(documentType, org.openide.util.NbBundle.getMessage(DocumentPanel.class, "DocumentPanel.documentType.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(documentType, org.openide.util.NbBundle.getMessage(DocumentPanel.class, "DocumentPanel.documentType.text")); // NOI18N
previewScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
previewTextArea.setEditable(false); previewTextArea.setEditable(false);
previewTextArea.setColumns(20); previewTextArea.setColumns(20);
previewTextArea.setLineWrap(true); previewTextArea.setLineWrap(true);
previewTextArea.setRows(4); previewTextArea.setRows(5);
previewTextArea.setWrapStyleWord(true); previewTextArea.setWrapStyleWord(true);
previewTextArea.setEnabled(false); previewTextArea.setEnabled(false);
previewTextArea.setFocusable(false); previewTextArea.setFocusable(false);
previewTextArea.setMaximumSize(new java.awt.Dimension(164, 94));
previewScrollPane.setViewportView(previewTextArea); previewScrollPane.setViewportView(previewTextArea);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
@ -192,8 +195,9 @@ public class DocumentPanel extends javax.swing.JPanel implements ListCellRendere
public Component getListCellRendererComponent(JList<? extends DocumentWrapper> list, DocumentWrapper value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<? extends DocumentWrapper> list, DocumentWrapper value, int index, boolean isSelected, boolean cellHasFocus) {
fileSizeLabel.setText(getFileSizeString(value.getResultFile().getFirstInstance().getSize())); fileSizeLabel.setText(getFileSizeString(value.getResultFile().getFirstInstance().getSize()));
countLabel.setText(Bundle.ImageThumbnailPanel_countLabel_text(value.getResultFile().getAllInstances().size())); countLabel.setText(Bundle.ImageThumbnailPanel_countLabel_text(value.getResultFile().getAllInstances().size()));
documentType.setText(value.getResultFile().getFileType().name()); //WJS-TODO fill this in with a document type instead of just DOCUMENT documentType.setText("Extension: " + value.getResultFile().getFirstInstance().getNameExtension()); //WJS-TODO fill this in with a document type instead of just DOCUMENT
previewTextArea.setText(value.getPreview()); previewTextArea.setText(value.getPreview());
previewTextArea.setCaretPosition(0);
if (value.getResultFile().isDeleted()) { if (value.getResultFile().isDeleted()) {
isDeletedLabel.setIcon(DELETED_ICON); isDeletedLabel.setIcon(DELETED_ICON);
isDeletedLabel.setToolTipText(Bundle.ImageThumbnailPanel_isDeleted_text()); isDeletedLabel.setToolTipText(Bundle.ImageThumbnailPanel_isDeleted_text());

View File

@ -18,10 +18,20 @@
*/ */
package org.sleuthkit.autopsy.filequery; package org.sleuthkit.autopsy.filequery;
import java.util.logging.Level;
import org.sleuthkit.datamodel.AbstractFile;
import org.apache.commons.lang3.StringUtils;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.StringExtract;
import org.sleuthkit.datamodel.TskCoreException;
public class DocumentWrapper { public class DocumentWrapper {
private String preview; private String preview;
private final ResultFile resultFile; private final ResultFile resultFile;
private static final Logger logger = Logger.getLogger(DocumentWrapper.class.getName());
//string extract utility
private final StringExtract stringExtract = new StringExtract();
/** /**
* Construct a new ImageThumbnailsWrapper. * Construct a new ImageThumbnailsWrapper.
@ -30,10 +40,36 @@ public class DocumentWrapper {
* summary is created for. * summary is created for.
*/ */
DocumentWrapper(ResultFile file) { DocumentWrapper(ResultFile file) {
this.preview = "Preview not currently available"; this.preview = createPreview(file.getFirstInstance());
this.resultFile = file; this.resultFile = file;
} }
private String createPreview(AbstractFile file) {
byte[] data = new byte[256];
int bytesRead = 0;
if (file.getSize() > 0) {
try {
bytesRead = file.read(data, 0, 256); // read the data
} catch (TskCoreException ex) {
logger.log(Level.WARNING, "Error while trying to show the String content.", ex); //NON-NLS
}
}
String text;
if (bytesRead > 0) {
//text = DataConversion.getString(data, bytesRead, 4);
final StringExtract.StringExtractUnicodeTable.SCRIPT selScript = StringExtract.StringExtractUnicodeTable.SCRIPT.LATIN_1;
stringExtract.setEnabledScript(selScript);
StringExtract.StringExtractResult res = stringExtract.extract(data, bytesRead, 0);
text = res.getText();
if (StringUtils.isBlank(text)) {
text = "No Preview available.";
}
} else {
text = "No bytes read for preview.";
}
return text;
}
/** /**
* Set the preview summary which exists. * Set the preview summary which exists.
* *
@ -44,8 +80,8 @@ public class DocumentWrapper {
} }
/** /**
* Get the ResultFile which represents the document the preview summary * Get the ResultFile which represents the document the preview summary was
* was created for. * created for.
* *
* @return The ResultFile which represents the image file which the * @return The ResultFile which represents the image file which the
* thumbnail was created for. * thumbnail was created for.