Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddHashValuesToDatabaseDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.hashdatabase;
20 
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;
33 import org.sleuthkit.datamodel.HashEntry;
34 
38 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39 public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog {
40 
41  HashDb hashDb;
42  Pattern md5Pattern = Pattern.compile("^[a-fA-F0-9]{32}$");
43  List<HashEntry> hashes = new ArrayList<>();
44  List<String> invalidHashes = new ArrayList<>();
45 
51  super((JFrame) WindowManager.getDefault().getMainWindow(),
52  NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.JDialog.Title", hashDb.getDisplayName()),
53  true);
54  this.hashDb = hashDb;
55  initComponents();
56  display();
57  }
58 
59  private void display() {
60  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
61  setVisible(true);
62  }
63 
70  void enableAddHashValuesToDatabaseDialog(boolean enable) {
71  if (enable) {
72  setDefaultCloseOperation(2);
73  } else {
74  setDefaultCloseOperation(0);
75  }
76  AddValuesToHashDatabaseButton.setEnabled(enable);
77  cancelButton.setEnabled(enable);
78  pasteFromClipboardButton.setEnabled(enable);
79  }
80 
86  @SuppressWarnings("unchecked")
87  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88  private void initComponents() {
89 
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  AddValuesToHashDatabaseButton = new javax.swing.JButton();
95  cancelButton = new javax.swing.JButton();
96 
97  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
98  setTitle(org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.title")); // NOI18N
99 
100  org.openide.awt.Mnemonics.setLocalizedText(instructionLabel, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.instructionLabel.text_1")); // NOI18N
101 
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);
107  }
108  });
109  jScrollPane1.setViewportView(hashValuesTextArea);
110 
111  org.openide.awt.Mnemonics.setLocalizedText(pasteFromClipboardButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.pasteFromClipboardButton.text_2")); // NOI18N
112  pasteFromClipboardButton.addActionListener(new java.awt.event.ActionListener() {
113  public void actionPerformed(java.awt.event.ActionEvent evt) {
114  pasteFromClipboardButtonActionPerformed(evt);
115  }
116  });
117 
118  org.openide.awt.Mnemonics.setLocalizedText(AddValuesToHashDatabaseButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.AddValuesToHashDatabaseButton.text_2")); // NOI18N
119  AddValuesToHashDatabaseButton.addActionListener(new java.awt.event.ActionListener() {
120  public void actionPerformed(java.awt.event.ActionEvent evt) {
121  AddValuesToHashDatabaseButtonActionPerformed(evt);
122  }
123  });
124 
125  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.cancelButton.text_2")); // NOI18N
126  cancelButton.addActionListener(new java.awt.event.ActionListener() {
127  public void actionPerformed(java.awt.event.ActionEvent evt) {
128  cancelButtonActionPerformed(evt);
129  }
130  });
131 
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()
137  .addContainerGap()
138  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139  .addGroup(layout.createSequentialGroup()
140  .addComponent(instructionLabel)
141  .addGap(0, 0, Short.MAX_VALUE))
142  .addComponent(jScrollPane1))
143  .addGap(18, 18, 18)
144  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145  .addComponent(AddValuesToHashDatabaseButton, javax.swing.GroupLayout.Alignment.TRAILING)
146  .addComponent(cancelButton, javax.swing.GroupLayout.Alignment.TRAILING)
147  .addComponent(pasteFromClipboardButton, javax.swing.GroupLayout.Alignment.TRAILING))
148  .addContainerGap())
149  );
150  layout.setVerticalGroup(
151  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152  .addGroup(layout.createSequentialGroup()
153  .addContainerGap()
154  .addComponent(instructionLabel)
155  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157  .addGroup(layout.createSequentialGroup()
158  .addComponent(AddValuesToHashDatabaseButton)
159  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
160  .addComponent(cancelButton)
161  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
162  .addComponent(pasteFromClipboardButton))
163  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
164  .addContainerGap())
165  );
166 
167  pack();
168  }// </editor-fold>//GEN-END:initComponents
169 
170  private void pasteFromClipboardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteFromClipboardButtonActionPerformed
171  hashValuesTextArea.paste();
172  hashValuesTextArea.append("\n");
173  // TODO - Avoid unnecessary \n appending in case nothing is pasted.
174  }//GEN-LAST:event_pasteFromClipboardButtonActionPerformed
175 
176  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
177  this.dispose();
178  }//GEN-LAST:event_cancelButtonActionPerformed
179 
180  private void hashValuesTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hashValuesTextAreaMouseClicked
181  if (SwingUtilities.isRightMouseButton(evt)) {
182  JPopupMenu popup = new JPopupMenu();
183 
184  JMenuItem cutMenu = new JMenuItem("Cut"); // NON-NLS
185  cutMenu.addActionListener(new ActionListener() {
186  @Override
187  public void actionPerformed(ActionEvent e) {
188  hashValuesTextArea.cut();
189  }
190  });
191 
192  JMenuItem copyMenu = new JMenuItem("Copy"); // NON-NLS
193  copyMenu.addActionListener(new ActionListener() {
194  @Override
195  public void actionPerformed(ActionEvent e) {
196  hashValuesTextArea.copy();
197  }
198  });
199 
200  JMenuItem pasteMenu = new JMenuItem("Paste"); // NON-NLS
201  pasteMenu.addActionListener(new ActionListener() {
202  @Override
203  public void actionPerformed(ActionEvent e) {
204  hashValuesTextArea.paste();
205  hashValuesTextArea.append("\n");
206  }
207  });
208 
209  popup.add(cutMenu);
210  popup.add(copyMenu);
211  popup.add(pasteMenu);
212  popup.show(hashValuesTextArea, evt.getX(), evt.getY());
213  }
214  }//GEN-LAST:event_hashValuesTextAreaMouseClicked
215 
216  private void AddValuesToHashDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddValuesToHashDatabaseButtonActionPerformed
217  AddHashValuesToDatabaseProgressDialog progressDialog = new AddHashValuesToDatabaseProgressDialog(this, hashDb, hashValuesTextArea.getText());
218  progressDialog.addHashValuesToDatabase();
219  }//GEN-LAST:event_AddValuesToHashDatabaseButtonActionPerformed
220 
221  // Variables declaration - do not modify//GEN-BEGIN:variables
222  private javax.swing.JButton AddValuesToHashDatabaseButton;
223  private javax.swing.JButton cancelButton;
224  private javax.swing.JTextArea hashValuesTextArea;
225  private javax.swing.JLabel instructionLabel;
226  private javax.swing.JScrollPane jScrollPane1;
227  private javax.swing.JButton pasteFromClipboardButton;
228  // End of variables declaration//GEN-END:variables
229 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.