colored progress bar to indicate success of failure of hash addition

This commit is contained in:
sidheshenator 2015-07-02 15:31:53 -04:00
parent d92ea4e830
commit ec7f48a4be
6 changed files with 127 additions and 73 deletions

View File

@ -26,19 +26,22 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="instructionLabel" pref="220" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="instructionLabel" min="-2" pref="220" max="-2" attributes="0"/>
<EmptySpace min="0" pref="41" max="32767" attributes="0"/>
</Group>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="AddValuesToHashDatabaseButton" max="32767" attributes="0"/>
<Component id="pasteFromClipboardButton" alignment="0" max="32767" attributes="0"/>
<Component id="cancelButton" alignment="0" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="AddValuesToHashDatabaseButton" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="1" min="-2" pref="151" max="-2" attributes="0"/>
<Component id="pasteFromClipboardButton" alignment="1" min="-2" pref="151" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -48,17 +51,17 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="instructionLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jScrollPane1" min="-2" pref="240" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="pasteFromClipboardButton" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="AddValuesToHashDatabaseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="pasteFromClipboardButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane1" pref="274" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="29" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View File

@ -1,7 +1,20 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.modules.hashdatabase;
@ -52,6 +65,7 @@ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog {
/**
* Toggle the buttons and default close operation.
*
* @param enable Set true to enable buttons and DISPOSE_ON_CLOSE. Set false
* to disable buttons and DO_NOTHING_ON_CLOSE
*/
@ -123,15 +137,17 @@ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(instructionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(instructionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 41, Short.MAX_VALUE))
.addComponent(jScrollPane1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(AddValuesToHashDatabaseButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pasteFromClipboardButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(AddValuesToHashDatabaseButton, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cancelButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pasteFromClipboardButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -139,15 +155,15 @@ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog {
.addContainerGap()
.addComponent(instructionLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pasteFromClipboardButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(AddValuesToHashDatabaseButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton)))
.addContainerGap(29, Short.MAX_VALUE))
.addComponent(pasteFromClipboardButton))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
.addContainerGap())
);
pack();

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="0"/>
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
@ -28,19 +28,19 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="addingHashesToDatabaseProgressBar" pref="311" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="okButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<Component id="statusLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="showErrorsButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="addingHashesToDatabaseProgressBar" min="-2" pref="300" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="okButton" min="-2" pref="91" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -53,9 +53,9 @@
<Component id="okButton" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="statusLabel" min="-2" max="-2" attributes="0"/>
<Component id="showErrorsButton" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="showErrorsButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="statusLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>

View File

@ -1,7 +1,20 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.modules.hashdatabase;
@ -12,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
@ -33,6 +47,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
private final List<HashEntry> hashes;
private final List<String> invalidHashes;
private final Pattern md5Pattern;
private String errorTitle;
private String errorMessage;
private final String text;
@ -62,7 +77,8 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
}
/**
* Executes a SwingWorker which performs addition of hashes into the database.
* Executes a SwingWorker which performs addition of hashes into the
* database.
*/
final void addHashValuesToDatabase() {
parentRef.enableAddHashValuesToDatabaseDialog(false);
@ -79,25 +95,30 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
if (!invalidHashes.isEmpty()) {
statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invalidHash"));
finish(false);
errorMessage = NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invaliHash.msg");
errorTitle = NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invaliHash.msg");
errorMessage = "";
for (String invalidHash : invalidHashes) {
errorMessage = errorMessage + invalidHash + "\n"; // NON-NLS
}
showErrorsButton.setVisible(true);
showErrorsButton.requestFocus();
} else if (hashes.isEmpty()) {
statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.noHashesToAdd"));
finish(false);
} else {
try {
hashDb.addHashes(hashes);
okButton.requestFocus();
statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.success", hashes.size()));
finish(true);
disposeParent = true;
} catch (TskCoreException ex) {
statusLabel.setText(NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash"));
finish(false);
errorMessage = NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash.msg", ex.toString());
errorTitle = NbBundle.getMessage(AddHashValuesToDatabaseProgressDialog.class, "AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash.msg");
errorMessage = ex.toString();
showErrorsButton.setVisible(true);
showErrorsButton.requestFocus();
}
}
return null;
@ -108,6 +129,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
/**
* Sets the progressbar to maximum value, change colors accordingly, and
* enables OK button.
*
* @param success
*/
private void finish(boolean success) {
@ -115,17 +137,24 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
addingHashesToDatabaseProgressBar.setIndeterminate(false);
addingHashesToDatabaseProgressBar.setValue(addingHashesToDatabaseProgressBar.getMaximum());
if (success) {
addingHashesToDatabaseProgressBar.setForeground(Color.green);
// a hack to set progressbar color.
addingHashesToDatabaseProgressBar.setStringPainted(true);
addingHashesToDatabaseProgressBar.setForeground(new Color(50,205,50));
addingHashesToDatabaseProgressBar.setString("");
} else {
addingHashesToDatabaseProgressBar.setBackground(Color.red);
addingHashesToDatabaseProgressBar.setForeground(Color.red);
// a hack to set progressbar color.
addingHashesToDatabaseProgressBar.setStringPainted(true);
addingHashesToDatabaseProgressBar.setForeground(new Color(178,34,34));
addingHashesToDatabaseProgressBar.setString("");
}
}
/**
* Parses for String for MD5 hashes and adds new HashEntry objects into the
* list of hashes. It also populates the invalidHashes list for user-feedback.
* list of hashes. It also populates the invalidHashes list for
* user-feedback.
*
* @param text
*/
private void getHashesFromTextArea(String text) {
@ -188,16 +217,16 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(addingHashesToDatabaseProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(okButton))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(statusLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(showErrorsButton)))
.addContainerGap())
.addComponent(showErrorsButton))
.addGroup(layout.createSequentialGroup()
.addComponent(addingHashesToDatabaseProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -207,9 +236,9 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
.addComponent(addingHashesToDatabaseProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(okButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(statusLabel)
.addComponent(showErrorsButton))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(showErrorsButton)
.addComponent(statusLabel))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
@ -225,10 +254,13 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog {
}//GEN-LAST:event_okButtonActionPerformed
private void showErrorsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showErrorsButtonActionPerformed
JLabel textLabel = new JLabel(errorTitle);
JTextArea textArea = new JTextArea(errorMessage);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(250, 100));
JOptionPane.showMessageDialog(this, scrollPane, "Error:\n", JOptionPane.OK_OPTION); // NON-NLS
Object[] jOptionPaneComponents = {textLabel, scrollPane};
JOptionPane.showMessageDialog(this, jOptionPaneComponents, "Error:\n", JOptionPane.OK_OPTION); // NON-NLS
}//GEN-LAST:event_showErrorsButtonActionPerformed

View File

@ -209,8 +209,8 @@ AddHashValuesToDatabaseDialog.title=Add Hashes to Database
AddHashValuesToDatabaseProgressDialog.showErrorsButton.text=Show Errors
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.parsing=Parsing text for MD5 hashes...
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invalidHash=The input contains invalid hash.
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invaliHash.msg=Invalid Hashes:\n
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.invaliHash.msg=Invalid Hashes:
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.noHashesToAdd=There are no hashes to add.
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.success={0} Hashes added successfully.
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash=There is an error adding valid hashes.
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash.msg=Error adding valid hashes to the database:\n{0}
AddHashValuesToDatabaseProgressDialog.addHashValuesToDatabase.errorAddingValidHash.msg=Error adding valid hashes to the database:

View File

@ -34,6 +34,7 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
@ -159,6 +160,13 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan
indexPathLabel.setText(ERROR_GETTING_PATH_TEXT);
}
try {
addHashesToDatabaseButton.setEnabled(!ingestIsRunning && db.isUpdateable());
} catch (TskCoreException ex) {
Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error identifying if the database is updateable.", ex); //NON-NLS
addHashesToDatabaseButton.setEnabled(false);
}
// Update indexing components.
try {
if (db.isIndexing()) {
@ -168,9 +176,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan
NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexGen"));
hashDbIndexStatusLabel.setForeground(Color.black);
indexButton.setEnabled(false);
addHashesToDatabaseButton.setEnabled(false);
} else if (db.hasIndex()) {
addHashesToDatabaseButton.setEnabled(true);
if (db.hasIndexOnly()) {
hashDbIndexStatusLabel.setText(
NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexOnly"));
@ -188,7 +194,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan
indexButton.setEnabled(false);
}
} else {
addHashesToDatabaseButton.setEnabled(true);
hashDbIndexStatusLabel.setText(
NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.noIndex"));
hashDbIndexStatusLabel.setForeground(Color.red);
@ -201,13 +206,11 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan
hashDbIndexStatusLabel.setForeground(Color.red);
indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index"));
indexButton.setEnabled(false);
addHashesToDatabaseButton.setEnabled(false);
}
// Disable the indexing button if ingest is in progress.
if (ingestIsRunning) {
indexButton.setEnabled(false);
addHashesToDatabaseButton.setEnabled(false);
}
// Update ingest option components.