Autopsy  4.14.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  searchTextField.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  searchTextField.cut();
55  } else if (jmi.equals(copyMenuItem)) {
56  searchTextField.copy();
57  } else if (jmi.equals(pasteMenuItem)) {
58  searchTextField.paste();
59  } else if (jmi.equals(selectAllMenuItem)) {
60  searchTextField.selectAll();
61  }
62  }
63  };
64  cutMenuItem.addActionListener(actList);
65  copyMenuItem.addActionListener(actList);
66  pasteMenuItem.addActionListener(actList);
67  selectAllMenuItem.addActionListener(actList);
68  this.searchTextField.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  }
86 
87  JCheckBox getHashCheckBox() {
88  return hashCheckBox;
89  }
90 
91  JTextField getSearchTextField() {
92  return searchTextField;
93  }
94 
95  void setComponentsEnabled() {
96  boolean enabled = hashCheckBox.isSelected();
97  this.searchTextField.setEnabled(enabled);
98  }
99 
105  @SuppressWarnings("unchecked")
106  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
107  private void initComponents() {
108 
109  rightClickMenu = new javax.swing.JPopupMenu();
110  cutMenuItem = new javax.swing.JMenuItem();
111  copyMenuItem = new javax.swing.JMenuItem();
112  pasteMenuItem = new javax.swing.JMenuItem();
113  selectAllMenuItem = new javax.swing.JMenuItem();
114  hashCheckBox = new javax.swing.JCheckBox();
115  searchTextField = new javax.swing.JTextField();
116 
117  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.cutMenuItem.text")); // NOI18N
118  rightClickMenu.add(cutMenuItem);
119 
120  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.copyMenuItem.text")); // NOI18N
121  rightClickMenu.add(copyMenuItem);
122 
123  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.pasteMenuItem.text")); // NOI18N
124  rightClickMenu.add(pasteMenuItem);
125 
126  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "NameSearchPanel.selectAllMenuItem.text")); // NOI18N
127  rightClickMenu.add(selectAllMenuItem);
128 
129  hashCheckBox.setText(org.openide.util.NbBundle.getMessage(HashSearchPanel.class, "HashSearchPanel.md5CheckBox.text")); // NOI18N
130  hashCheckBox.addActionListener(new java.awt.event.ActionListener() {
131  public void actionPerformed(java.awt.event.ActionEvent evt) {
132  hashCheckBoxActionPerformed(evt);
133  }
134  });
135 
136  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
137  this.setLayout(layout);
138  layout.setHorizontalGroup(
139  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140  .addGroup(layout.createSequentialGroup()
141  .addGap(0, 0, 0)
142  .addComponent(hashCheckBox)
143  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
144  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
145  .addGap(0, 0, 0))
146  );
147  layout.setVerticalGroup(
148  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
149  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150  .addComponent(hashCheckBox)
151  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
152  );
153  }// </editor-fold>//GEN-END:initComponents
154 
155  private void hashCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashCheckBoxActionPerformed
156  setComponentsEnabled();
157  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
158  }//GEN-LAST:event_hashCheckBoxActionPerformed
159 
160  // Variables declaration - do not modify//GEN-BEGIN:variables
161  private javax.swing.JMenuItem copyMenuItem;
162  private javax.swing.JMenuItem cutMenuItem;
163  private javax.swing.JCheckBox hashCheckBox;
164  private javax.swing.JMenuItem pasteMenuItem;
165  private javax.swing.JPopupMenu rightClickMenu;
166  private javax.swing.JTextField searchTextField;
167  private javax.swing.JMenuItem selectAllMenuItem;
168  // End of variables declaration//GEN-END:variables
169 
170  void addActionListener(ActionListener l) {
171  searchTextField.addActionListener(l);
172  }
173 }

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