Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LogicalImagerPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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.logicalimager.dsp;
20 
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.io.File;
24 import java.io.FilenameFilter;
25 import java.io.IOException;
26 import java.nio.file.FileStore;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.logging.Level;
33 import java.util.regex.Matcher;
34 import java.util.regex.Pattern;
35 import javax.swing.JFileChooser;
36 import javax.swing.JPanel;
37 import javax.swing.JTable;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.event.DocumentEvent;
40 import javax.swing.event.DocumentListener;
41 import javax.swing.filechooser.FileSystemView;
42 import javax.swing.table.DefaultTableModel;
43 import javax.swing.table.TableColumn;
44 import org.openide.util.NbBundle.Messages;
47 
52 @Messages({
53  "LogicalImagerPanel.messageLabel.noImageSelected=No image selected",
54  "LogicalImagerPanel.messageLabel.driveHasNoImages=Drive has no images",
55  "LogicalImagerPanel.selectAcquisitionFromDriveLabel.text=Select acquisition from Drive",})
56 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
57 final class LogicalImagerPanel extends JPanel implements DocumentListener {
58 
59  private static final Logger logger = Logger.getLogger(LogicalImagerPanel.class.getName());
60  private static final long serialVersionUID = 1L;
61  private static final String NO_IMAGE_SELECTED = Bundle.LogicalImagerPanel_messageLabel_noImageSelected();
62  private static final String DRIVE_HAS_NO_IMAGES = Bundle.LogicalImagerPanel_messageLabel_driveHasNoImages();
63  private static final int COLUMN_TO_SORT_ON_INDEX = 1;
64  private static final int NUMBER_OF_VISIBLE_COLUMNS = 2;
65  private static final String[] EMPTY_LIST_DATA = {};
66 
67  private final JFileChooser fileChooser = new JFileChooser();
68  private final Pattern regex = Pattern.compile("Logical_Imager_(.+)_(\\d{4})(\\d{2})(\\d{2})_(\\d{2})_(\\d{2})_(\\d{2})");
69  private Path manualImageDirPath;
70  private DefaultTableModel imageTableModel;
71 
78  private LogicalImagerPanel(String context) {
79  initComponents();
80  configureImageTable();
81  jScrollPane1.setBorder(null);
82  clearImageTable();
83  }
84 
89  private void configureImageTable() {
90  //hide path column while leaving it in model
91  if (imageTable.getColumnCount() > NUMBER_OF_VISIBLE_COLUMNS) {
92  TableColumn columnToHide = imageTable.getColumn(imageTableModel.getColumnName(NUMBER_OF_VISIBLE_COLUMNS));
93  if (columnToHide != null) {
94  imageTable.removeColumn(columnToHide);
95  }
96  //sort on specified column in decending order, the first call will toggle to ascending order, the second to descending order
97  imageTable.getRowSorter().toggleSortOrder(COLUMN_TO_SORT_ON_INDEX);
98  imageTable.getRowSorter().toggleSortOrder(COLUMN_TO_SORT_ON_INDEX);
99  }
100  }
101 
110  static synchronized LogicalImagerPanel createInstance(String context) {
111  LogicalImagerPanel instance = new LogicalImagerPanel(context);
112  // post-constructor initialization of listener support without leaking references of uninitialized objects
113  instance.imageTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
114  return instance;
115  }
116 
122  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123  private void initComponents() {
124 
125  buttonGroup1 = new javax.swing.ButtonGroup();
126  browseButton = new javax.swing.JButton();
127  importRadioButton = new javax.swing.JRadioButton();
128  manualRadioButton = new javax.swing.JRadioButton();
129  pathTextField = new javax.swing.JTextField();
130  selectFolderLabel = new javax.swing.JLabel();
131  selectDriveLabel = new javax.swing.JLabel();
132  selectFromDriveLabel = new javax.swing.JLabel();
133  driveListScrollPane = new javax.swing.JScrollPane();
134  driveList = new javax.swing.JList<>();
135  refreshButton = new javax.swing.JButton();
136  imageScrollPane = new javax.swing.JScrollPane();
137  imageTable = new javax.swing.JTable();
138  jSeparator2 = new javax.swing.JSeparator();
139  jScrollPane1 = new javax.swing.JScrollPane();
140  messageTextArea = new javax.swing.JTextArea();
141 
142  setMinimumSize(new java.awt.Dimension(0, 65));
143  setPreferredSize(new java.awt.Dimension(403, 65));
144 
145  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.browseButton.text")); // NOI18N
146  browseButton.setEnabled(false);
147  browseButton.addActionListener(new java.awt.event.ActionListener() {
148  public void actionPerformed(java.awt.event.ActionEvent evt) {
149  browseButtonActionPerformed(evt);
150  }
151  });
152 
153  buttonGroup1.add(importRadioButton);
154  importRadioButton.setSelected(true);
155  org.openide.awt.Mnemonics.setLocalizedText(importRadioButton, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.importRadioButton.text")); // NOI18N
156  importRadioButton.setToolTipText("");
157  importRadioButton.addActionListener(new java.awt.event.ActionListener() {
158  public void actionPerformed(java.awt.event.ActionEvent evt) {
159  importRadioButtonActionPerformed(evt);
160  }
161  });
162 
163  buttonGroup1.add(manualRadioButton);
164  org.openide.awt.Mnemonics.setLocalizedText(manualRadioButton, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.manualRadioButton.text")); // NOI18N
165  manualRadioButton.addActionListener(new java.awt.event.ActionListener() {
166  public void actionPerformed(java.awt.event.ActionEvent evt) {
167  manualRadioButtonActionPerformed(evt);
168  }
169  });
170 
171  pathTextField.setDisabledTextColor(java.awt.Color.black);
172  pathTextField.setEnabled(false);
173 
174  org.openide.awt.Mnemonics.setLocalizedText(selectFolderLabel, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.selectFolderLabel.text")); // NOI18N
175 
176  org.openide.awt.Mnemonics.setLocalizedText(selectDriveLabel, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.selectDriveLabel.text")); // NOI18N
177 
178  org.openide.awt.Mnemonics.setLocalizedText(selectFromDriveLabel, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.selectFromDriveLabel.text")); // NOI18N
179 
180  driveList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
181  driveList.addMouseListener(new java.awt.event.MouseAdapter() {
182  public void mouseReleased(java.awt.event.MouseEvent evt) {
183  driveListMouseReleased(evt);
184  }
185  });
186  driveList.addKeyListener(new java.awt.event.KeyAdapter() {
187  public void keyReleased(java.awt.event.KeyEvent evt) {
188  driveListKeyReleased(evt);
189  }
190  });
191  driveListScrollPane.setViewportView(driveList);
192 
193  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(LogicalImagerPanel.class, "LogicalImagerPanel.refreshButton.text")); // NOI18N
194  refreshButton.addActionListener(new java.awt.event.ActionListener() {
195  public void actionPerformed(java.awt.event.ActionEvent evt) {
196  refreshButtonActionPerformed(evt);
197  }
198  });
199 
200  imageScrollPane.setPreferredSize(new java.awt.Dimension(346, 402));
201 
202  imageTable.setAutoCreateRowSorter(true);
203  imageTable.setModel(new javax.swing.table.DefaultTableModel(
204  new Object [][] {
205 
206  },
207  new String [] {
208 
209  }
210  ));
211  imageTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
212  imageTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
213  imageTable.setShowHorizontalLines(false);
214  imageTable.setShowVerticalLines(false);
215  imageTable.getTableHeader().setReorderingAllowed(false);
216  imageTable.addMouseListener(new java.awt.event.MouseAdapter() {
217  public void mouseReleased(java.awt.event.MouseEvent evt) {
218  imageTableMouseReleased(evt);
219  }
220  });
221  imageTable.addKeyListener(new java.awt.event.KeyAdapter() {
222  public void keyReleased(java.awt.event.KeyEvent evt) {
223  imageTableKeyReleased(evt);
224  }
225  });
226  imageScrollPane.setViewportView(imageTable);
227  imageTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
228 
229  jScrollPane1.setBorder(null);
230 
231  messageTextArea.setBackground(new java.awt.Color(240, 240, 240));
232  messageTextArea.setColumns(20);
233  messageTextArea.setForeground(java.awt.Color.red);
234  messageTextArea.setLineWrap(true);
235  messageTextArea.setRows(3);
236  messageTextArea.setBorder(null);
237  messageTextArea.setDisabledTextColor(java.awt.Color.red);
238  messageTextArea.setEnabled(false);
239  messageTextArea.setMargin(new java.awt.Insets(0, 0, 0, 0));
240  jScrollPane1.setViewportView(messageTextArea);
241 
242  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
243  this.setLayout(layout);
244  layout.setHorizontalGroup(
245  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246  .addGroup(layout.createSequentialGroup()
247  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248  .addGroup(layout.createSequentialGroup()
249  .addGap(10, 10, 10)
250  .addComponent(selectFolderLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
251  .addGap(13, 13, 13)
252  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 474, javax.swing.GroupLayout.PREFERRED_SIZE))
253  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
254  .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)
255  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256  .addGroup(layout.createSequentialGroup()
257  .addGap(41, 41, 41)
258  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addComponent(driveListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
260  .addComponent(refreshButton))
261  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
262  .addComponent(imageScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE))
263  .addGroup(layout.createSequentialGroup()
264  .addGap(20, 20, 20)
265  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266  .addGroup(layout.createSequentialGroup()
267  .addComponent(manualRadioButton)
268  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
269  .addComponent(browseButton))
270  .addComponent(importRadioButton)
271  .addGroup(layout.createSequentialGroup()
272  .addGap(21, 21, 21)
273  .addComponent(selectDriveLabel)
274  .addGap(113, 113, 113)
275  .addComponent(selectFromDriveLabel))))))
276  .addGroup(layout.createSequentialGroup()
277  .addContainerGap()
278  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 568, javax.swing.GroupLayout.PREFERRED_SIZE)))
279  .addContainerGap(93, Short.MAX_VALUE))
280  );
281  layout.setVerticalGroup(
282  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283  .addGroup(layout.createSequentialGroup()
284  .addGap(16, 16, 16)
285  .addComponent(importRadioButton)
286  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
287  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
288  .addComponent(selectDriveLabel)
289  .addComponent(selectFromDriveLabel))
290  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
291  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292  .addComponent(imageScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
293  .addComponent(driveListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE))
294  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
295  .addComponent(refreshButton)
296  .addGap(18, 18, 18)
297  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
298  .addComponent(browseButton)
299  .addComponent(manualRadioButton))
300  .addGap(18, 18, 18)
301  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
302  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
303  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
304  .addComponent(selectFolderLabel)
305  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
306  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
308  .addGap(6, 6, 6))
309  );
310  }// </editor-fold>//GEN-END:initComponents
311 
312  @Messages({
313  "# {0} - sparseImageDirectory",
314  "LogicalImagerPanel.messageLabel.directoryDoesNotContainSparseImage=Directory {0} does not contain any images",
315  "# {0} - invalidFormatDirectory",
316  "LogicalImagerPanel.messageLabel.directoryFormatInvalid=Directory {0} does not match format Logical_Imager_HOSTNAME_yyyymmdd_HH_MM_SS"
317  })
318  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
319  imageTable.clearSelection();
320  manualImageDirPath = null;
321  setErrorMessage(NO_IMAGE_SELECTED);
322  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
323  int retval = fileChooser.showOpenDialog(this);
324  if (retval == JFileChooser.APPROVE_OPTION) {
325  String path = fileChooser.getSelectedFile().getPath();
326  Matcher m = regex.matcher(path);
327  if (m.find()) {
328  File dir = Paths.get(path).toFile();
329  String[] vhdFiles = dir.list(new FilenameFilter() {
330  @Override
331  public boolean accept(File dir, String name) {
332  return name.endsWith(".vhd");
333  }
334  });
335  if (vhdFiles.length == 0) {
336  // No VHD files, try directories for individual files
337  String[] directories = dir.list(new FilenameFilter() {
338  @Override
339  public boolean accept(File dir, String name) {
340  return Paths.get(dir.toString(), name).toFile().isDirectory();
341  }
342  });
343  if (directories.length == 0) {
344  // No directories, bail
345  setErrorMessage(Bundle.LogicalImagerPanel_messageLabel_directoryDoesNotContainSparseImage(path));
346  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
347  return;
348  }
349  }
350  manualImageDirPath = Paths.get(path);
351  setNormalMessage(path);
352  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
353  } else {
354  setErrorMessage(Bundle.LogicalImagerPanel_messageLabel_directoryFormatInvalid(path));
355  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
356  }
357  } else {
358  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
359  }
360  }//GEN-LAST:event_browseButtonActionPerformed
361 
362  private void imageTableSelect() {
363  int index = imageTable.getSelectedRow();
364  if (index != -1) {
365  setNormalMessage((String) imageTableModel.getValueAt(imageTable.convertRowIndexToModel(index), 2));
366  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
367  } else {
368  setErrorMessage(NO_IMAGE_SELECTED);
369  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
370  }
371  }
372 
373  private boolean dirHasImagerResult(File dir) {
374  String[] fList = dir.list(new FilenameFilter() {
375  @Override
376  public boolean accept(File dir, String name) {
377  return name.endsWith(".vhd") || Paths.get(dir.toString(), name).toFile().isDirectory();
378  }
379  });
380  return (fList != null && fList.length != 0);
381  }
382 
383  private void driveListSelect() {
384  String selectedStr = driveList.getSelectedValue();
385  if (selectedStr == null) {
386  return;
387  }
388  String driveLetter = selectedStr.substring(0, 3);
389  File directory = new File(driveLetter);
390  File[] fList = directory.listFiles();
391 
392  if (fList != null) {
393  imageTableModel = new ImageTableModel();
394  // Find all directories with name like Logical_Imager_HOSTNAME_yyyymmdd_HH_MM_SS
395  // and has Logical Imager result in it
396  for (File file : fList) {
397  if (file.isDirectory() && dirHasImagerResult(file)) {
398  String dir = file.getName();
399  Matcher m = regex.matcher(dir);
400  if (m.find()) {
401  String imageDirPath = driveLetter + dir;
402  String hostname = m.group(1);
403  String year = m.group(2);
404  String month = m.group(3);
405  String day = m.group(4);
406  String hour = m.group(5);
407  String minute = m.group(6);
408  String second = m.group(7);
409  String extractDate = year + "/" + month + "/" + day
410  + " " + hour + ":" + minute + ":" + second;
411  imageTableModel.addRow(new Object[]{hostname, extractDate, imageDirPath});
412  }
413  }
414  }
415  selectFromDriveLabel.setText(Bundle.LogicalImagerPanel_selectAcquisitionFromDriveLabel_text()
416  + " " + driveLetter);
417  imageTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
418  imageTable.setModel(imageTableModel);
419  configureImageTable();
420  fixImageTableColumnWidth();
421  // If there are any images, select the first one
422  if (imageTable.getRowCount() > 0) {
423  imageTable.setRowSelectionInterval(0, 0);
424  imageTableSelect();
425  } else {
426  setErrorMessage(DRIVE_HAS_NO_IMAGES);
427  }
428  } else {
429  clearImageTable();
430  setErrorMessage(DRIVE_HAS_NO_IMAGES);
431  }
432  }
433 
434  private void fixImageTableColumnWidth() {
435  int width = imageScrollPane.getPreferredSize().width - 2;
436  imageTable.getColumnModel().getColumn(0).setPreferredWidth((int) (.60 * width));
437  imageTable.getColumnModel().getColumn(1).setPreferredWidth((int) (.40 * width));
438  }
439 
440  private void setErrorMessage(String msg) {
441  messageTextArea.setForeground(Color.red);
442  messageTextArea.setText(msg);
443  pathTextField.setText("");
444  }
445 
446  private void setNormalMessage(String msg) {
447  pathTextField.setText(msg);
448  messageTextArea.setText("");
449  }
450 
451  private void clearImageTable() {
452  imageTableModel = new ImageTableModel();
453  imageTable.setModel(imageTableModel);
454  configureImageTable();
455  fixImageTableColumnWidth();
456  }
457 
458  private void toggleMouseAndKeyListeners(Component component, boolean isEnable) {
459  component.setEnabled(isEnable);
460  }
461 
462  private void manualRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manualRadioButtonActionPerformed
463  browseButton.setEnabled(true);
464 
465  // disable import panel
466  toggleMouseAndKeyListeners(driveList, false);
467  toggleMouseAndKeyListeners(driveListScrollPane, false);
468  toggleMouseAndKeyListeners(imageScrollPane, false);
469  toggleMouseAndKeyListeners(imageTable, false);
470 
471  refreshButton.setEnabled(false);
472 
473  manualImageDirPath = null;
474  setNormalMessage("");
475  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
476  }//GEN-LAST:event_manualRadioButtonActionPerformed
477 
478  private void importRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importRadioButtonActionPerformed
479  browseButton.setEnabled(false);
480 
481  toggleMouseAndKeyListeners(driveList, true);
482  toggleMouseAndKeyListeners(driveListScrollPane, true);
483  toggleMouseAndKeyListeners(imageScrollPane, true);
484  toggleMouseAndKeyListeners(imageTable, true);
485 
486  refreshButton.setEnabled(true);
487 
488  manualImageDirPath = null;
489  setNormalMessage("");
490  refreshButton.doClick();
491  }//GEN-LAST:event_importRadioButtonActionPerformed
492 
493  @Messages({
494  "LogicalImagerPanel.messageLabel.scanningExternalDrives=Scanning external drives for images ...",
495  "LogicalImagerPanel.messageLabel.noExternalDriveFound=No drive found"
496  })
497  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
498  // Scan external drives for vhd images
499  clearImageTable();
500  setNormalMessage(Bundle.LogicalImagerPanel_messageLabel_scanningExternalDrives());
501  List<String> listData = new ArrayList<>();
502  File[] roots = File.listRoots();
503  int firstRemovableDrive = -1;
504  int i = 0;
505  for (File root : roots) {
506  if (DriveListUtils.isNetworkDrive(root.toString().replace(":\\", ""))) {
507  continue;
508  }
509  String description = FileSystemView.getFileSystemView().getSystemTypeDescription(root);
510  long spaceInBytes = root.getTotalSpace();
511  String sizeWithUnit = DriveListUtils.humanReadableByteCount(spaceInBytes, false);
512  listData.add(root + " (" + description + ") (" + sizeWithUnit + ")");
513  if (firstRemovableDrive == -1) {
514  try {
515  FileStore fileStore = Files.getFileStore(root.toPath());
516  if ((boolean) fileStore.getAttribute("volume:isRemovable")) { //NON-NLS
517  firstRemovableDrive = i;
518  }
519  } catch (IOException ignored) {
520  //unable to get this removable drive for default selection will try and select next removable drive by default
521  logger.log(Level.INFO, String.format("Unable to select first removable drive found: %s", ignored.getMessage()));
522  }
523  }
524  i++;
525  }
526  driveList.setListData(listData.toArray(new String[listData.size()]));
527  if (!listData.isEmpty()) {
528  // auto-select the first external drive, if any
529  driveList.setSelectedIndex(firstRemovableDrive == -1 ? 0 : firstRemovableDrive);
530  driveListMouseReleased(null);
531  driveList.requestFocusInWindow();
532  } else {
533  setErrorMessage(Bundle.LogicalImagerPanel_messageLabel_noExternalDriveFound());
534  }
535  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
536  }//GEN-LAST:event_refreshButtonActionPerformed
537 
538  private void driveListKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_driveListKeyReleased
539  if (importRadioButton.isSelected()) {
540  driveListSelect();
541  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
542  }
543  }//GEN-LAST:event_driveListKeyReleased
544 
545  private void imageTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_imageTableKeyReleased
546  if (importRadioButton.isSelected()) {
547  imageTableSelect();
548  }
549  }//GEN-LAST:event_imageTableKeyReleased
550 
551  private void imageTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imageTableMouseReleased
552  if (importRadioButton.isSelected()) {
553  imageTableSelect();
554  }
555  }//GEN-LAST:event_imageTableMouseReleased
556 
557  private void driveListMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_driveListMouseReleased
558  if (importRadioButton.isSelected()) {
559  driveListSelect();
560  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), true, false);
561  }
562  }//GEN-LAST:event_driveListMouseReleased
563 
564 
565  // Variables declaration - do not modify//GEN-BEGIN:variables
566  private javax.swing.JButton browseButton;
567  private javax.swing.ButtonGroup buttonGroup1;
568  private javax.swing.JList<String> driveList;
569  private javax.swing.JScrollPane driveListScrollPane;
570  private javax.swing.JScrollPane imageScrollPane;
571  private javax.swing.JTable imageTable;
572  private javax.swing.JRadioButton importRadioButton;
573  private javax.swing.JScrollPane jScrollPane1;
574  private javax.swing.JSeparator jSeparator2;
575  private javax.swing.JRadioButton manualRadioButton;
576  private javax.swing.JTextArea messageTextArea;
577  private javax.swing.JTextField pathTextField;
578  private javax.swing.JButton refreshButton;
579  private javax.swing.JLabel selectDriveLabel;
580  private javax.swing.JLabel selectFolderLabel;
581  private javax.swing.JLabel selectFromDriveLabel;
582  // End of variables declaration//GEN-END:variables
583 
584  void reset() {
585  //reset the UI elements to default
586  manualImageDirPath = null;
587  setNormalMessage("");
588  driveList.setListData(EMPTY_LIST_DATA);
589  clearImageTable();
590  if (importRadioButton.isSelected()) {
591  refreshButton.doClick();
592  }
593  }
594 
600  boolean validatePanel() {
601  if (manualRadioButton.isSelected()) {
602  return manualImageDirPath != null && manualImageDirPath.toFile().exists();
603  } else if (imageTable.getSelectedRow() != -1) {
604  Path path = Paths.get((String) imageTableModel.getValueAt(imageTable.convertRowIndexToModel(imageTable.getSelectedRow()), 2));
605  return path != null && path.toFile().exists();
606  } else {
607  return false;
608  }
609  }
610 
611  Path getImageDirPath() {
612  if (manualRadioButton.isSelected()) {
613  return manualImageDirPath;
614  } else if (imageTable.getSelectedRow() != -1) {
615  return Paths.get((String) imageTableModel.getValueAt(imageTable.convertRowIndexToModel(imageTable.getSelectedRow()), 2));
616  } else {
617  return null;
618  }
619  }
620 
621  @Override
622  public void insertUpdate(DocumentEvent e) {
623  }
624 
625  @Override
626  public void removeUpdate(DocumentEvent e) {
627  }
628 
629  @Override
630  public void changedUpdate(DocumentEvent e) {
631  }
632 
633  void storeSettings() {
634  }
635 
639  private class ImageTableModel extends DefaultTableModel {
640 
641  private static final long serialVersionUID = 1L;
642 
643  @Override
644  public int getColumnCount() {
645  return 3;
646  }
647 
648  @Messages({
649  "LogicalImagerPanel.imageTable.columnModel.title0=Hostname",
650  "LogicalImagerPanel.imageTable.columnModel.title1=Extracted Date (GMT)",
651  "LogicalImagerPanel.imageTable.columnModel.title2=Path"
652  })
653  @Override
654  public String getColumnName(int column) {
655  String colName = null;
656  switch (column) {
657  case 0:
658  colName = Bundle.LogicalImagerPanel_imageTable_columnModel_title0();
659  break;
660  case 1:
661  colName = Bundle.LogicalImagerPanel_imageTable_columnModel_title1();
662  break;
663  case 2:
664  colName = Bundle.LogicalImagerPanel_imageTable_columnModel_title2();
665  break;
666  default:
667  break;
668  }
669  return colName;
670  }
671 
672  @Override
673  public boolean isCellEditable(int rowIndex, int columnIndex) {
674  return false;
675  }
676  }
677 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.