19 package org.sleuthkit.autopsy.livetriage;
 
   21 import java.util.ArrayList;
 
   22 import java.util.List;
 
   23 import java.util.concurrent.CancellationException;
 
   24 import java.util.logging.Level;
 
   25 import java.awt.Dimension;
 
   26 import java.awt.Point;
 
   27 import java.util.Collections;
 
   28 import javax.swing.SwingWorker;
 
   29 import javax.swing.event.ListSelectionEvent;
 
   30 import javax.swing.event.ListSelectionListener;
 
   31 import javax.swing.event.TableModelListener;
 
   32 import javax.swing.table.TableModel;
 
   33 import org.openide.util.NbBundle;
 
   41 @SuppressWarnings(
"PMD.SingularField") 
 
   42 class SelectDriveDialog extends javax.swing.JDialog {
 
   44     private List<LocalDisk> disks = 
new ArrayList<>();
 
   45     private final LocalDiskModel model = 
new LocalDiskModel();
 
   46     private final java.awt.Frame parent;
 
   47     private String drivePath = 
"";
 
   52     @NbBundle.Messages({
"SelectDriveDialog.title=Create Live Triage Drive"})
 
   53     SelectDriveDialog(java.awt.Frame parent, 
boolean modal) {
 
   59         bnOk.setEnabled(
false);
 
   60         diskTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
 
   62             public void valueChanged(ListSelectionEvent e) {
 
   63                 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
 
   64                     bnOk.setEnabled(
true);
 
   66                     bnOk.setEnabled(
false);
 
   73         this.setTitle(Bundle.SelectDriveDialog_title());
 
   75         final Dimension parentSize = parent.getSize();
 
   76         final Point parentLocationOnScreen = parent.getLocationOnScreen();
 
   77         final Dimension childSize = this.getSize();
 
   80         x = (parentSize.width - childSize.width) / 2;
 
   81         y = (parentSize.height - childSize.height) / 2;
 
   82         x += parentLocationOnScreen.x;
 
   83         y += parentLocationOnScreen.y;
 
   89     String getSelectedDrive() {
 
   90         return this.drivePath;
 
   98     @SuppressWarnings(
"unchecked")
 
  100     private 
void initComponents() {
 
  102         driveTableScrollPane = 
new javax.swing.JScrollPane();
 
  103         diskTable = 
new javax.swing.JTable();
 
  104         selectDriveLabel = 
new javax.swing.JLabel();
 
  105         bnRefresh = 
new javax.swing.JButton();
 
  106         bnOk = 
new javax.swing.JButton();
 
  107         errorLabel = 
new javax.swing.JLabel();
 
  108         jSeparator1 = 
new javax.swing.JSeparator();
 
  109         bnCancel = 
new javax.swing.JButton();
 
  110         descriptionScrollPane = 
new javax.swing.JScrollPane();
 
  111         descriptionTextArea = 
new javax.swing.JTextArea();
 
  113         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  115         diskTable.setModel(model);
 
  116         driveTableScrollPane.setViewportView(diskTable);
 
  118         org.openide.awt.Mnemonics.setLocalizedText(selectDriveLabel, 
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.selectDriveLabel.text")); 
 
  120         org.openide.awt.Mnemonics.setLocalizedText(bnRefresh, 
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.bnRefresh.text")); 
 
  121         bnRefresh.addActionListener(
new java.awt.event.ActionListener() {
 
  122             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  123                 bnRefreshActionPerformed(evt);
 
  127         org.openide.awt.Mnemonics.setLocalizedText(bnOk, 
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.bnOk.text")); 
 
  128         bnOk.addActionListener(
new java.awt.event.ActionListener() {
 
  129             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  130                 bnOkActionPerformed(evt);
 
  134         org.openide.awt.Mnemonics.setLocalizedText(errorLabel, 
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.errorLabel.text")); 
 
  136         org.openide.awt.Mnemonics.setLocalizedText(bnCancel, 
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.bnCancel.text")); 
 
  137         bnCancel.addActionListener(
new java.awt.event.ActionListener() {
 
  138             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  139                 bnCancelActionPerformed(evt);
 
  143         descriptionScrollPane.setBorder(null);
 
  145         descriptionTextArea.setBackground(
new java.awt.Color(240, 240, 240));
 
  146         descriptionTextArea.setColumns(20);
 
  147         descriptionTextArea.setRows(5);
 
  148         descriptionTextArea.setText(
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, 
"SelectDriveDialog.descriptionTextArea.text")); 
 
  149         descriptionTextArea.setBorder(null);
 
  150         descriptionScrollPane.setViewportView(descriptionTextArea);
 
  152         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  153         getContentPane().setLayout(layout);
 
  154         layout.setHorizontalGroup(
 
  155             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  156             .addGroup(layout.createSequentialGroup()
 
  158                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, 
false)
 
  159                     .addGroup(layout.createSequentialGroup()
 
  160                         .addComponent(bnRefresh, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
 
  161                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
 
  162                         .addComponent(bnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  163                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  164                         .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  165                     .addComponent(driveTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
 
  166                     .addComponent(selectDriveLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  167                     .addComponent(jSeparator1)
 
  168                     .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  169                     .addComponent(descriptionScrollPane))
 
  170                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  172         layout.setVerticalGroup(
 
  173             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  174             .addGroup(layout.createSequentialGroup()
 
  176                 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  177                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  178                 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  179                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  180                 .addComponent(selectDriveLabel)
 
  181                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  182                 .addComponent(driveTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  183                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  184                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  185                     .addComponent(bnRefresh)
 
  186                     .addComponent(bnCancel)
 
  188                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  189                 .addComponent(errorLabel)
 
  190                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  196     private void bnRefreshActionPerformed(java.awt.event.ActionEvent evt) {
 
  200     private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {
 
  201         if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
 
  202             LocalDisk selectedDisk = disks.get(diskTable.getSelectedRow());
 
  203             drivePath = selectedDisk.getPath();
 
  210     private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {
 
  216     private javax.swing.JButton bnCancel;
 
  217     private javax.swing.JButton bnOk;
 
  218     private javax.swing.JButton bnRefresh;
 
  219     private javax.swing.JScrollPane descriptionScrollPane;
 
  220     private javax.swing.JTextArea descriptionTextArea;
 
  221     private javax.swing.JTable diskTable;
 
  222     private javax.swing.JScrollPane driveTableScrollPane;
 
  223     private javax.swing.JLabel errorLabel;
 
  224     private javax.swing.JSeparator jSeparator1;
 
  225     private javax.swing.JLabel selectDriveLabel;
 
  231     @NbBundle.Messages({
"SelectDriveDialog.localDiskModel.loading.msg=",
 
  232         "SelectDriveDialog.localDiskModel.nodrives.msg=Executable could not be found",
 
  233         "SelectDriveDialog.diskTable.column1.title=Disk Name",
 
  234         "SelectDriveDialog.diskTable.column2.title=Disk Size",
 
  235         "SelectDriveDialog.errLabel.disksNotDetected.text=Disks were not detected. On some systems it requires admin privileges",
 
  236         "SelectDriveDialog.errLabel.disksNotDetected.toolTipText=Disks were not detected." 
  241         private LocalDiskThread worker = null;
 
  242         private boolean ready = 
false;
 
  243         private volatile boolean loadingDisks = 
false;
 
  246         private final String LOADING = NbBundle.getMessage(this.getClass(), 
"SelectDriveDialog.localDiskModel.loading.msg");
 
  247         private final String NO_DRIVES = NbBundle.getMessage(this.getClass(), 
"SelectDriveDialog.localDiskModel.nodrives.msg");
 
  252             if (loadingDisks && worker != null) {
 
  253                 worker.cancel(
false);
 
  257             errorLabel.setText(
"");
 
  258             diskTable.setEnabled(
false);
 
  261             worker = 
new LocalDiskThread();
 
  267             if (disks.isEmpty()) {
 
  281             switch (columnIndex) {
 
  283                     return NbBundle.getMessage(this.getClass(), 
"SelectDriveDialog.diskTable.column1.title");
 
  285                     return NbBundle.getMessage(this.getClass(), 
"SelectDriveDialog.diskTable.column2.title");
 
  304                 if (disks.isEmpty()) {
 
  307                 switch (columnIndex) {
 
  309                         return disks.get(rowIndex).getName();
 
  311                         return disks.get(rowIndex).getReadableSize();
 
  313                         return disks.get(rowIndex).getPath();
 
  321         public void setValueAt(Object aValue, 
int rowIndex, 
int columnIndex) {
 
  339         class LocalDiskThread 
extends SwingWorker<Object, Void> {
 
  342             private List<LocalDisk> partitions = 
new ArrayList<>();
 
  345             protected Object doInBackground() throws Exception {
 
  347                 partitions = 
new ArrayList<>();
 
  356             private void displayErrors() {
 
  357                 if (partitions.isEmpty()) {
 
  360                                 NbBundle.getMessage(
this.getClass(), 
"SelectDriveDialog.errLabel.disksNotDetected.text"));
 
  361                         errorLabel.setToolTipText(NbBundle.getMessage(
this.getClass(),
 
  362                                 "SelectDriveDialog.errLabel.disksNotDetected.toolTipText"));
 
  365                                 NbBundle.getMessage(
this.getClass(), 
"SelectDriveDialog.errLabel.drivesNotDetected.text"));
 
  366                         errorLabel.setToolTipText(NbBundle.getMessage(
this.getClass(),
 
  367                                 "SelectDriveDialog.errLabel.drivesNotDetected.toolTipText"));
 
  369                     errorLabel.setVisible(
true);
 
  370                     diskTable.setEnabled(
false);
 
  375             protected void done() {
 
  378                 } 
catch (CancellationException ex) {
 
  379                     logger.log(Level.INFO, 
"Loading local disks was canceled."); 
 
  380                 } 
catch (InterruptedException ex) {
 
  381                     logger.log(Level.INFO, 
"Loading local disks was interrupted."); 
 
  382                 } 
catch (Exception ex) {
 
  383                     logger.log(Level.SEVERE, 
"Fatal error when loading local disks", ex); 
 
  385                     if (!this.isCancelled()) {
 
  388                         loadingDisks = 
false;
 
  389                         disks = 
new ArrayList<>();
 
  390                         disks.addAll(partitions);
 
  392                         if (disks.size() > 0) {
 
  393                             diskTable.setEnabled(
true);
 
  394                             diskTable.clearSelection();
 
  396                             Collections.sort(disks, (LocalDisk disk1, LocalDisk disk2) -> disk1.getName().compareToIgnoreCase(disk2.getName()));
 
  402                 diskTable.revalidate();
 
void removeTableModelListener(TableModelListener l)
void addTableModelListener(TableModelListener l)
Class<?> getColumnClass(int columnIndex)
boolean isCellEditable(int rowIndex, int columnIndex)
String getColumnName(int columnIndex)
synchronized static Logger getLogger(String name)
Object getValueAt(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)