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

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