19 package org.sleuthkit.autopsy.filesearch;
21 import java.awt.Component;
22 import java.awt.event.ActionListener;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.text.DateFormat;
26 import java.text.ParseException;
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.Calendar;
30 import java.util.Date;
31 import java.util.Iterator;
32 import java.util.List;
34 import java.util.SimpleTimeZone;
35 import java.util.TimeZone;
36 import javax.swing.JLabel;
37 import javax.swing.JList;
38 import javax.swing.JSeparator;
39 import javax.swing.ListCellRenderer;
40 import javax.swing.border.EmptyBorder;
42 import org.openide.util.NbBundle;
49 class DateSearchFilter
extends AbstractFileSearchFilter<DateSearchPanel> {
51 private static final String NONE_SELECTED_MESSAGE = NbBundle.getMessage(DateSearchFilter.class,
"DateSearchFilter.noneSelectedMsg.text");
52 private static final DateFormat DATE_FORMAT =
new SimpleDateFormat(
"MM/dd/yyyy");
53 private static final String SEPARATOR =
"SEPARATOR";
59 this(
new DateSearchPanel(DATE_FORMAT, DateSearchFilter.createTimeZoneList()));
62 private DateSearchFilter(DateSearchPanel panel) {
64 Case.addPropertyChangeListener(this.
new CasePropertyChangeListener());
68 public boolean isEnabled() {
69 return this.getComponent().getDateCheckBox().isSelected();
73 public String getPredicate() throws FilterValidationException {
74 String addQuery =
"1";
75 DateSearchPanel panel = this.getComponent();
78 String tz = this.getComponent().getTimeZoneComboBox().getSelectedItem().toString();
79 String tzID = tz.substring(tz.indexOf(
" ") + 1);
80 TimeZone selectedTZ = TimeZone.getTimeZone(tzID);
84 String startDateValue = panel.getDateFromTextField().getText();
85 Calendar startDate = null;
87 DateFormat sdf =
new SimpleDateFormat(
"MM/dd/yyyy");
88 sdf.setTimeZone(selectedTZ);
89 Date temp = sdf.parse(startDateValue);
91 startDate = Calendar.getInstance(
new SimpleTimeZone(0,
"GMT"));
92 startDate.setTime(temp);
93 }
catch (ParseException ex) {
96 if (!startDateValue.equals(
"")) {
97 if (startDate != null) {
98 fromDate = startDate.getTimeInMillis() / 1000;
103 String endDateValue = panel.getDateToTextField().getText();
104 Calendar endDate = null;
106 DateFormat sdf =
new SimpleDateFormat(
"MM/dd/yyyy");
107 sdf.setTimeZone(selectedTZ);
108 Date temp2 = sdf.parse(endDateValue);
110 endDate = Calendar.getInstance(
new SimpleTimeZone(0,
"GMT"));
111 endDate.setTime(temp2);
112 endDate.set(Calendar.HOUR, endDate.get(Calendar.HOUR) + 24);
113 }
catch (ParseException ex) {
116 if (!endDateValue.equals(
"")) {
117 if (endDate != null) {
118 toDate = endDate.getTimeInMillis() / 1000;
122 final boolean modifiedChecked = panel.getModifiedCheckBox().isSelected();
123 final boolean changedChecked = panel.getChangedCheckBox().isSelected();
124 final boolean accessedChecked = panel.getAccessedCheckBox().isSelected();
125 final boolean createdChecked = panel.getAccessedCheckBox().isSelected();
128 if (modifiedChecked || changedChecked || accessedChecked || createdChecked) {
130 String subQuery =
"0";
132 if (modifiedChecked) {
133 subQuery +=
" or mtime between " + fromDate +
" and " + toDate;
136 if (changedChecked) {
137 subQuery +=
" or ctime between " + fromDate +
" and " + toDate;
140 if (accessedChecked) {
141 subQuery +=
" or atime between " + fromDate +
" and " + toDate;
144 if (createdChecked) {
145 subQuery +=
" or crtime between " + fromDate +
" and " + toDate;
148 addQuery +=
" and (" + subQuery +
")";
150 throw new FilterValidationException(NONE_SELECTED_MESSAGE);
157 private void updateTimeZoneList() {
158 this.getComponent().setTimeZones(DateSearchFilter.createTimeZoneList());
161 private static List<String> createTimeZoneList() {
163 List<String> timeZones =
new ArrayList<String>();
165 if (Case.existsCurrentCase()) {
167 Case currentCase = Case.getCurrentCase();
169 Set<TimeZone> caseTimeZones = currentCase.getTimeZone();
170 Iterator<TimeZone> iterator = caseTimeZones.iterator();
171 while (iterator.hasNext()) {
172 TimeZone zone = iterator.next();
173 int offset = zone.getRawOffset() / 1000;
174 int hour = offset / 3600;
175 int minutes = (offset % 3600) / 60;
176 String item = String.format(
"(GMT%+d:%02d) %s", hour, minutes, zone.getID());
180 if (caseTimeZones.size() > 0) {
181 timeZones.add(SEPARATOR);
185 String[] ids = SimpleTimeZone.getAvailableIDs();
186 for (String
id : ids) {
187 TimeZone zone = TimeZone.getTimeZone(
id);
188 int offset = zone.getRawOffset() / 1000;
189 int hour = offset / 3600;
190 int minutes = (offset % 3600) / 60;
191 String item = String.format(
"(GMT%+d:%02d) %s", hour, minutes,
id);
200 public void addActionListener(ActionListener l) {
201 getComponent().addActionListener(l);
207 static class ComboBoxRenderer
extends JLabel implements ListCellRenderer<String> {
209 JSeparator separator;
213 setBorder(
new EmptyBorder(1, 1, 1, 1));
214 separator =
new JSeparator(JSeparator.HORIZONTAL);
218 public Component getListCellRendererComponent(JList<? extends String> list, String value,
int index,
boolean isSelected,
boolean cellHasFocus) {
219 String str = (value == null) ?
"" : value;
220 if (SEPARATOR.equals(str)) {
224 setBackground(list.getSelectionBackground());
225 setForeground(list.getSelectionForeground());
227 setBackground(list.getBackground());
228 setForeground(list.getForeground());
230 setFont(list.getFont());
240 String changed = evt.getPropertyName();
241 Object oldValue = evt.getOldValue();
242 Object newValue = evt.getNewValue();
246 if (newValue != null) {
247 DateSearchFilter.this.updateTimeZoneList();
253 DateSearchFilter.this.updateTimeZoneList();
258 DateSearchFilter.this.updateTimeZoneList();
void propertyChange(PropertyChangeEvent evt)