19 package org.sleuthkit.autopsy.modules.hashdatabase;
 
   21 import java.awt.event.ActionEvent;
 
   22 import java.awt.event.ActionListener;
 
   23 import java.util.ArrayList;
 
   24 import java.util.List;
 
   25 import java.util.regex.Pattern;
 
   26 import javax.swing.JFrame;
 
   27 import javax.swing.JMenuItem;
 
   28 import javax.swing.JPopupMenu;
 
   29 import javax.swing.SwingUtilities;
 
   30 import org.openide.util.NbBundle;
 
   31 import org.openide.windows.WindowManager;
 
   38 @SuppressWarnings(
"PMD.SingularField") 
 
   42     Pattern md5Pattern = Pattern.compile(
"^[a-fA-F0-9]{32}$");
 
   43     List<HashEntry> hashes = 
new ArrayList<>();
 
   44     List<String> invalidHashes = 
new ArrayList<>();
 
   51         super((JFrame) WindowManager.getDefault().getMainWindow(),
 
   60         setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
 
   70     void enableAddHashValuesToDatabaseDialog(
boolean enable) {
 
   72             setDefaultCloseOperation(2);
 
   74             setDefaultCloseOperation(0);
 
   76         okButton.setEnabled(enable);
 
   77         cancelButton.setEnabled(enable);
 
   78         pasteFromClipboardButton.setEnabled(enable);
 
   86     @SuppressWarnings(
"unchecked")
 
   88     private 
void initComponents() {
 
   90         instructionLabel = 
new javax.swing.JLabel();
 
   91         jScrollPane1 = 
new javax.swing.JScrollPane();
 
   92         hashValuesTextArea = 
new javax.swing.JTextArea();
 
   93         pasteFromClipboardButton = 
new javax.swing.JButton();
 
   94         okButton = 
new javax.swing.JButton();
 
   95         cancelButton = 
new javax.swing.JButton();
 
   97         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  100         org.openide.awt.Mnemonics.setLocalizedText(instructionLabel, 
org.openide.util.NbBundle.getMessage(
AddHashValuesToDatabaseDialog.class, 
"AddHashValuesToDatabaseDialog.instructionLabel.text_1")); 
 
  102         hashValuesTextArea.setColumns(20);
 
  103         hashValuesTextArea.setRows(5);
 
  104         hashValuesTextArea.addMouseListener(
new java.awt.event.MouseAdapter() {
 
  105             public void mouseClicked(java.awt.event.MouseEvent evt) {
 
  106                 hashValuesTextAreaMouseClicked(evt);
 
  109         jScrollPane1.setViewportView(hashValuesTextArea);
 
  111         org.openide.awt.Mnemonics.setLocalizedText(pasteFromClipboardButton, 
org.openide.util.NbBundle.getMessage(
AddHashValuesToDatabaseDialog.class, 
"AddHashValuesToDatabaseDialog.pasteFromClipboardButton.text_2")); 
 
  112         pasteFromClipboardButton.addActionListener(
new java.awt.event.ActionListener() {
 
  113             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  114                 pasteFromClipboardButtonActionPerformed(evt);
 
  118         org.openide.awt.Mnemonics.setLocalizedText(okButton, 
org.openide.util.NbBundle.getMessage(
AddHashValuesToDatabaseDialog.class, 
"AddHashValuesToDatabaseDialog.okButton.text_2")); 
 
  119         okButton.addActionListener(
new java.awt.event.ActionListener() {
 
  120             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  121                 okButtonActionPerformed(evt);
 
  125         org.openide.awt.Mnemonics.setLocalizedText(cancelButton, 
org.openide.util.NbBundle.getMessage(
AddHashValuesToDatabaseDialog.class, 
"AddHashValuesToDatabaseDialog.cancelButton.text_2")); 
 
  126         cancelButton.addActionListener(
new java.awt.event.ActionListener() {
 
  127             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  128                 cancelButtonActionPerformed(evt);
 
  132         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  133         getContentPane().setLayout(layout);
 
  134         layout.setHorizontalGroup(
 
  135             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  136             .addGroup(layout.createSequentialGroup()
 
  138                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  139                     .addComponent(jScrollPane1)
 
  140                     .addGroup(layout.createSequentialGroup()
 
  141                         .addComponent(instructionLabel)
 
  142                         .addGap(0, 0, Short.MAX_VALUE))
 
  143                     .addGroup(layout.createSequentialGroup()
 
  144                         .addComponent(pasteFromClipboardButton)
 
  145                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 121, Short.MAX_VALUE)
 
  146                         .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  147                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  148                         .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
 
  151         layout.setVerticalGroup(
 
  152             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  153             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  155                 .addComponent(instructionLabel)
 
  156                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  157                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
 
  158                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  159                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  160                     .addComponent(pasteFromClipboardButton)
 
  161                     .addComponent(okButton)
 
  162                     .addComponent(cancelButton))
 
  170         hashValuesTextArea.paste();
 
  171         hashValuesTextArea.append(
"\n");
 
  180         if (SwingUtilities.isRightMouseButton(evt)) {
 
  181             JPopupMenu popup = 
new JPopupMenu();
 
  183             JMenuItem cutMenu = 
new JMenuItem(
"Cut"); 
 
  184             cutMenu.addActionListener(
new ActionListener() {
 
  186                 public void actionPerformed(ActionEvent e) {
 
  187                     hashValuesTextArea.cut();
 
  191             JMenuItem copyMenu = 
new JMenuItem(
"Copy"); 
 
  192             copyMenu.addActionListener(
new ActionListener() {
 
  194                 public void actionPerformed(ActionEvent e) {
 
  195                     hashValuesTextArea.copy();
 
  199             JMenuItem pasteMenu = 
new JMenuItem(
"Paste"); 
 
  200             pasteMenu.addActionListener(
new ActionListener() {
 
  202                 public void actionPerformed(ActionEvent e) {
 
  203                     hashValuesTextArea.paste();
 
  204                     hashValuesTextArea.append(
"\n");
 
  210             popup.add(pasteMenu);
 
  211             popup.show(hashValuesTextArea, evt.getX(), evt.getY());
 
  217         progressDialog.addHashValuesToDatabase();
 
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JButton okButton
javax.swing.JButton pasteFromClipboardButton
void hashValuesTextAreaMouseClicked(java.awt.event.MouseEvent evt)
void okButtonActionPerformed(java.awt.event.ActionEvent evt)
void pasteFromClipboardButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JTextArea hashValuesTextArea
javax.swing.JLabel instructionLabel
javax.swing.JScrollPane jScrollPane1
javax.swing.JButton cancelButton