Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
SizeSearchPanel.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 java.text.NumberFormat;
24 import javax.swing.JCheckBox;
25 import javax.swing.JComboBox;
26 import javax.swing.JFormattedTextField;
27 import javax.swing.JMenuItem;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 
34 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
35 class SizeSearchPanel extends javax.swing.JPanel {
36 
37  private static final long serialVersionUID = 1L;
38 
42  SizeSearchPanel() {
43  initComponents();
44  customizeComponents();
45  setComponentsEnabled();
46  }
47 
48  private void customizeComponents() {
49 
50  sizeTextField.setComponentPopupMenu(rightClickMenu);
51  ActionListener actList = new ActionListener() {
52  @Override
53  public void actionPerformed(ActionEvent e) {
54  JMenuItem jmi = (JMenuItem) e.getSource();
55  if (jmi.equals(cutMenuItem)) {
56  sizeTextField.cut();
57  } else if (jmi.equals(copyMenuItem)) {
58  sizeTextField.copy();
59  } else if (jmi.equals(pasteMenuItem)) {
60  sizeTextField.paste();
61  } else if (jmi.equals(selectAllMenuItem)) {
62  sizeTextField.selectAll();
63  }
64  }
65  };
66  cutMenuItem.addActionListener(actList);
67  copyMenuItem.addActionListener(actList);
68  pasteMenuItem.addActionListener(actList);
69  selectAllMenuItem.addActionListener(actList);
70  this.sizeTextField.getDocument().addDocumentListener(new DocumentListener() {
71  @Override
72  public void insertUpdate(DocumentEvent e) {
73  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
74  }
75 
76  @Override
77  public void removeUpdate(DocumentEvent e) {
78  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
79  }
80 
81  @Override
82  public void changedUpdate(DocumentEvent e) {
83  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
84  }
85  });
86 
87 
88 
89  }
90 
91  JCheckBox getSizeCheckBox() {
92  return sizeCheckBox;
93  }
94 
95  JComboBox<String> getSizeCompareComboBox() {
96  return sizeCompareComboBox;
97  }
98 
99  JFormattedTextField getSizeTextField() {
100  return sizeTextField;
101  }
102 
103  JComboBox<String> getSizeUnitComboBox() {
104  return sizeUnitComboBox;
105  }
106 
107  void setComponentsEnabled() {
108  boolean enabled = this.sizeCheckBox.isSelected();
109  this.sizeCompareComboBox.setEnabled(enabled);
110  this.sizeUnitComboBox.setEnabled(enabled);
111  this.sizeTextField.setEnabled(enabled);
112  }
113 
119  @SuppressWarnings("unchecked")
120  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
121  private void initComponents() {
122 
123  rightClickMenu = new javax.swing.JPopupMenu();
124  cutMenuItem = new javax.swing.JMenuItem();
125  copyMenuItem = new javax.swing.JMenuItem();
126  pasteMenuItem = new javax.swing.JMenuItem();
127  selectAllMenuItem = new javax.swing.JMenuItem();
128  sizeUnitComboBox = new javax.swing.JComboBox<>();
129  sizeTextField = new JFormattedTextField(NumberFormat.getIntegerInstance());
130  sizeCompareComboBox = new javax.swing.JComboBox<>();
131  sizeCheckBox = new javax.swing.JCheckBox();
132 
133  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.cutMenuItem.text")); // NOI18N
134  rightClickMenu.add(cutMenuItem);
135 
136  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.copyMenuItem.text")); // NOI18N
137  rightClickMenu.add(copyMenuItem);
138 
139  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.pasteMenuItem.text")); // NOI18N
140  rightClickMenu.add(pasteMenuItem);
141 
142  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.selectAllMenuItem.text")); // NOI18N
143  rightClickMenu.add(selectAllMenuItem);
144 
145  sizeUnitComboBox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "Byte(s)", "KB", "MB", "GB", "TB" }));
146 
147  sizeTextField.setValue(0);
148 
149  sizeCompareComboBox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "equal to", "greater than", "less than" }));
150 
151  sizeCheckBox.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.sizeCheckBox.text")); // NOI18N
152  sizeCheckBox.addActionListener(new java.awt.event.ActionListener() {
153  public void actionPerformed(java.awt.event.ActionEvent evt) {
154  sizeCheckBoxActionPerformed(evt);
155  }
156  });
157 
158  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
159  this.setLayout(layout);
160  layout.setHorizontalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addGroup(layout.createSequentialGroup()
163  .addComponent(sizeCheckBox)
164  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165  .addComponent(sizeCompareComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
166  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
167  .addComponent(sizeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
168  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
169  .addComponent(sizeUnitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
170  .addGap(63, 63, 63))
171  );
172  layout.setVerticalGroup(
173  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
174  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
175  .addComponent(sizeCompareComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
176  .addComponent(sizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
177  .addComponent(sizeUnitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
178  .addComponent(sizeCheckBox))
179  );
180  }// </editor-fold>//GEN-END:initComponents
181 
182  private void sizeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sizeCheckBoxActionPerformed
183  setComponentsEnabled();
184  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
185  }//GEN-LAST:event_sizeCheckBoxActionPerformed
186 
187  // Variables declaration - do not modify//GEN-BEGIN:variables
188  private javax.swing.JMenuItem copyMenuItem;
189  private javax.swing.JMenuItem cutMenuItem;
190  private javax.swing.JMenuItem pasteMenuItem;
191  private javax.swing.JPopupMenu rightClickMenu;
192  private javax.swing.JMenuItem selectAllMenuItem;
193  private javax.swing.JCheckBox sizeCheckBox;
194  private javax.swing.JComboBox<String> sizeCompareComboBox;
195  private javax.swing.JFormattedTextField sizeTextField;
196  private javax.swing.JComboBox<String> sizeUnitComboBox;
197  // End of variables declaration//GEN-END:variables
198 
199  void addActionListener(ActionListener l) {
200  sizeTextField.addActionListener(l);
201  }
202 }

Copyright © 2012-2022 Basis Technology. Generated on: Thu Sep 29 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.