20 package org.sleuthkit.autopsy.filesearch;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.text.DateFormat;
25 import java.text.ParseException;
26 import java.util.Date;
27 import java.util.List;
28 import javax.swing.JCheckBox;
29 import javax.swing.JComboBox;
30 import javax.swing.JFormattedTextField;
31 import javax.swing.JMenuItem;
32 import javax.swing.JPopupMenu;
37 class DateSearchPanel
extends javax.swing.JPanel {
39 DateFormat dateFormat;
40 List<String> timeZones;
42 DateSearchPanel(DateFormat dateFormat, List<String> timeZones) {
43 this.dateFormat = dateFormat;
44 this.timeZones = timeZones;
47 customizeComponents();
50 private void customizeComponents(){
52 dateFromTextField.setComponentPopupMenu(rightClickMenu);
53 dateToTextField.setComponentPopupMenu(rightClickMenu);
54 ActionListener actList =
new ActionListener(){
56 public void actionPerformed(ActionEvent e){
57 JMenuItem jmi = (JMenuItem) e.getSource();
59 JFormattedTextField jftf = (JFormattedTextField) ((JPopupMenu) jmi.getParent()).getInvoker();
60 if(jmi.equals(cutMenuItem))
62 else if(jmi.equals(copyMenuItem))
64 else if(jmi.equals(pasteMenuItem))
66 else if(jmi.equals(selectAllMenuItem))
70 cutMenuItem.addActionListener(actList);
71 copyMenuItem.addActionListener(actList);
72 pasteMenuItem.addActionListener(actList);
73 selectAllMenuItem.addActionListener(actList);
77 JCheckBox getAccessedCheckBox() {
78 return accessedCheckBox;
81 JCheckBox getChangedCheckBox() {
82 return changedCheckBox;
85 JCheckBox getCreatedCheckBox() {
86 return createdCheckBox;
89 JCheckBox getDateCheckBox() {
93 JFormattedTextField getDateFromTextField() {
94 return dateFromTextField;
97 JFormattedTextField getDateToTextField() {
98 return dateToTextField;
101 JCheckBox getModifiedCheckBox() {
102 return modifiedCheckBox;
105 JComboBox<String> getTimeZoneComboBox() {
106 return timeZoneComboBox;
109 void setTimeZones(List<String> newTimeZones) {
110 this.timeZones = newTimeZones;
111 this.timeZoneComboBox.removeAllItems();
112 for (String tz : newTimeZones) {
113 this.timeZoneComboBox.addItem(tz);
122 @SuppressWarnings(
"unchecked")
124 private
void initComponents() {
126 rightClickMenu =
new javax.swing.JPopupMenu();
127 cutMenuItem =
new javax.swing.JMenuItem();
128 copyMenuItem =
new javax.swing.JMenuItem();
129 pasteMenuItem =
new javax.swing.JMenuItem();
130 selectAllMenuItem =
new javax.swing.JMenuItem();
131 dateToTextField =
new JFormattedTextField(this.dateFormat);
132 jLabel1 =
new javax.swing.JLabel();
133 jLabel4 =
new javax.swing.JLabel();
134 dateCheckBox =
new javax.swing.JCheckBox();
135 timeZoneComboBox =
new JComboBox<>(this.timeZones.toArray(
new String[this.timeZones.size()]));
136 timeZoneComboBox.setRenderer(
new DateSearchFilter.ComboBoxRenderer());
137 jLabel3 =
new javax.swing.JLabel();
138 dateFromTextField =
new JFormattedTextField(this.dateFormat);
139 jLabel2 =
new javax.swing.JLabel();
140 modifiedCheckBox =
new javax.swing.JCheckBox();
141 changedCheckBox =
new javax.swing.JCheckBox();
142 accessedCheckBox =
new javax.swing.JCheckBox();
143 createdCheckBox =
new javax.swing.JCheckBox();
144 dateFromButtonCalendar =
new org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton();
145 dateToButtonCalendar =
new org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton();
147 cutMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.cutMenuItem.text"));
148 rightClickMenu.add(cutMenuItem);
150 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.copyMenuItem.text"));
151 rightClickMenu.add(copyMenuItem);
153 pasteMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.pasteMenuItem.text"));
154 rightClickMenu.add(pasteMenuItem);
156 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.selectAllMenuItem.text"));
157 rightClickMenu.add(selectAllMenuItem);
159 dateToTextField.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateToTextField.text"));
160 dateToTextField.addFocusListener(
new java.awt.event.FocusAdapter() {
161 public void focusLost(java.awt.event.FocusEvent evt) {
162 dateToTextFieldFocusLost(evt);
166 jLabel1.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel1.text"));
168 jLabel4.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel4.text"));
170 dateCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateCheckBox.text"));
172 jLabel3.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel3.text"));
174 dateFromTextField.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateFromTextField.text"));
175 dateFromTextField.addFocusListener(
new java.awt.event.FocusAdapter() {
176 public void focusLost(java.awt.event.FocusEvent evt) {
177 dateFromTextFieldFocusLost(evt);
181 jLabel2.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel2.text"));
183 modifiedCheckBox.setSelected(
true);
184 modifiedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.modifiedCheckBox.text"));
186 changedCheckBox.setSelected(
true);
187 changedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.changedCheckBox.text"));
189 accessedCheckBox.setSelected(
true);
190 accessedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.accessedCheckBox.text"));
192 createdCheckBox.setSelected(
true);
193 createdCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.createdCheckBox.text"));
195 dateFromButtonCalendar.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateFromButtonCalendar.text"));
196 dateFromButtonCalendar.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
197 public void propertyChange(java.beans.PropertyChangeEvent evt) {
198 dateFromPopupChanged(evt);
202 dateToButtonCalendar.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateToButtonCalendar.text"));
203 dateToButtonCalendar.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
204 public void propertyChange(java.beans.PropertyChangeEvent evt) {
205 dateToPopupChanged(evt);
209 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
210 this.setLayout(layout);
211 layout.setHorizontalGroup(
212 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213 .addGroup(layout.createSequentialGroup()
214 .addComponent(dateCheckBox)
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216 .addComponent(dateFromTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
218 .addComponent(dateFromButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
219 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
220 .addComponent(jLabel1)
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
222 .addComponent(dateToTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
224 .addComponent(dateToButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
225 .addGroup(layout.createSequentialGroup()
227 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addGroup(layout.createSequentialGroup()
229 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230 .addComponent(changedCheckBox)
231 .addComponent(modifiedCheckBox))
232 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
233 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234 .addComponent(accessedCheckBox)
235 .addComponent(createdCheckBox)))
236 .addGroup(layout.createSequentialGroup()
237 .addComponent(jLabel4)
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
240 .addGroup(layout.createSequentialGroup()
242 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243 .addComponent(jLabel3)
244 .addComponent(jLabel2)))))
246 layout.setVerticalGroup(
247 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addGroup(layout.createSequentialGroup()
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
251 .addComponent(dateCheckBox)
252 .addComponent(dateFromTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
253 .addComponent(dateToButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
254 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
255 .addComponent(jLabel1)
256 .addComponent(dateToTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
257 .addComponent(dateFromButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
259 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
260 .addComponent(jLabel4)
261 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
262 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
263 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
264 .addGroup(layout.createSequentialGroup()
265 .addComponent(modifiedCheckBox)
266 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
267 .addComponent(changedCheckBox))
268 .addGroup(layout.createSequentialGroup()
269 .addComponent(accessedCheckBox)
271 .addComponent(createdCheckBox))
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
273 .addComponent(jLabel2)
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addComponent(jLabel3)
276 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
280 private void dateFromTextFieldFocusLost(java.awt.event.FocusEvent evt) {
282 String fromDateString = this.dateFromTextField.getText();
283 if (!fromDateString.equals(
"")) {
285 Date fromDate = dateFormat.parse(fromDateString);
286 dateFromButtonCalendar.setTargetDate(fromDate);
287 }
catch (ParseException ex) {
293 private void dateToTextFieldFocusLost(java.awt.event.FocusEvent evt) {
295 String toDateString = this.dateToTextField.getText();
296 if (!toDateString.equals(
"")) {
298 Date toDate = dateFormat.parse(toDateString);
299 dateToButtonCalendar.setTargetDate(toDate);
300 }
catch (ParseException ex) {
306 private void dateFromPopupChanged(java.beans.PropertyChangeEvent evt) {
307 if (evt.getNewValue() instanceof Date) {
308 setFromDate((Date) evt.getNewValue());
312 private void dateToPopupChanged(java.beans.PropertyChangeEvent evt) {
313 if (evt.getNewValue() instanceof Date) {
314 setToDate((Date) evt.getNewValue());
322 private void setFromDate(Date date) {
323 String dateStringResult =
"";
325 dateStringResult = dateFormat.format(date);
327 dateFromTextField.setText(dateStringResult);
328 dateFromButtonCalendar.setTargetDate(date);
335 private void setToDate(Date date) {
336 String dateStringResult =
"";
338 dateStringResult = dateFormat.format(date);
340 dateToTextField.setText(dateStringResult);
341 dateToButtonCalendar.setTargetDate(date);
344 private javax.swing.JCheckBox accessedCheckBox;
345 private javax.swing.JCheckBox changedCheckBox;
346 private javax.swing.JMenuItem copyMenuItem;
347 private javax.swing.JCheckBox createdCheckBox;
348 private javax.swing.JMenuItem cutMenuItem;
349 private javax.swing.JCheckBox dateCheckBox;
350 private org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton dateFromButtonCalendar;
351 private javax.swing.JFormattedTextField dateFromTextField;
352 private org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton dateToButtonCalendar;
353 private javax.swing.JFormattedTextField dateToTextField;
354 private javax.swing.JLabel jLabel1;
355 private javax.swing.JLabel jLabel2;
356 private javax.swing.JLabel jLabel3;
357 private javax.swing.JLabel jLabel4;
358 private javax.swing.JCheckBox modifiedCheckBox;
359 private javax.swing.JMenuItem pasteMenuItem;
360 private javax.swing.JPopupMenu rightClickMenu;
361 private javax.swing.JMenuItem selectAllMenuItem;
362 private javax.swing.JComboBox<String> timeZoneComboBox;
365 void addActionListener(ActionListener l) {
366 dateFromTextField.addActionListener(l);
367 dateToTextField.addActionListener(l);