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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.