Autopsy  4.7.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.setFont(hashCheckBox.getFont().deriveFont(hashCheckBox.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
131  hashCheckBox.addActionListener(new java.awt.event.ActionListener() {
132  public void actionPerformed(java.awt.event.ActionEvent evt) {
133  hashCheckBoxActionPerformed(evt);
134  }
135  });
136 
137  searchTextField.setFont(searchTextField.getFont().deriveFont(searchTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
138 
139  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
140  this.setLayout(layout);
141  layout.setHorizontalGroup(
142  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143  .addGroup(layout.createSequentialGroup()
144  .addGap(0, 0, 0)
145  .addComponent(hashCheckBox)
146  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
147  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
148  .addGap(0, 0, 0))
149  );
150  layout.setVerticalGroup(
151  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
153  .addComponent(hashCheckBox)
154  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
155  );
156  }// </editor-fold>//GEN-END:initComponents
157 
158  private void hashCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashCheckBoxActionPerformed
159  setComponentsEnabled();
160  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
161  }//GEN-LAST:event_hashCheckBoxActionPerformed
162 
163  // Variables declaration - do not modify//GEN-BEGIN:variables
164  private javax.swing.JMenuItem copyMenuItem;
165  private javax.swing.JMenuItem cutMenuItem;
166  private javax.swing.JCheckBox hashCheckBox;
167  private javax.swing.JMenuItem pasteMenuItem;
168  private javax.swing.JPopupMenu rightClickMenu;
169  private javax.swing.JTextField searchTextField;
170  private javax.swing.JMenuItem selectAllMenuItem;
171  // End of variables declaration//GEN-END:variables
172 
173  void addActionListener(ActionListener l) {
174  searchTextField.addActionListener(l);
175  }
176 }

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