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 javax.swing.SwingWorker;
28 import javax.swing.event.ListSelectionEvent;
29 import javax.swing.event.ListSelectionListener;
30 import javax.swing.event.TableModelListener;
31 import javax.swing.table.TableModel;
32 import org.openide.util.NbBundle;
40 @SuppressWarnings(
"PMD.SingularField")
41 class SelectDriveDialog extends javax.swing.JDialog {
43 private List<LocalDisk> disks =
new ArrayList<>();
44 private final LocalDiskModel model =
new LocalDiskModel();
45 private final java.awt.Frame parent;
46 private String drivePath =
"";
51 @NbBundle.Messages({
"SelectDriveDialog.title=Create Live Triage Drive"})
52 SelectDriveDialog(java.awt.Frame parent,
boolean modal) {
58 bnOk.setEnabled(
false);
59 diskTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
61 public void valueChanged(ListSelectionEvent e) {
62 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
63 bnOk.setEnabled(
true);
65 bnOk.setEnabled(
false);
72 this.setTitle(Bundle.SelectDriveDialog_title());
74 final Dimension parentSize = parent.getSize();
75 final Point parentLocationOnScreen = parent.getLocationOnScreen();
76 final Dimension childSize = this.getSize();
79 x = (parentSize.width - childSize.width) / 2;
80 y = (parentSize.height - childSize.height) / 2;
81 x += parentLocationOnScreen.x;
82 y += parentLocationOnScreen.y;
88 String getSelectedDrive() {
89 return this.drivePath;
97 @SuppressWarnings(
"unchecked")
99 private
void initComponents() {
101 jScrollPane1 =
new javax.swing.JScrollPane();
102 diskTable =
new javax.swing.JTable();
103 jLabel1 =
new javax.swing.JLabel();
104 bnRefresh =
new javax.swing.JButton();
105 bnOk =
new javax.swing.JButton();
106 errorLabel =
new javax.swing.JLabel();
107 jSeparator1 =
new javax.swing.JSeparator();
108 bnCancel =
new javax.swing.JButton();
109 jScrollPane2 =
new javax.swing.JScrollPane();
110 jTextArea1 =
new javax.swing.JTextArea();
112 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
114 diskTable.setModel(model);
115 jScrollPane1.setViewportView(diskTable);
117 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.jLabel1.text"));
119 org.openide.awt.Mnemonics.setLocalizedText(bnRefresh,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnRefresh.text"));
120 bnRefresh.addActionListener(
new java.awt.event.ActionListener() {
121 public void actionPerformed(java.awt.event.ActionEvent evt) {
122 bnRefreshActionPerformed(evt);
126 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnOk.text"));
127 bnOk.addActionListener(
new java.awt.event.ActionListener() {
128 public void actionPerformed(java.awt.event.ActionEvent evt) {
129 bnOkActionPerformed(evt);
133 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.errorLabel.text"));
135 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnCancel.text"));
136 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
138 bnCancelActionPerformed(evt);
142 jScrollPane2.setBorder(null);
144 jTextArea1.setBackground(
new java.awt.Color(240, 240, 240));
145 jTextArea1.setColumns(20);
146 jTextArea1.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
147 jTextArea1.setRows(5);
148 jTextArea1.setText(
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.jTextArea1.text"));
149 jTextArea1.setBorder(null);
150 jScrollPane2.setViewportView(jTextArea1);
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(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
166 .addComponent(jLabel1, 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(jScrollPane2))
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(jScrollPane2, 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(jLabel1)
181 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
182 .addComponent(jScrollPane1, 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.JTable diskTable;
220 private javax.swing.JLabel errorLabel;
221 private javax.swing.JLabel jLabel1;
222 private javax.swing.JScrollPane jScrollPane1;
223 private javax.swing.JScrollPane jScrollPane2;
224 private javax.swing.JSeparator jSeparator1;
225 private javax.swing.JTextArea jTextArea1;
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);
391 if (disks.size() > 0) {
392 diskTable.setEnabled(
true);
393 diskTable.clearSelection();
398 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)