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

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