Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashSearchPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.filesearch;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import javax.swing.JCheckBox;
24 import javax.swing.JMenuItem;
25 import javax.swing.JTextField;
26 import javax.swing.event.DocumentEvent;
27 import javax.swing.event.DocumentListener;
28 
32 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
33 class HashSearchPanel extends javax.swing.JPanel {
34 
35  private static final long serialVersionUID = 1L;
36 
40  HashSearchPanel() {
41  initComponents();
42  customizeComponents();
43  setComponentsEnabled();
44  }
45 
46  private void customizeComponents() {
47 
48  md5TextField.setComponentPopupMenu(rightClickMenu);
49  ActionListener actList = new ActionListener() {
50  @Override
51  public void actionPerformed(ActionEvent e) {
52  JMenuItem jmi = (JMenuItem) e.getSource();
53  if (jmi.equals(cutMenuItem)) {
54  md5TextField.cut();
55  } else if (jmi.equals(copyMenuItem)) {
56  md5TextField.copy();
57  } else if (jmi.equals(pasteMenuItem)) {
58  md5TextField.paste();
59  } else if (jmi.equals(selectAllMenuItem)) {
60  md5TextField.selectAll();
61  }
62  }
63  };
64  cutMenuItem.addActionListener(actList);
65  copyMenuItem.addActionListener(actList);
66  pasteMenuItem.addActionListener(actList);
67  selectAllMenuItem.addActionListener(actList);
68  this.md5TextField.getDocument().addDocumentListener(new DocumentListener() {
69  @Override
70  public void insertUpdate(DocumentEvent e) {
71  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
72  }
73 
74  @Override
75  public void removeUpdate(DocumentEvent e) {
76  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
77  }
78 
79  @Override
80  public void changedUpdate(DocumentEvent e) {
81  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
82  }
83  });
84 
85  this.sha256TextField.getDocument().addDocumentListener(new DocumentListener() {
86  @Override
87  public void insertUpdate(DocumentEvent e) {
88  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
89  }
90 
91  @Override
92  public void removeUpdate(DocumentEvent e) {
93  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
94  }
95 
96  @Override
97  public void changedUpdate(DocumentEvent e) {
98  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
99  }
100  });
101 
102  }
103 
104  JCheckBox getMd5HashCheckBox() {
105  return md5CheckBox;
106  }
107 
108  JTextField getMd5TextField() {
109  return md5TextField;
110  }
111 
112  JCheckBox getSha256HashCheckBox() {
113  return sha256CheckBox;
114  }
115 
116  JTextField getSha256TextField() {
117  return sha256TextField;
118  }
119 
120  void setComponentsEnabled() {
121  boolean md5Enabled = md5CheckBox.isSelected();
122  this.md5TextField.setEnabled(md5Enabled);
123  boolean sha256Enabled = sha256CheckBox.isSelected();
124  this.sha256TextField.setEnabled(sha256Enabled);
125  }
126 
132  @SuppressWarnings("unchecked")
133  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
134  private void initComponents() {
135 
136  rightClickMenu = new javax.swing.JPopupMenu();
137  cutMenuItem = new javax.swing.JMenuItem();
138  copyMenuItem = new javax.swing.JMenuItem();
139  pasteMenuItem = new javax.swing.JMenuItem();
140  selectAllMenuItem = new javax.swing.JMenuItem();
141  md5CheckBox = new javax.swing.JCheckBox();
142  md5TextField = new javax.swing.JTextField();
143  sha256CheckBox = new javax.swing.JCheckBox();
144  sha256TextField = new javax.swing.JTextField();
145 
146  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.cutMenuItem.text")); // NOI18N
147  rightClickMenu.add(cutMenuItem);
148 
149  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.copyMenuItem.text")); // NOI18N
150  rightClickMenu.add(copyMenuItem);
151 
152  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.pasteMenuItem.text")); // NOI18N
153  rightClickMenu.add(pasteMenuItem);
154 
155  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.selectAllMenuItem.text")); // NOI18N
156  rightClickMenu.add(selectAllMenuItem);
157 
158  md5CheckBox.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "HashSearchPanel.md5CheckBox.text")); // NOI18N
159  md5CheckBox.addActionListener(new java.awt.event.ActionListener() {
160  public void actionPerformed(java.awt.event.ActionEvent evt) {
161  md5CheckBoxActionPerformed(evt);
162  }
163  });
164 
165  sha256CheckBox.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "HashSearchPanel.sha256CheckBox.text")); // NOI18N
166  sha256CheckBox.addActionListener(new java.awt.event.ActionListener() {
167  public void actionPerformed(java.awt.event.ActionEvent evt) {
168  sha256CheckBoxActionPerformed(evt);
169  }
170  });
171 
172  sha256TextField.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "HashSearchPanel.sha256TextField.text")); // NOI18N
173 
174  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
175  this.setLayout(layout);
176  layout.setHorizontalGroup(
177  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addGroup(layout.createSequentialGroup()
179  .addGap(0, 0, 0)
180  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181  .addGroup(layout.createSequentialGroup()
182  .addComponent(sha256CheckBox)
183  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184  .addComponent(sha256TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
185  .addGroup(layout.createSequentialGroup()
186  .addComponent(md5CheckBox)
187  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188  .addComponent(md5TextField)))
189  .addContainerGap())
190  );
191  layout.setVerticalGroup(
192  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193  .addGroup(layout.createSequentialGroup()
194  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
195  .addComponent(md5CheckBox)
196  .addComponent(md5TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
197  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
199  .addComponent(sha256CheckBox)
200  .addComponent(sha256TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
201  );
202  }// </editor-fold>//GEN-END:initComponents
203 
204  private void md5CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_md5CheckBoxActionPerformed
205  setComponentsEnabled();
206  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
207  }//GEN-LAST:event_md5CheckBoxActionPerformed
208 
209  private void sha256CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sha256CheckBoxActionPerformed
210  setComponentsEnabled();
211  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
212  }//GEN-LAST:event_sha256CheckBoxActionPerformed
213 
214  // Variables declaration - do not modify//GEN-BEGIN:variables
215  private javax.swing.JMenuItem copyMenuItem;
216  private javax.swing.JMenuItem cutMenuItem;
217  private javax.swing.JCheckBox md5CheckBox;
218  private javax.swing.JTextField md5TextField;
219  private javax.swing.JMenuItem pasteMenuItem;
220  private javax.swing.JPopupMenu rightClickMenu;
221  private javax.swing.JMenuItem selectAllMenuItem;
222  private javax.swing.JCheckBox sha256CheckBox;
223  private javax.swing.JTextField sha256TextField;
224  // End of variables declaration//GEN-END:variables
225 
226  void addActionListener(ActionListener l) {
227  md5TextField.addActionListener(l);
228  }
229 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.