Autopsy  4.13.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.setFont(nameCheckBox.getFont().deriveFont(nameCheckBox.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
132  nameCheckBox.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.nameCheckBox.text")); // NOI18N
133  nameCheckBox.addActionListener(new java.awt.event.ActionListener() {
134  public void actionPerformed(java.awt.event.ActionEvent evt) {
135  nameCheckBoxActionPerformed(evt);
136  }
137  });
138 
139  searchTextField.setFont(searchTextField.getFont().deriveFont(searchTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
140  searchTextField.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.searchTextField.text")); // NOI18N
141 
142  noteNameLabel.setFont(noteNameLabel.getFont().deriveFont(noteNameLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
143  noteNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
144  noteNameLabel.setText(org.openide.util.NbBundle.getMessage(NameSearchPanel.class, "NameSearchPanel.noteNameLabel.text")); // NOI18N
145  noteNameLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
146  noteNameLabel.setMaximumSize(new java.awt.Dimension(250, 30));
147  noteNameLabel.setMinimumSize(new java.awt.Dimension(250, 30));
148  noteNameLabel.setPreferredSize(new java.awt.Dimension(250, 40));
149 
150  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
151  this.setLayout(layout);
152  layout.setHorizontalGroup(
153  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
155  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
156  .addGroup(layout.createSequentialGroup()
157  .addContainerGap()
158  .addComponent(noteNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
159  .addGroup(layout.createSequentialGroup()
160  .addComponent(nameCheckBox)
161  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162  .addComponent(searchTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)))
163  .addGap(0, 0, 0))
164  );
165  layout.setVerticalGroup(
166  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addGroup(layout.createSequentialGroup()
168  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
169  .addComponent(nameCheckBox)
170  .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
171  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
172  .addComponent(noteNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
173  .addGap(0, 0, Short.MAX_VALUE))
174  );
175  }// </editor-fold>//GEN-END:initComponents
176 
177  private void nameCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameCheckBoxActionPerformed
178  setComponentsEnabled();
179  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
180  }//GEN-LAST:event_nameCheckBoxActionPerformed
181 
182  // Variables declaration - do not modify//GEN-BEGIN:variables
183  private javax.swing.JMenuItem copyMenuItem;
184  private javax.swing.JMenuItem cutMenuItem;
185  private javax.swing.JCheckBox nameCheckBox;
186  private javax.swing.JLabel noteNameLabel;
187  private javax.swing.JMenuItem pasteMenuItem;
188  private javax.swing.JPopupMenu rightClickMenu;
189  private javax.swing.JTextField searchTextField;
190  private javax.swing.JMenuItem selectAllMenuItem;
191  // End of variables declaration//GEN-END:variables
192 
193  void addActionListener(ActionListener l) {
194  searchTextField.addActionListener(l);
195  }
196 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.