Autopsy  4.13.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  selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
136  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.selectButton.text")); // NOI18N
137  selectButton.addActionListener(new java.awt.event.ActionListener() {
138  public void actionPerformed(java.awt.event.ActionEvent evt) {
139  selectButtonActionPerformed(evt);
140  }
141  });
142 
143  cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
144  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.cancelButton.text")); // NOI18N
145  cancelButton.addActionListener(new java.awt.event.ActionListener() {
146  public void actionPerformed(java.awt.event.ActionEvent evt) {
147  cancelButtonActionPerformed(evt);
148  }
149  });
150 
151  javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
152  buttonPanel.setLayout(buttonPanelLayout);
153  buttonPanelLayout.setHorizontalGroup(
154  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
156  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
157  .addComponent(selectButton)
158  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
159  .addComponent(cancelButton)
160  .addContainerGap())
161  );
162  buttonPanelLayout.setVerticalGroup(
163  buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164  .addGroup(buttonPanelLayout.createSequentialGroup()
165  .addContainerGap()
166  .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167  .addComponent(selectButton)
168  .addComponent(cancelButton))
169  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170  );
171 
172  pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
173  pathNameTextField.setText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.pathNameTextField.text")); // NOI18N
174  pathNameTextField.addActionListener(new java.awt.event.ActionListener() {
175  public void actionPerformed(java.awt.event.ActionEvent evt) {
176  pathNameTextFieldActionPerformed(evt);
177  }
178  });
179 
180  browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
181  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.browseButton.text")); // NOI18N
182  browseButton.addActionListener(new java.awt.event.ActionListener() {
183  public void actionPerformed(java.awt.event.ActionEvent evt) {
184  browseButtonActionPerformed(evt);
185  }
186  });
187 
188  lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
189  lbWarning.setForeground(new java.awt.Color(244, 0, 0));
190  org.openide.awt.Mnemonics.setLocalizedText(lbWarning, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.text")); // NOI18N
191  lbWarning.setToolTipText(org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.lbWarning.toolTipText")); // NOI18N
192 
193  javax.swing.GroupLayout containerPanelLayout = new javax.swing.GroupLayout(containerPanel);
194  containerPanel.setLayout(containerPanelLayout);
195  containerPanelLayout.setHorizontalGroup(
196  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197  .addGroup(containerPanelLayout.createSequentialGroup()
198  .addContainerGap()
199  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
201  .addGroup(containerPanelLayout.createSequentialGroup()
202  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
203  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204  .addComponent(browseButton)
205  .addContainerGap(83, Short.MAX_VALUE))))
206  );
207  containerPanelLayout.setVerticalGroup(
208  containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209  .addGroup(containerPanelLayout.createSequentialGroup()
210  .addGap(18, 18, 18)
211  .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
212  .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213  .addComponent(browseButton))
214  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215  .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
216  .addGap(18, 18, 18))
217  );
218 
219  titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
220  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(MissingImageDialog.class, "MissingImageDialog.titleLabel.text")); // NOI18N
221 
222  titleSeparator.setForeground(new java.awt.Color(102, 102, 102));
223 
224  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
225  getContentPane().setLayout(layout);
226  layout.setHorizontalGroup(
227  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
229  .addGroup(layout.createSequentialGroup()
230  .addContainerGap()
231  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232  .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
233  .addGroup(layout.createSequentialGroup()
234  .addComponent(titleLabel)
235  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
236  .addComponent(titleSeparator)))
237  .addContainerGap())
238  );
239  layout.setVerticalGroup(
240  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
241  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
242  .addContainerGap()
243  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
244  .addComponent(titleLabel)
245  .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
246  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
247  .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
248  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
249  .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
250  );
251 
252  pack();
253  }// </editor-fold>//GEN-END:initComponents
254 
255  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
256  try {
257  String newPath = pathNameTextField.getText();
258  //TODO handle local files
259  db.setImagePaths(obj_id, Arrays.asList(new String[]{newPath}));
260  this.dispose();
261  } catch (TskCoreException ex) {
262  lbWarning.setText(NbBundle.getMessage(this.getClass(), "MissingImageDialog.ErrorSettingImage"));
263  logger.log(Level.SEVERE, "Error setting image paths", ex); //NON-NLS
264  }
265  }//GEN-LAST:event_selectButtonActionPerformed
266 
267  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
268  cancel();
269  }//GEN-LAST:event_cancelButtonActionPerformed
270 
271  private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathNameTextFieldActionPerformed
272  updateSelectButton();
273  }//GEN-LAST:event_pathNameTextFieldActionPerformed
274 
275  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
276 
277  String oldText = pathNameTextField.getText();
278  lbWarning.setText("");
279  // set the current directory of the FileChooser if the ImagePath Field is valid
280  File currentDir = new File(oldText);
281  if (currentDir.exists()) {
282  fileChooser.setCurrentDirectory(currentDir);
283  }
284 
285  int retval = fileChooser.showOpenDialog(this);
286  if (retval == JFileChooser.APPROVE_OPTION) {
287  String path = fileChooser.getSelectedFile().getPath();
288  pathNameTextField.setText(path);
289  }
290  //pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString(), false, true);
291 
292  updateSelectButton();
293  }//GEN-LAST:event_browseButtonActionPerformed
294  // Variables declaration - do not modify//GEN-BEGIN:variables
295  private javax.swing.JButton browseButton;
296  private javax.swing.JPanel buttonPanel;
297  private javax.swing.JButton cancelButton;
298  private javax.swing.JPanel containerPanel;
299  private javax.swing.JLabel lbWarning;
300  private javax.swing.JTextField pathNameTextField;
301  private javax.swing.JButton selectButton;
302  private javax.swing.JLabel titleLabel;
303  private javax.swing.JSeparator titleSeparator;
304  // End of variables declaration//GEN-END:variables
305 
309  void cancel() {
310  int ret = JOptionPane.showConfirmDialog(this,
311  NbBundle.getMessage(this.getClass(),
312  "MissingImageDialog.confDlg.noFileSel.msg"),
313  NbBundle.getMessage(this.getClass(),
314  "MissingImageDialog.confDlg.noFileSel.title"),
315  JOptionPane.YES_NO_OPTION);
316  if (ret == JOptionPane.YES_OPTION) {
317  this.dispose();
318  }
319  }
320 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.