Autopsy  4.7.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-2018 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.event.WindowAdapter;
22 import java.awt.event.WindowEvent;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.ArrayList;
26 import java.util.logging.Level;
27 import java.io.File;
28 import javax.swing.JFileChooser;
29 import javax.swing.JFrame;
30 import javax.swing.JOptionPane;
31 import org.openide.util.NbBundle;
32 import org.openide.windows.WindowManager;
35 import org.sleuthkit.datamodel.SleuthkitCase;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 class MissingImageDialog extends javax.swing.JDialog {
43 
44  private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
45  long obj_id;
46  SleuthkitCase db;
47  static final GeneralFilter rawFilter = new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
48  static final GeneralFilter encaseFilter = new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
49  static final List<String> allExt = new ArrayList<String>();
50 
51  static {
52  allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
53  allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
54  }
55  static final String allDesc = NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.allDesc.text");
56  static final GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
57  private final JFileChooser fc = new JFileChooser();
58 
65  private MissingImageDialog(long obj_id, SleuthkitCase db) {
66  super((JFrame) WindowManager.getDefault().getMainWindow(), true);
67  this.obj_id = obj_id;
68  this.db = db;
69  initComponents();
70 
71  fc.setDragEnabled(false);
72  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
73  fc.setMultiSelectionEnabled(false);
74 
75  fc.addChoosableFileFilter(rawFilter);
76  fc.addChoosableFileFilter(encaseFilter);
77  fc.setFileFilter(allFilter);
78 
79  selectButton.setEnabled(false);
80  }
81 
88  static void makeDialog(long obj_id, SleuthkitCase db) {
89  final MissingImageDialog dialog = new MissingImageDialog(obj_id, db);
90  dialog.addWindowListener(new WindowAdapter() {
91  @Override
92  public void windowClosing(WindowEvent e) {
93  dialog.cancel();
94  }
95  });
96  dialog.display();
97  }
98 
102  private void display() {
103  this.setTitle(NbBundle.getMessage(this.getClass(), "MissingImageDialog.display.title"));
104  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
105  this.setVisible(true);
106  }
107 
111  private void updateSelectButton() {
112 
113  // Enable this based on whether there is a valid path
114  if (!pathNameTextField.getText().isEmpty()) {
115  String filePath = pathNameTextField.getText();
116  boolean isExist = new File(filePath).isFile() || DriveUtils.driveExists(filePath);
117  selectButton.setEnabled(isExist);
118  }
119  }
120 
126  @SuppressWarnings("unchecked")
127  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
128  private void initComponents() {
129 
130  buttonPanel = new javax.swing.JPanel();
131  selectButton = new javax.swing.JButton();
132  cancelButton = new javax.swing.JButton();
133  containerPanel = new javax.swing.JPanel();
134  pathNameTextField = new javax.swing.JTextField();
135  browseButton = new javax.swing.JButton();
136  lbWarning = new javax.swing.JLabel();
137  titleLabel = new javax.swing.JLabel();
138  titleSeparator = new javax.swing.JSeparator();
139 
140  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
141 
142  selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
143  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.selectButton.text")); // NOI18N
144  selectButton.addActionListener(new java.awt.event.ActionListener() {
145  public void actionPerformed(java.awt.event.ActionEvent evt) {
146  selectButtonActionPerformed(evt);
147  }
148  });
149 
150  cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
151  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.cancelButton.text")); // NOI18N
152  cancelButton.addActionListener(new java.awt.event.ActionListener() {
153  public void actionPerformed(java.awt.event.ActionEvent evt) {
154  cancelButtonActionPerformed(evt);
155  }
156  });
157 
158  javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
159  buttonPanel.setLayout(buttonPanelLayout);
160  buttonPanelLayout.setHorizontalGroup(
161  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
163  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
164  .addComponent(selectButton)
165  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
166  .addComponent(cancelButton)
167  .addContainerGap())
168  );
169  buttonPanelLayout.setVerticalGroup(
170  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171  .addGroup(buttonPanelLayout.createSequentialGroup()
172  .addContainerGap()
173  .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
174  .addComponent(selectButton)
175  .addComponent(cancelButton))
176  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
177  );
178 
179  pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
180  pathNameTextField.setText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.pathNameTextField.text")); // NOI18N
181  pathNameTextField.addActionListener(new java.awt.event.ActionListener() {
182  public void actionPerformed(java.awt.event.ActionEvent evt) {
183  pathNameTextFieldActionPerformed(evt);
184  }
185  });
186 
187  browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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  lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
196  lbWarning.setForeground(new java.awt.Color(244, 0, 0));
197  org.openide.awt.Mnemonics.setLocalizedText(lbWarning, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.text")); // NOI18N
198  lbWarning.setToolTipText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.toolTipText")); // NOI18N
199 
200  javax.swing.GroupLayout containerPanelLayout = new javax.swing.GroupLayout(containerPanel);
201  containerPanel.setLayout(containerPanelLayout);
202  containerPanelLayout.setHorizontalGroup(
203  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addGroup(containerPanelLayout.createSequentialGroup()
205  .addContainerGap()
206  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
208  .addGroup(containerPanelLayout.createSequentialGroup()
209  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
210  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
211  .addComponent(browseButton)
212  .addContainerGap(83, Short.MAX_VALUE))))
213  );
214  containerPanelLayout.setVerticalGroup(
215  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
216  .addGroup(containerPanelLayout.createSequentialGroup()
217  .addGap(18, 18, 18)
218  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
219  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
220  .addComponent(browseButton))
221  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
222  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
223  .addGap(18, 18, 18))
224  );
225 
226  titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
227  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.titleLabel.text")); // NOI18N
228 
229  titleSeparator.setForeground(new java.awt.Color(102, 102, 102));
230 
231  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
232  getContentPane().setLayout(layout);
233  layout.setHorizontalGroup(
234  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235  .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
236  .addGroup(layout.createSequentialGroup()
237  .addContainerGap()
238  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239  .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
240  .addGroup(layout.createSequentialGroup()
241  .addComponent(titleLabel)
242  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
243  .addComponent(titleSeparator)))
244  .addContainerGap())
245  );
246  layout.setVerticalGroup(
247  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
249  .addContainerGap()
250  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
251  .addComponent(titleLabel)
252  .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
253  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
254  .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
255  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256  .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
257  );
258 
259  pack();
260  }// </editor-fold>//GEN-END:initComponents
261 
262  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
263  try {
264  String newPath = pathNameTextField.getText();
265  //TODO handle local files
266  db.setImagePaths(obj_id, Arrays.asList(new String[]{newPath}));
267  this.dispose();
268  } catch (TskCoreException ex) {
269  lbWarning.setText(NbBundle.getMessage(this.getClass(), "MissingImageDialog.ErrorSettingImage"));
270  logger.log(Level.WARNING, "Error setting image paths", ex); //NON-NLS
271  }
272  }//GEN-LAST:event_selectButtonActionPerformed
273 
274  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
275  cancel();
276  }//GEN-LAST:event_cancelButtonActionPerformed
277 
278  private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathNameTextFieldActionPerformed
279  updateSelectButton();
280  }//GEN-LAST:event_pathNameTextFieldActionPerformed
281 
282  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
283 
284  String oldText = pathNameTextField.getText();
285  lbWarning.setText("");
286  // set the current directory of the FileChooser if the ImagePath Field is valid
287  File currentDir = new File(oldText);
288  if (currentDir.exists()) {
289  fc.setCurrentDirectory(currentDir);
290  }
291 
292  int retval = fc.showOpenDialog(this);
293  if (retval == JFileChooser.APPROVE_OPTION) {
294  String path = fc.getSelectedFile().getPath();
295  pathNameTextField.setText(path);
296  }
297  //pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString(), false, true);
298 
299  updateSelectButton();
300  }//GEN-LAST:event_browseButtonActionPerformed
301  // Variables declaration - do not modify//GEN-BEGIN:variables
302  private javax.swing.JButton browseButton;
303  private javax.swing.JPanel buttonPanel;
304  private javax.swing.JButton cancelButton;
305  private javax.swing.JPanel containerPanel;
306  private javax.swing.JLabel lbWarning;
307  private javax.swing.JTextField pathNameTextField;
308  private javax.swing.JButton selectButton;
309  private javax.swing.JLabel titleLabel;
310  private javax.swing.JSeparator titleSeparator;
311  // End of variables declaration//GEN-END:variables
312 
316  void cancel() {
317  int ret = JOptionPane.showConfirmDialog(this,
318  NbBundle.getMessage(this.getClass(),
319  "MissingImageDialog.confDlg.noFileSel.msg"),
320  NbBundle.getMessage(this.getClass(),
321  "MissingImageDialog.confDlg.noFileSel.title"),
322  JOptionPane.YES_NO_OPTION);
323  if (ret == JOptionPane.YES_OPTION) {
324  this.dispose();
325  }
326  }
327 }

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