Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
NameSearchPanel.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 NameSearchPanel extends javax.swing.JPanel {
34 
35  private static final long serialVersionUID = 1L;
36 
40  NameSearchPanel() {
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 getNameCheckBox() {
88  return nameCheckBox;
89  }
90 
91  JTextField getSearchTextField() {
92  return searchTextField;
93  }
94 
95  void setComponentsEnabled() {
96  boolean enabled = nameCheckBox.isSelected();
97  this.searchTextField.setEnabled(enabled);
98  this.noteNameLabel.setEnabled(enabled);
99  }
100 
106  @SuppressWarnings("unchecked")
107  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
108  private void initComponents() {
109 
110  rightClickMenu = new javax.swing.JPopupMenu();
111  cutMenuItem = new javax.swing.JMenuItem();
112  copyMenuItem = new javax.swing.JMenuItem();
113  pasteMenuItem = new javax.swing.JMenuItem();
114  selectAllMenuItem = new javax.swing.JMenuItem();
115  nameCheckBox = new javax.swing.JCheckBox();
116  searchTextField = new javax.swing.JTextField();
117  noteNameLabel = new javax.swing.JLabel();
118 
119  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.cutMenuItem.text")); // NOI18N
120  rightClickMenu.add(cutMenuItem);
121 
122  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.copyMenuItem.text")); // NOI18N
123  rightClickMenu.add(copyMenuItem);
124 
125  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.pasteMenuItem.text")); // NOI18N
126  rightClickMenu.add(pasteMenuItem);
127 
128  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.selectAllMenuItem.text")); // NOI18N
129  rightClickMenu.add(selectAllMenuItem);
130 
131  nameCheckBox.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.nameCheckBox.text")); // NOI18N
132  nameCheckBox.addActionListener(new java.awt.event.ActionListener() {
133  public void actionPerformed(java.awt.event.ActionEvent evt) {
134  nameCheckBoxActionPerformed(evt);
135  }
136  });
137 
138  searchTextField.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.searchTextField.text")); // NOI18N
139 
140  noteNameLabel.setFont(noteNameLabel.getFont().deriveFont(noteNameLabel.getFont().getSize()-1f));
141  noteNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
142  noteNameLabel.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.noteNameLabel.text")); // NOI18N
143  noteNameLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
144  noteNameLabel.setMaximumSize(new java.awt.Dimension(250, 30));
145  noteNameLabel.setMinimumSize(new java.awt.Dimension(250, 30));
146  noteNameLabel.setPreferredSize(new java.awt.Dimension(250, 40));
147 
148  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
149  this.setLayout(layout);
150  layout.setHorizontalGroup(
151  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
153  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
154  .addGroup(layout.createSequentialGroup()
155  .addContainerGap()
156  .addComponent(noteNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
157  .addGroup(layout.createSequentialGroup()
158  .addComponent(nameCheckBox)
159  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
160  .addComponent(searchTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)))
161  .addGap(0, 0, 0))
162  );
163  layout.setVerticalGroup(
164  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165  .addGroup(layout.createSequentialGroup()
166  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167  .addComponent(nameCheckBox)
168  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
169  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
170  .addComponent(noteNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
171  .addGap(0, 0, Short.MAX_VALUE))
172  );
173  }// </editor-fold>//GEN-END:initComponents
174 
175  private void nameCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameCheckBoxActionPerformed
176  setComponentsEnabled();
177  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
178  }//GEN-LAST:event_nameCheckBoxActionPerformed
179 
180  // Variables declaration - do not modify//GEN-BEGIN:variables
181  private javax.swing.JMenuItem copyMenuItem;
182  private javax.swing.JMenuItem cutMenuItem;
183  private javax.swing.JCheckBox nameCheckBox;
184  private javax.swing.JLabel noteNameLabel;
185  private javax.swing.JMenuItem pasteMenuItem;
186  private javax.swing.JPopupMenu rightClickMenu;
187  private javax.swing.JTextField searchTextField;
188  private javax.swing.JMenuItem selectAllMenuItem;
189  // End of variables declaration//GEN-END:variables
190 
191  void addActionListener(ActionListener l) {
192  searchTextField.addActionListener(l);
193  }
194 }

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.