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

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