Autopsy  4.1
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 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 
33 class SizeSearchPanel extends javax.swing.JPanel {
34 
38  SizeSearchPanel() {
39  initComponents();
40  customizeComponents();
41  setComponentsEnabled();
42  }
43 
44  private void customizeComponents() {
45 
46  sizeTextField.setComponentPopupMenu(rightClickMenu);
47  ActionListener actList = new ActionListener() {
48  @Override
49  public void actionPerformed(ActionEvent e) {
50  JMenuItem jmi = (JMenuItem) e.getSource();
51  if (jmi.equals(cutMenuItem)) {
52  sizeTextField.cut();
53  } else if (jmi.equals(copyMenuItem)) {
54  sizeTextField.copy();
55  } else if (jmi.equals(pasteMenuItem)) {
56  sizeTextField.paste();
57  } else if (jmi.equals(selectAllMenuItem)) {
58  sizeTextField.selectAll();
59  }
60  }
61  };
62  cutMenuItem.addActionListener(actList);
63  copyMenuItem.addActionListener(actList);
64  pasteMenuItem.addActionListener(actList);
65  selectAllMenuItem.addActionListener(actList);
66 
67  }
68 
69  JCheckBox getSizeCheckBox() {
70  return sizeCheckBox;
71  }
72 
73  JComboBox<String> getSizeCompareComboBox() {
74  return sizeCompareComboBox;
75  }
76 
77  JFormattedTextField getSizeTextField() {
78  return sizeTextField;
79  }
80 
81  JComboBox<String> getSizeUnitComboBox() {
82  return sizeUnitComboBox;
83  }
84 
85  void setComponentsEnabled() {
86  boolean enabled = this.sizeCheckBox.isSelected();
87  this.sizeCompareComboBox.setEnabled(enabled);
88  this.sizeUnitComboBox.setEnabled(enabled);
89  this.sizeTextField.setEnabled(enabled);
90  }
91 
97  @SuppressWarnings("unchecked")
98  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
99  private void initComponents() {
100 
101  rightClickMenu = new javax.swing.JPopupMenu();
102  cutMenuItem = new javax.swing.JMenuItem();
103  copyMenuItem = new javax.swing.JMenuItem();
104  pasteMenuItem = new javax.swing.JMenuItem();
105  selectAllMenuItem = new javax.swing.JMenuItem();
106  sizeUnitComboBox = new javax.swing.JComboBox<>();
107  sizeTextField = new JFormattedTextField(NumberFormat.getIntegerInstance());
108  sizeCompareComboBox = new javax.swing.JComboBox<>();
109  sizeCheckBox = new javax.swing.JCheckBox();
110 
111  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.cutMenuItem.text")); // NOI18N
112  rightClickMenu.add(cutMenuItem);
113 
114  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.copyMenuItem.text")); // NOI18N
115  rightClickMenu.add(copyMenuItem);
116 
117  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.pasteMenuItem.text")); // NOI18N
118  rightClickMenu.add(pasteMenuItem);
119 
120  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.selectAllMenuItem.text")); // NOI18N
121  rightClickMenu.add(selectAllMenuItem);
122 
123  sizeUnitComboBox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "Byte(s)", "KB", "MB", "GB", "TB" }));
124 
125  sizeTextField.setValue(0);
126  sizeTextField.addMouseListener(new java.awt.event.MouseAdapter() {
127  public void mouseClicked(java.awt.event.MouseEvent evt) {
128  sizeTextFieldMouseClicked(evt);
129  }
130  });
131 
132  sizeCompareComboBox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "equal to", "greater than", "less than" }));
133 
134  sizeCheckBox.setText(org.openide.util.NbBundle.getMessage(SizeSearchPanel.class, "SizeSearchPanel.sizeCheckBox.text")); // NOI18N
135  sizeCheckBox.addActionListener(new java.awt.event.ActionListener() {
136  public void actionPerformed(java.awt.event.ActionEvent evt) {
137  sizeCheckBoxActionPerformed(evt);
138  }
139  });
140 
141  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
142  this.setLayout(layout);
143  layout.setHorizontalGroup(
144  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145  .addGroup(layout.createSequentialGroup()
146  .addComponent(sizeCheckBox)
147  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
148  .addComponent(sizeCompareComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
149  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
150  .addComponent(sizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
151  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
152  .addComponent(sizeUnitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
153  );
154  layout.setVerticalGroup(
155  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
157  .addComponent(sizeCompareComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
158  .addComponent(sizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
159  .addComponent(sizeUnitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
160  .addComponent(sizeCheckBox))
161  );
162  }// </editor-fold>//GEN-END:initComponents
163 
164  private void sizeTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sizeTextFieldMouseClicked
165  this.sizeCheckBox.setSelected(true);
166  this.sizeTextField.selectAll(); // select all so user can change it easily
167  }//GEN-LAST:event_sizeTextFieldMouseClicked
168 
169  private void sizeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sizeCheckBoxActionPerformed
170  setComponentsEnabled();
171  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
172  }//GEN-LAST:event_sizeCheckBoxActionPerformed
173 
174  // Variables declaration - do not modify//GEN-BEGIN:variables
175  private javax.swing.JMenuItem copyMenuItem;
176  private javax.swing.JMenuItem cutMenuItem;
177  private javax.swing.JMenuItem pasteMenuItem;
178  private javax.swing.JPopupMenu rightClickMenu;
179  private javax.swing.JMenuItem selectAllMenuItem;
180  private javax.swing.JCheckBox sizeCheckBox;
181  private javax.swing.JComboBox<String> sizeCompareComboBox;
182  private javax.swing.JFormattedTextField sizeTextField;
183  private javax.swing.JComboBox<String> sizeUnitComboBox;
184  // End of variables declaration//GEN-END:variables
185 
186  void addActionListener(ActionListener l) {
187  sizeTextField.addActionListener(l);
188  }
189 }

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