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

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