Autopsy 4.22.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-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 */
19package org.sleuthkit.autopsy.modules.hashdatabase;
20
21import java.awt.event.ActionEvent;
22import java.awt.event.ActionListener;
23import java.util.ArrayList;
24import java.util.List;
25import java.util.regex.Pattern;
26import javax.swing.JFrame;
27import javax.swing.JMenuItem;
28import javax.swing.JPopupMenu;
29import javax.swing.SwingUtilities;
30import org.openide.util.NbBundle;
31import org.openide.windows.WindowManager;
32import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb;
33import org.sleuthkit.datamodel.HashEntry;
34
38@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39public 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
50 AddHashValuesToDatabaseDialog(HashDb hashDb) {
51 super((JFrame) WindowManager.getDefault().getMainWindow(),
52 NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.JDialog.Title", hashDb.getDisplayName()),
53 true);
54 this.hashDb = hashDb;
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 okButton.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 okButton = 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(okButton, org.openide.util.NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.okButton.text_2")); // NOI18N
119 okButton.addActionListener(new java.awt.event.ActionListener() {
120 public void actionPerformed(java.awt.event.ActionEvent evt) {
121 okButtonActionPerformed(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 .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)))
149 .addContainerGap())
150 );
151 layout.setVerticalGroup(
152 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
153 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
154 .addContainerGap()
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))
163 .addContainerGap())
164 );
165
166 pack();
167 }// </editor-fold>//GEN-END:initComponents
168
169 private void pasteFromClipboardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteFromClipboardButtonActionPerformed
170 hashValuesTextArea.paste();
171 hashValuesTextArea.append("\n");
172 // TODO - Avoid unnecessary \n appending in case nothing is pasted.
173 }//GEN-LAST:event_pasteFromClipboardButtonActionPerformed
174
175 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
176 this.dispose();
177 }//GEN-LAST:event_cancelButtonActionPerformed
178
179 private void hashValuesTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hashValuesTextAreaMouseClicked
180 if (SwingUtilities.isRightMouseButton(evt)) {
181 JPopupMenu popup = new JPopupMenu();
182
183 JMenuItem cutMenu = new JMenuItem("Cut"); // NON-NLS
184 cutMenu.addActionListener(new ActionListener() {
185 @Override
186 public void actionPerformed(ActionEvent e) {
187 hashValuesTextArea.cut();
188 }
189 });
190
191 JMenuItem copyMenu = new JMenuItem("Copy"); // NON-NLS
192 copyMenu.addActionListener(new ActionListener() {
193 @Override
194 public void actionPerformed(ActionEvent e) {
195 hashValuesTextArea.copy();
196 }
197 });
198
199 JMenuItem pasteMenu = new JMenuItem("Paste"); // NON-NLS
200 pasteMenu.addActionListener(new ActionListener() {
201 @Override
202 public void actionPerformed(ActionEvent e) {
203 hashValuesTextArea.paste();
204 hashValuesTextArea.append("\n");
205 }
206 });
207
208 popup.add(cutMenu);
209 popup.add(copyMenu);
210 popup.add(pasteMenu);
211 popup.show(hashValuesTextArea, evt.getX(), evt.getY());
212 }
213 }//GEN-LAST:event_hashValuesTextAreaMouseClicked
214
215 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
217 progressDialog.addHashValuesToDatabase();
218 }//GEN-LAST:event_okButtonActionPerformed
219
220 // Variables declaration - do not modify//GEN-BEGIN:variables
221 private javax.swing.JButton cancelButton;
222 private javax.swing.JTextArea hashValuesTextArea;
223 private javax.swing.JLabel instructionLabel;
224 private javax.swing.JScrollPane jScrollPane1;
225 private javax.swing.JButton okButton;
226 private javax.swing.JButton pasteFromClipboardButton;
227 // End of variables declaration//GEN-END:variables
228}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.