Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MissingImageDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2014 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.casemodule;
20 
21 import java.awt.*;
22 import java.awt.event.WindowAdapter;
23 import java.awt.event.WindowEvent;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.ArrayList;
27 import java.util.logging.Level;
28 import java.io.File;
29 import javax.swing.JFileChooser;
30 import javax.swing.JFrame;
31 import javax.swing.JOptionPane;
32 import org.openide.util.NbBundle;
34 import org.sleuthkit.datamodel.SleuthkitCase;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
37 class MissingImageDialog extends javax.swing.JDialog {
38 
39  private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
40  long obj_id;
41  SleuthkitCase db;
42  static final GeneralFilter rawFilter = new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
43  static final GeneralFilter encaseFilter = new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
44  static final List<String> allExt = new ArrayList<String>();
45 
46  static {
47  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
48  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
49  }
50  static final String allDesc = NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.allDesc.text");
51  static final GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
52  private JFileChooser fc = new JFileChooser();
53 
54  private MissingImageDialog(long obj_id, SleuthkitCase db) {
55  super(new JFrame(), true);
56  this.obj_id = obj_id;
57  this.db = db;
58  initComponents();
59 
60  fc.setDragEnabled(false);
61  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
62  fc.setMultiSelectionEnabled(false);
63 
64  fc.addChoosableFileFilter(rawFilter);
65  fc.addChoosableFileFilter(encaseFilter);
66  fc.setFileFilter(allFilter);
67 
68  customInit();
69  }
70 
71 //
72 // * Client call to create a MissingImageDialog.
73 // *
74 // * @param obj_id obj_id of the missing image
75 // * @param db the current SleuthkitCase connected to a db
76 //
77  static void makeDialog(long obj_id, SleuthkitCase db) {
78  final MissingImageDialog dialog = new MissingImageDialog(obj_id, db);
79  dialog.addWindowListener(new WindowAdapter() {
80  @Override
81  public void windowClosing(WindowEvent e) {
82  dialog.cancel();
83  }
84  });
85  dialog.display();
86  }
87 
88  private void customInit() {
89 
90  selectButton.setEnabled(false);
91  }
92 
93  private void display() {
94  this.setTitle(NbBundle.getMessage(this.getClass(), "MissingImageDialog.display.title"));
95  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
96  // set the popUp window / JFrame
97  int w = this.getSize().width;
98  int h = this.getSize().height;
99  // set the location of the popUp Window on the center of the screen
100  setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
101 
102  this.setVisible(true);
103  }
104 
105 //
106 // * Focuses the select button for easy enter-pressing access.
107 //
108  private void moveFocusToSelect() {
109  this.selectButton.requestFocusInWindow();
110  }
111 
112 //
113 // * Enables/disables the select button based off the current panel.
114 //
115  private void updateSelectButton() {
116 
117  // Enable this based on whether there is a valid path
118  if (!pathNameTextField.getText().isEmpty()) {
119  String filePath = pathNameTextField.getText();
120  boolean isExist = Case.pathExists(filePath) || Case.driveExists(filePath);
121  selectButton.setEnabled(isExist);
122  }
123  }
124 
125 //
126 // * This method is called from within the constructor to initialize the form.
127 // * WARNING: Do NOT modify this code. The content of this method is always
128 // * regenerated by the Form Editor.
129 //
130  @SuppressWarnings("unchecked")
131  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
132  private void initComponents() {
133 
134  buttonPanel = new javax.swing.JPanel();
135  selectButton = new javax.swing.JButton();
136  cancelButton = new javax.swing.JButton();
137  containerPanel = new javax.swing.JPanel();
138  pathNameTextField = new javax.swing.JTextField();
139  browseButton = new javax.swing.JButton();
140  lbWarning = new javax.swing.JLabel();
141  titleLabel = new javax.swing.JLabel();
142  titleSeparator = new javax.swing.JSeparator();
143 
144  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
145 
146  selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
147  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.selectButton.text")); // NOI18N
148  selectButton.addActionListener(new java.awt.event.ActionListener() {
149  public void actionPerformed(java.awt.event.ActionEvent evt) {
150  selectButtonActionPerformed(evt);
151  }
152  });
153 
154  cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
155  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.cancelButton.text")); // NOI18N
156  cancelButton.addActionListener(new java.awt.event.ActionListener() {
157  public void actionPerformed(java.awt.event.ActionEvent evt) {
158  cancelButtonActionPerformed(evt);
159  }
160  });
161 
162  javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
163  buttonPanel.setLayout(buttonPanelLayout);
164  buttonPanelLayout.setHorizontalGroup(
165  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
167  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
168  .addComponent(selectButton)
169  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
170  .addComponent(cancelButton)
171  .addContainerGap())
172  );
173  buttonPanelLayout.setVerticalGroup(
174  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175  .addGroup(buttonPanelLayout.createSequentialGroup()
176  .addContainerGap()
177  .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
178  .addComponent(selectButton)
179  .addComponent(cancelButton))
180  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
181  );
182 
183  pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
184  pathNameTextField.setText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.pathNameTextField.text")); // NOI18N
185  pathNameTextField.addActionListener(new java.awt.event.ActionListener() {
186  public void actionPerformed(java.awt.event.ActionEvent evt) {
187  pathNameTextFieldActionPerformed(evt);
188  }
189  });
190 
191  browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
192  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.browseButton.text")); // NOI18N
193  browseButton.addActionListener(new java.awt.event.ActionListener() {
194  public void actionPerformed(java.awt.event.ActionEvent evt) {
195  browseButtonActionPerformed(evt);
196  }
197  });
198 
199  lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
200  lbWarning.setForeground(new java.awt.Color(244, 0, 0));
201  org.openide.awt.Mnemonics.setLocalizedText(lbWarning, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.text")); // NOI18N
202  lbWarning.setToolTipText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.toolTipText")); // NOI18N
203 
204  javax.swing.GroupLayout containerPanelLayout = new javax.swing.GroupLayout(containerPanel);
205  containerPanel.setLayout(containerPanelLayout);
206  containerPanelLayout.setHorizontalGroup(
207  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208  .addGroup(containerPanelLayout.createSequentialGroup()
209  .addContainerGap()
210  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
212  .addGroup(containerPanelLayout.createSequentialGroup()
213  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
214  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215  .addComponent(browseButton)
216  .addContainerGap(83, Short.MAX_VALUE))))
217  );
218  containerPanelLayout.setVerticalGroup(
219  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addGroup(containerPanelLayout.createSequentialGroup()
221  .addGap(18, 18, 18)
222  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
223  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224  .addComponent(browseButton))
225  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
226  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
227  .addGap(18, 18, 18))
228  );
229 
230  titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
231  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.titleLabel.text")); // NOI18N
232 
233  titleSeparator.setForeground(new java.awt.Color(102, 102, 102));
234 
235  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
236  getContentPane().setLayout(layout);
237  layout.setHorizontalGroup(
238  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239  .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
240  .addGroup(layout.createSequentialGroup()
241  .addContainerGap()
242  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243  .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
244  .addGroup(layout.createSequentialGroup()
245  .addComponent(titleLabel)
246  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
247  .addComponent(titleSeparator)))
248  .addContainerGap())
249  );
250  layout.setVerticalGroup(
251  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
253  .addContainerGap()
254  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
255  .addComponent(titleLabel)
256  .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
257  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
258  .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
259  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
260  .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
261  );
262 
263  pack();
264  }// </editor-fold>//GEN-END:initComponents
265 
266  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
267  try {
268  String newPath = pathNameTextField.getText();
269  //TODO handle local files
270  db.setImagePaths(obj_id, Arrays.asList(new String[]{newPath}));
271  this.dispose();
272  } catch (TskCoreException ex) {
273  lbWarning.setText(NbBundle.getMessage(this.getClass(), "MissingImageDialog.ErrorSettingImage"));
274  logger.log(Level.WARNING, "Error setting image paths", ex); //NON-NLS
275  }
276  }//GEN-LAST:event_selectButtonActionPerformed
277 
278  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
279  cancel();
280  }//GEN-LAST:event_cancelButtonActionPerformed
281 
282  private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathNameTextFieldActionPerformed
283  // TODO add your handling code here:
284 
285  updateSelectButton();
286  }//GEN-LAST:event_pathNameTextFieldActionPerformed
287 
288  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
289 
290  String oldText = pathNameTextField.getText();
291  lbWarning.setText("");
292  // set the current directory of the FileChooser if the ImagePath Field is valid
293  File currentDir = new File(oldText);
294  if (currentDir.exists()) {
295  fc.setCurrentDirectory(currentDir);
296  }
297 
298  int retval = fc.showOpenDialog(this);
299  if (retval == JFileChooser.APPROVE_OPTION) {
300  String path = fc.getSelectedFile().getPath();
301  pathNameTextField.setText(path);
302  }
303  //pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString(), false, true);
304 
305  updateSelectButton();
306  }//GEN-LAST:event_browseButtonActionPerformed
307  // Variables declaration - do not modify//GEN-BEGIN:variables
308  private javax.swing.JButton browseButton;
309  private javax.swing.JPanel buttonPanel;
310  private javax.swing.JButton cancelButton;
311  private javax.swing.JPanel containerPanel;
312  private javax.swing.JLabel lbWarning;
313  private javax.swing.JTextField pathNameTextField;
314  private javax.swing.JButton selectButton;
315  private javax.swing.JLabel titleLabel;
316  private javax.swing.JSeparator titleSeparator;
317  // End of variables declaration//GEN-END:variables
318 
319 //
320 // * Verify the user wants to cancel searching for the image.
321 //
322  void cancel() {
323  int ret = JOptionPane.showConfirmDialog(null,
324  NbBundle.getMessage(this.getClass(),
325  "MissingImageDialog.confDlg.noFileSel.msg"),
326  NbBundle.getMessage(this.getClass(),
327  "MissingImageDialog.confDlg.noFileSel.title"),
328  JOptionPane.YES_NO_OPTION);
329  if (ret == JOptionPane.YES_OPTION) {
330  this.dispose();
331  }
332  }
333 }

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