19 package org.sleuthkit.autopsy.filesearch;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.text.DateFormat;
24 import java.text.ParseException;
25 import java.util.Date;
26 import java.util.List;
27 import javax.swing.JCheckBox;
28 import javax.swing.JComboBox;
29 import javax.swing.JFormattedTextField;
30 import javax.swing.JMenuItem;
31 import javax.swing.JPopupMenu;
36 class DateSearchPanel
extends javax.swing.JPanel {
38 DateFormat dateFormat;
39 List<String> timeZones;
41 DateSearchPanel(DateFormat dateFormat, List<String> timeZones) {
42 this.dateFormat = dateFormat;
43 this.timeZones = timeZones;
46 customizeComponents();
49 private void customizeComponents() {
51 dateFromTextField.setComponentPopupMenu(rightClickMenu);
52 dateToTextField.setComponentPopupMenu(rightClickMenu);
53 ActionListener actList =
new ActionListener() {
55 public void actionPerformed(ActionEvent e) {
56 JMenuItem jmi = (JMenuItem) e.getSource();
61 JFormattedTextField jftf = (JFormattedTextField) ((JPopupMenu) jmi.getParent()).getInvoker();
62 if (jmi.equals(cutMenuItem)) {
64 }
else if (jmi.equals(copyMenuItem)) {
66 }
else if (jmi.equals(pasteMenuItem)) {
68 }
else if (jmi.equals(selectAllMenuItem)) {
73 cutMenuItem.addActionListener(actList);
74 copyMenuItem.addActionListener(actList);
75 pasteMenuItem.addActionListener(actList);
76 selectAllMenuItem.addActionListener(actList);
79 JCheckBox getAccessedCheckBox() {
80 return accessedCheckBox;
83 JCheckBox getChangedCheckBox() {
84 return changedCheckBox;
87 JCheckBox getCreatedCheckBox() {
88 return createdCheckBox;
91 JCheckBox getDateCheckBox() {
95 JFormattedTextField getDateFromTextField() {
96 return dateFromTextField;
99 JFormattedTextField getDateToTextField() {
100 return dateToTextField;
103 JCheckBox getModifiedCheckBox() {
104 return modifiedCheckBox;
107 JComboBox<String> getTimeZoneComboBox() {
108 return timeZoneComboBox;
111 void setTimeZones(List<String> newTimeZones) {
112 this.timeZones = newTimeZones;
113 this.timeZoneComboBox.removeAllItems();
114 for (String tz : newTimeZones) {
115 this.timeZoneComboBox.addItem(tz);
124 @SuppressWarnings(
"unchecked")
126 private
void initComponents() {
128 rightClickMenu =
new javax.swing.JPopupMenu();
129 cutMenuItem =
new javax.swing.JMenuItem();
130 copyMenuItem =
new javax.swing.JMenuItem();
131 pasteMenuItem =
new javax.swing.JMenuItem();
132 selectAllMenuItem =
new javax.swing.JMenuItem();
133 dateToTextField =
new JFormattedTextField(this.dateFormat);
134 jLabel1 =
new javax.swing.JLabel();
135 jLabel4 =
new javax.swing.JLabel();
136 dateCheckBox =
new javax.swing.JCheckBox();
137 timeZoneComboBox =
new JComboBox<>(this.timeZones.toArray(
new String[this.timeZones.size()]));
138 timeZoneComboBox.setRenderer(
new DateSearchFilter.ComboBoxRenderer());
139 jLabel3 =
new javax.swing.JLabel();
140 dateFromTextField =
new JFormattedTextField(this.dateFormat);
141 jLabel2 =
new javax.swing.JLabel();
142 modifiedCheckBox =
new javax.swing.JCheckBox();
143 changedCheckBox =
new javax.swing.JCheckBox();
144 accessedCheckBox =
new javax.swing.JCheckBox();
145 createdCheckBox =
new javax.swing.JCheckBox();
146 dateFromButtonCalendar =
new org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton();
147 dateToButtonCalendar =
new org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton();
149 cutMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.cutMenuItem.text"));
150 rightClickMenu.add(cutMenuItem);
152 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.copyMenuItem.text"));
153 rightClickMenu.add(copyMenuItem);
155 pasteMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.pasteMenuItem.text"));
156 rightClickMenu.add(pasteMenuItem);
158 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.selectAllMenuItem.text"));
159 rightClickMenu.add(selectAllMenuItem);
161 dateToTextField.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateToTextField.text"));
162 dateToTextField.addFocusListener(
new java.awt.event.FocusAdapter() {
163 public void focusLost(java.awt.event.FocusEvent evt) {
164 dateToTextFieldFocusLost(evt);
168 jLabel1.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel1.text"));
170 jLabel4.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel4.text"));
172 dateCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateCheckBox.text"));
174 jLabel3.setFont(
new java.awt.Font(
"Tahoma", 0, 10));
175 jLabel3.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel3.text"));
177 dateFromTextField.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateFromTextField.text"));
178 dateFromTextField.addFocusListener(
new java.awt.event.FocusAdapter() {
179 public void focusLost(java.awt.event.FocusEvent evt) {
180 dateFromTextFieldFocusLost(evt);
184 jLabel2.setFont(
new java.awt.Font(
"Tahoma", 0, 10));
185 jLabel2.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.jLabel2.text"));
187 modifiedCheckBox.setSelected(
true);
188 modifiedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.modifiedCheckBox.text"));
190 changedCheckBox.setSelected(
true);
191 changedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.changedCheckBox.text"));
193 accessedCheckBox.setSelected(
true);
194 accessedCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.accessedCheckBox.text"));
196 createdCheckBox.setSelected(
true);
197 createdCheckBox.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.createdCheckBox.text"));
199 dateFromButtonCalendar.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateFromButtonCalendar.text"));
200 dateFromButtonCalendar.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
201 public void propertyChange(java.beans.PropertyChangeEvent evt) {
202 dateFromPopupChanged(evt);
206 dateToButtonCalendar.setText(
org.openide.util.NbBundle.getMessage(DateSearchPanel.class,
"DateSearchPanel.dateToButtonCalendar.text"));
207 dateToButtonCalendar.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
208 public void propertyChange(java.beans.PropertyChangeEvent evt) {
209 dateToPopupChanged(evt);
213 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
214 this.setLayout(layout);
215 layout.setHorizontalGroup(
216 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217 .addGroup(layout.createSequentialGroup()
218 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
219 .addGroup(layout.createSequentialGroup()
220 .addComponent(dateCheckBox)
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222 .addComponent(dateFromTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
224 .addComponent(dateFromButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
225 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
226 .addComponent(jLabel1)
227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
228 .addComponent(dateToTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
230 .addComponent(dateToButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
231 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
233 .addComponent(jLabel2)
234 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
235 .addComponent(jLabel3)))
236 .addContainerGap(26, Short.MAX_VALUE))
237 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
238 .addGap(0, 0, Short.MAX_VALUE)
239 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240 .addGroup(layout.createSequentialGroup()
241 .addComponent(jLabel4)
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
244 .addGroup(layout.createSequentialGroup()
245 .addComponent(modifiedCheckBox)
247 .addComponent(accessedCheckBox)
248 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
249 .addComponent(createdCheckBox)
250 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
251 .addComponent(changedCheckBox)))
254 layout.setVerticalGroup(
255 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256 .addGroup(layout.createSequentialGroup()
257 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
258 .addGroup(layout.createSequentialGroup()
259 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
260 .addComponent(dateCheckBox)
261 .addComponent(dateFromTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
263 .addGroup(layout.createSequentialGroup()
264 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addComponent(dateToButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
266 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
267 .addComponent(jLabel1)
268 .addComponent(dateToTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
269 .addComponent(dateFromButtonCalendar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
270 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
271 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
272 .addComponent(jLabel3)
273 .addComponent(jLabel2))
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
275 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
276 .addComponent(jLabel4)
277 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
278 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
279 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280 .addComponent(modifiedCheckBox, javax.swing.GroupLayout.Alignment.TRAILING)
281 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
282 .addComponent(accessedCheckBox)
283 .addComponent(createdCheckBox)
284 .addComponent(changedCheckBox)))
289 private void dateFromTextFieldFocusLost(java.awt.event.FocusEvent evt) {
291 String fromDateString = this.dateFromTextField.getText();
292 if (!fromDateString.equals(
"")) {
294 Date fromDate = dateFormat.parse(fromDateString);
295 dateFromButtonCalendar.setTargetDate(fromDate);
296 }
catch (ParseException ex) {
302 private void dateToTextFieldFocusLost(java.awt.event.FocusEvent evt) {
304 String toDateString = this.dateToTextField.getText();
305 if (!toDateString.equals(
"")) {
307 Date toDate = dateFormat.parse(toDateString);
308 dateToButtonCalendar.setTargetDate(toDate);
309 }
catch (ParseException ex) {
315 private void dateFromPopupChanged(java.beans.PropertyChangeEvent evt) {
316 if (evt.getNewValue() instanceof Date) {
317 setFromDate((Date) evt.getNewValue());
321 private void dateToPopupChanged(java.beans.PropertyChangeEvent evt) {
322 if (evt.getNewValue() instanceof Date) {
323 setToDate((Date) evt.getNewValue());
333 private void setFromDate(Date date) {
334 String dateStringResult =
"";
336 dateStringResult = dateFormat.format(date);
338 dateFromTextField.setText(dateStringResult);
339 dateFromButtonCalendar.setTargetDate(date);
347 private void setToDate(Date date) {
348 String dateStringResult =
"";
350 dateStringResult = dateFormat.format(date);
352 dateToTextField.setText(dateStringResult);
353 dateToButtonCalendar.setTargetDate(date);
356 private javax.swing.JCheckBox accessedCheckBox;
357 private javax.swing.JCheckBox changedCheckBox;
358 private javax.swing.JMenuItem copyMenuItem;
359 private javax.swing.JCheckBox createdCheckBox;
360 private javax.swing.JMenuItem cutMenuItem;
361 private javax.swing.JCheckBox dateCheckBox;
362 private org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton dateFromButtonCalendar;
363 private javax.swing.JFormattedTextField dateFromTextField;
364 private org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton dateToButtonCalendar;
365 private javax.swing.JFormattedTextField dateToTextField;
366 private javax.swing.JLabel jLabel1;
367 private javax.swing.JLabel jLabel2;
368 private javax.swing.JLabel jLabel3;
369 private javax.swing.JLabel jLabel4;
370 private javax.swing.JCheckBox modifiedCheckBox;
371 private javax.swing.JMenuItem pasteMenuItem;
372 private javax.swing.JPopupMenu rightClickMenu;
373 private javax.swing.JMenuItem selectAllMenuItem;
374 private javax.swing.JComboBox<String> timeZoneComboBox;
377 void addActionListener(ActionListener l) {
378 dateFromTextField.addActionListener(l);
379 dateToTextField.addActionListener(l);