19 package org.sleuthkit.autopsy.filesearch;
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;
34 @SuppressWarnings(
"PMD.SingularField")
35 class SizeSearchPanel extends javax.swing.JPanel {
37 private static final long serialVersionUID = 1L;
44 customizeComponents();
45 setComponentsEnabled();
48 private void customizeComponents() {
50 sizeTextField.setComponentPopupMenu(rightClickMenu);
51 ActionListener actList =
new ActionListener() {
53 public void actionPerformed(ActionEvent e) {
54 JMenuItem jmi = (JMenuItem) e.getSource();
55 if (jmi.equals(cutMenuItem)) {
57 }
else if (jmi.equals(copyMenuItem)) {
59 }
else if (jmi.equals(pasteMenuItem)) {
60 sizeTextField.paste();
61 }
else if (jmi.equals(selectAllMenuItem)) {
62 sizeTextField.selectAll();
66 cutMenuItem.addActionListener(actList);
67 copyMenuItem.addActionListener(actList);
68 pasteMenuItem.addActionListener(actList);
69 selectAllMenuItem.addActionListener(actList);
70 this.sizeTextField.getDocument().addDocumentListener(
new DocumentListener() {
72 public void insertUpdate(DocumentEvent e) {
73 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
77 public void removeUpdate(DocumentEvent e) {
78 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
82 public void changedUpdate(DocumentEvent e) {
83 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
91 JCheckBox getSizeCheckBox() {
95 JComboBox<String> getSizeCompareComboBox() {
96 return sizeCompareComboBox;
99 JFormattedTextField getSizeTextField() {
100 return sizeTextField;
103 JComboBox<String> getSizeUnitComboBox() {
104 return sizeUnitComboBox;
107 void setComponentsEnabled() {
108 boolean enabled = this.sizeCheckBox.isSelected();
109 this.sizeCompareComboBox.setEnabled(enabled);
110 this.sizeUnitComboBox.setEnabled(enabled);
111 this.sizeTextField.setEnabled(enabled);
119 @SuppressWarnings(
"unchecked")
121 private
void initComponents() {
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();
133 cutMenuItem.setText(
org.openide.util.NbBundle.getMessage(SizeSearchPanel.class,
"SizeSearchPanel.cutMenuItem.text"));
134 rightClickMenu.add(cutMenuItem);
136 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(SizeSearchPanel.class,
"SizeSearchPanel.copyMenuItem.text"));
137 rightClickMenu.add(copyMenuItem);
139 pasteMenuItem.setText(
org.openide.util.NbBundle.getMessage(SizeSearchPanel.class,
"SizeSearchPanel.pasteMenuItem.text"));
140 rightClickMenu.add(pasteMenuItem);
142 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(SizeSearchPanel.class,
"SizeSearchPanel.selectAllMenuItem.text"));
143 rightClickMenu.add(selectAllMenuItem);
145 sizeUnitComboBox.setModel(
new javax.swing.DefaultComboBoxModel<String>(
new String[] {
"Byte(s)",
"KB",
"MB",
"GB",
"TB" }));
147 sizeTextField.setValue(0);
149 sizeCompareComboBox.setModel(
new javax.swing.DefaultComboBoxModel<String>(
new String[] {
"equal to",
"greater than",
"less than" }));
151 sizeCheckBox.setText(
org.openide.util.NbBundle.getMessage(SizeSearchPanel.class,
"SizeSearchPanel.sizeCheckBox.text"));
152 sizeCheckBox.addActionListener(
new java.awt.event.ActionListener() {
153 public void actionPerformed(java.awt.event.ActionEvent evt) {
154 sizeCheckBoxActionPerformed(evt);
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)
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))
182 private void sizeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
183 setComponentsEnabled();
184 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
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;
199 void addActionListener(ActionListener l) {
200 sizeTextField.addActionListener(l);