Autopsy  4.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 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.Dimension;
22 import java.awt.Toolkit;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.regex.Pattern;
28 import javax.swing.JFrame;
29 import javax.swing.JMenuItem;
30 import javax.swing.JPopupMenu;
31 import javax.swing.SwingUtilities;
32 import org.openide.util.NbBundle;
34 import org.sleuthkit.datamodel.HashEntry;
35 
40 public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog {
41 
42  HashDb hashDb;
43  Pattern md5Pattern = Pattern.compile("^[a-fA-F0-9]{32}$");
44  List<HashEntry> hashes = new ArrayList<>();
45  List<String> invalidHashes = new ArrayList<>();
46 
52  super(new JFrame(),
53  NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.JDialog.Title", hashDb.getHashSetName()),
54  true);
55  this.hashDb = hashDb;
57  display();
58  }
59 
60  private void display() {
61  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
62  setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
63  setVisible(true);
64  }
65 
72  void enableAddHashValuesToDatabaseDialog(boolean enable) {
73  if (enable) {
74  setDefaultCloseOperation(2);
75  } else {
76  setDefaultCloseOperation(0);
77  }
78  AddValuesToHashDatabaseButton.setEnabled(enable);
79  cancelButton.setEnabled(enable);
80  pasteFromClipboardButton.setEnabled(enable);
81  }
82 
88  @SuppressWarnings("unchecked")
89  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
90  private void initComponents() {
91 
92  instructionLabel = new javax.swing.JLabel();
93  jScrollPane1 = new javax.swing.JScrollPane();
94  hashValuesTextArea = new javax.swing.JTextArea();
95  pasteFromClipboardButton = new javax.swing.JButton();
96  AddValuesToHashDatabaseButton = new javax.swing.JButton();
97  cancelButton = new javax.swing.JButton();
98 
99  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
100  setTitle(org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.title")); // NOI18N
101 
102  org.openide.awt.Mnemonics.setLocalizedText(instructionLabel, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.instructionLabel.text_1")); // NOI18N
103 
104  hashValuesTextArea.setColumns(20);
105  hashValuesTextArea.setRows(5);
106  hashValuesTextArea.addMouseListener(new java.awt.event.MouseAdapter() {
107  public void mouseClicked(java.awt.event.MouseEvent evt) {
109  }
110  });
111  jScrollPane1.setViewportView(hashValuesTextArea);
112 
113  org.openide.awt.Mnemonics.setLocalizedText(pasteFromClipboardButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.pasteFromClipboardButton.text_2")); // NOI18N
114  pasteFromClipboardButton.addActionListener(new java.awt.event.ActionListener() {
115  public void actionPerformed(java.awt.event.ActionEvent evt) {
117  }
118  });
119 
120  org.openide.awt.Mnemonics.setLocalizedText(AddValuesToHashDatabaseButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.AddValuesToHashDatabaseButton.text_2")); // NOI18N
121  AddValuesToHashDatabaseButton.addActionListener(new java.awt.event.ActionListener() {
122  public void actionPerformed(java.awt.event.ActionEvent evt) {
124  }
125  });
126 
127  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.cancelButton.text_2")); // NOI18N
128  cancelButton.addActionListener(new java.awt.event.ActionListener() {
129  public void actionPerformed(java.awt.event.ActionEvent evt) {
131  }
132  });
133 
134  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
135  getContentPane().setLayout(layout);
136  layout.setHorizontalGroup(
137  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
138  .addGroup(layout.createSequentialGroup()
139  .addContainerGap()
140  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141  .addGroup(layout.createSequentialGroup()
142  .addComponent(instructionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
143  .addGap(0, 41, Short.MAX_VALUE))
144  .addComponent(jScrollPane1))
145  .addGap(18, 18, 18)
146  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147  .addComponent(AddValuesToHashDatabaseButton, javax.swing.GroupLayout.Alignment.TRAILING)
148  .addComponent(cancelButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
149  .addComponent(pasteFromClipboardButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
150  .addContainerGap())
151  );
152  layout.setVerticalGroup(
153  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154  .addGroup(layout.createSequentialGroup()
155  .addContainerGap()
156  .addComponent(instructionLabel)
157  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
158  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
159  .addGroup(layout.createSequentialGroup()
160  .addComponent(AddValuesToHashDatabaseButton)
161  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162  .addComponent(cancelButton)
163  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
164  .addComponent(pasteFromClipboardButton))
165  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
166  .addContainerGap())
167  );
168 
169  pack();
170  }// </editor-fold>//GEN-END:initComponents
171 
172  private void pasteFromClipboardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteFromClipboardButtonActionPerformed
173  hashValuesTextArea.paste();
174  hashValuesTextArea.append("\n");
175  // TODO - Avoid unnecessary \n appending in case nothing is pasted.
176  }//GEN-LAST:event_pasteFromClipboardButtonActionPerformed
177 
178  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
179  this.dispose();
180  }//GEN-LAST:event_cancelButtonActionPerformed
181 
182  private void hashValuesTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hashValuesTextAreaMouseClicked
183  if (SwingUtilities.isRightMouseButton(evt)) {
184  JPopupMenu popup = new JPopupMenu();
185 
186  JMenuItem cutMenu = new JMenuItem("Cut"); // NON-NLS
187  cutMenu.addActionListener(new ActionListener() {
188  @Override
189  public void actionPerformed(ActionEvent e) {
190  hashValuesTextArea.cut();
191  }
192  });
193 
194  JMenuItem copyMenu = new JMenuItem("Copy"); // NON-NLS
195  copyMenu.addActionListener(new ActionListener() {
196  @Override
197  public void actionPerformed(ActionEvent e) {
198  hashValuesTextArea.copy();
199  }
200  });
201 
202  JMenuItem pasteMenu = new JMenuItem("Paste"); // NON-NLS
203  pasteMenu.addActionListener(new ActionListener() {
204  @Override
205  public void actionPerformed(ActionEvent e) {
206  hashValuesTextArea.paste();
207  hashValuesTextArea.append("\n");
208  }
209  });
210 
211  popup.add(cutMenu);
212  popup.add(copyMenu);
213  popup.add(pasteMenu);
214  popup.show(hashValuesTextArea, evt.getX(), evt.getY());
215  }
216  }//GEN-LAST:event_hashValuesTextAreaMouseClicked
217 
218  private void AddValuesToHashDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddValuesToHashDatabaseButtonActionPerformed
220  progressDialog.addHashValuesToDatabase();
221  }//GEN-LAST:event_AddValuesToHashDatabaseButtonActionPerformed
222 
223  // Variables declaration - do not modify//GEN-BEGIN:variables
224  private javax.swing.JButton AddValuesToHashDatabaseButton;
225  private javax.swing.JButton cancelButton;
226  private javax.swing.JTextArea hashValuesTextArea;
227  private javax.swing.JLabel instructionLabel;
228  private javax.swing.JScrollPane jScrollPane1;
229  private javax.swing.JButton pasteFromClipboardButton;
230  // End of variables declaration//GEN-END:variables
231 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.