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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.