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

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