Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SelectDriveDialog.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 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 */
19package org.sleuthkit.autopsy.livetriage;
20
21import java.util.ArrayList;
22import java.util.List;
23import java.util.concurrent.CancellationException;
24import java.util.logging.Level;
25import java.awt.Dimension;
26import java.awt.Point;
27import java.util.Collections;
28import javax.swing.SwingWorker;
29import javax.swing.event.ListSelectionEvent;
30import javax.swing.event.ListSelectionListener;
31import javax.swing.event.TableModelListener;
32import javax.swing.table.TableModel;
33import org.openide.util.NbBundle;
34import org.sleuthkit.autopsy.coreutils.LocalDisk;
35import org.sleuthkit.autopsy.coreutils.Logger;
36import org.sleuthkit.autopsy.coreutils.PlatformUtil;
37
41@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42class SelectDriveDialog extends javax.swing.JDialog {
43
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 = "";
48
52 @NbBundle.Messages({"SelectDriveDialog.title=Create Live Triage Drive"})
53 SelectDriveDialog(java.awt.Frame parent, boolean modal) {
54 super(parent, modal);
55 initComponents();
56 this.parent = parent;
57
58 model.loadDisks();
59 bnOk.setEnabled(false);
60 diskTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
61 @Override
62 public void valueChanged(ListSelectionEvent e) {
63 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
64 bnOk.setEnabled(true);
65 } else { //The selection changed to nothing valid being selected, such as with ctrl+click
66 bnOk.setEnabled(false);
67 }
68 }
69 });
70 }
71
72 void display() {
73 this.setTitle(Bundle.SelectDriveDialog_title());
74
75 final Dimension parentSize = parent.getSize();
76 final Point parentLocationOnScreen = parent.getLocationOnScreen();
77 final Dimension childSize = this.getSize();
78 int x;
79 int y;
80 x = (parentSize.width - childSize.width) / 2;
81 y = (parentSize.height - childSize.height) / 2;
82 x += parentLocationOnScreen.x;
83 y += parentLocationOnScreen.y;
84
85 setLocation(x, y);
86 setVisible(true);
87 }
88
89 String getSelectedDrive() {
90 return this.drivePath;
91 }
92
98 @SuppressWarnings("unchecked")
99 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
100 private void initComponents() {
101
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();
112
113 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
114
115 diskTable.setModel(model);
116 driveTableScrollPane.setViewportView(diskTable);
117
118 org.openide.awt.Mnemonics.setLocalizedText(selectDriveLabel, org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, "SelectDriveDialog.selectDriveLabel.text")); // NOI18N
119
120 org.openide.awt.Mnemonics.setLocalizedText(bnRefresh, org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, "SelectDriveDialog.bnRefresh.text")); // NOI18N
121 bnRefresh.addActionListener(new java.awt.event.ActionListener() {
122 public void actionPerformed(java.awt.event.ActionEvent evt) {
123 bnRefreshActionPerformed(evt);
124 }
125 });
126
127 org.openide.awt.Mnemonics.setLocalizedText(bnOk, org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, "SelectDriveDialog.bnOk.text")); // NOI18N
128 bnOk.addActionListener(new java.awt.event.ActionListener() {
129 public void actionPerformed(java.awt.event.ActionEvent evt) {
130 bnOkActionPerformed(evt);
131 }
132 });
133
134 org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, "SelectDriveDialog.errorLabel.text")); // NOI18N
135
136 org.openide.awt.Mnemonics.setLocalizedText(bnCancel, org.openide.util.NbBundle.getMessage(SelectDriveDialog.class, "SelectDriveDialog.bnCancel.text")); // NOI18N
137 bnCancel.addActionListener(new java.awt.event.ActionListener() {
138 public void actionPerformed(java.awt.event.ActionEvent evt) {
139 bnCancelActionPerformed(evt);
140 }
141 });
142
143 descriptionScrollPane.setBorder(null);
144
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")); // NOI18N
149 descriptionTextArea.setBorder(null);
150 descriptionScrollPane.setViewportView(descriptionTextArea);
151
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()
157 .addContainerGap()
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))
171 );
172 layout.setVerticalGroup(
173 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
174 .addGroup(layout.createSequentialGroup()
175 .addContainerGap()
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)
187 .addComponent(bnOk))
188 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189 .addComponent(errorLabel)
190 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
191 );
192
193 pack();
194 }// </editor-fold>//GEN-END:initComponents
195
196 private void bnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnRefreshActionPerformed
197 model.loadDisks();
198 }//GEN-LAST:event_bnRefreshActionPerformed
199
200 private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed
201 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
202 LocalDisk selectedDisk = disks.get(diskTable.getSelectedRow());
203 drivePath = selectedDisk.getPath();
204 } else {
205 drivePath = "";
206 }
207 dispose();
208 }//GEN-LAST:event_bnOkActionPerformed
209
210 private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnCancelActionPerformed
211 dispose();
212 }//GEN-LAST:event_bnCancelActionPerformed
213
214
215 // Variables declaration - do not modify//GEN-BEGIN:variables
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;
226 // End of variables declaration//GEN-END:variables
227
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."
237
238 })
239 private class LocalDiskModel implements TableModel {
240
241 private LocalDiskThread worker = null;
242 private boolean ready = false;
243 private volatile boolean loadingDisks = false;
244
245 //private String SELECT = "Select a local disk:";
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");
248
249 private void loadDisks() {
250
251 // if there is a worker already building the lists, then cancel it first.
252 if (loadingDisks && worker != null) {
253 worker.cancel(false);
254 }
255
256 // Clear the lists
257 errorLabel.setText("");
258 diskTable.setEnabled(false);
259 ready = false;
260 loadingDisks = true;
261 worker = new LocalDiskThread();
262 worker.execute();
263 }
264
265 @Override
266 public int getRowCount() {
267 if (disks.isEmpty()) {
268 return 0;
269 }
270 return disks.size();
271 }
272
273 @Override
274 public int getColumnCount() {
275 return 2;
276
277 }
278
279 @Override
280 public String getColumnName(int columnIndex) {
281 switch (columnIndex) {
282 case 0:
283 return NbBundle.getMessage(this.getClass(), "SelectDriveDialog.diskTable.column1.title");
284 case 1:
285 return NbBundle.getMessage(this.getClass(), "SelectDriveDialog.diskTable.column2.title");
286 default:
287 return "Unnamed"; //NON-NLS
288 }
289 }
290
291 @Override
292 public Class<?> getColumnClass(int columnIndex) {
293 return String.class;
294 }
295
296 @Override
297 public boolean isCellEditable(int rowIndex, int columnIndex) {
298 return false;
299 }
300
301 @Override
302 public Object getValueAt(int rowIndex, int columnIndex) {
303 if (ready) {
304 if (disks.isEmpty()) {
305 return NO_DRIVES;
306 }
307 switch (columnIndex) {
308 case 0:
309 return disks.get(rowIndex).getName();
310 case 1:
311 return disks.get(rowIndex).getReadableSize();
312 default:
313 return disks.get(rowIndex).getPath();
314 }
315 } else {
316 return LOADING;
317 }
318 }
319
320 @Override
321 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
322 //setter does nothing they should not be able to modify table
323 }
324
325 @Override
326 public void addTableModelListener(TableModelListener l) {
327
328 }
329
330 @Override
331 public void removeTableModelListener(TableModelListener l) {
332
333 }
334
339 class LocalDiskThread extends SwingWorker<Object, Void> {
340
341 private final Logger logger = Logger.getLogger(LocalDiskThread.class.getName());
342 private List<LocalDisk> partitions = new ArrayList<>();
343
344 @Override
345 protected Object doInBackground() throws Exception {
346 // Populate the lists
347 partitions = new ArrayList<>();
348 partitions = PlatformUtil.getPartitions();
349 return null;
350 }
351
356 private void displayErrors() {
357 if (partitions.isEmpty()) {
359 errorLabel.setText(
360 NbBundle.getMessage(this.getClass(), "SelectDriveDialog.errLabel.disksNotDetected.text"));
361 errorLabel.setToolTipText(NbBundle.getMessage(this.getClass(),
362 "SelectDriveDialog.errLabel.disksNotDetected.toolTipText"));
363 } else {
364 errorLabel.setText(
365 NbBundle.getMessage(this.getClass(), "SelectDriveDialog.errLabel.drivesNotDetected.text"));
366 errorLabel.setToolTipText(NbBundle.getMessage(this.getClass(),
367 "SelectDriveDialog.errLabel.drivesNotDetected.toolTipText"));
368 }
369 errorLabel.setVisible(true);
370 diskTable.setEnabled(false);
371 }
372 }
373
374 @Override
375 protected void done() {
376 try {
377 super.get(); //block and get all exceptions thrown while doInBackground()
378 } catch (CancellationException ex) {
379 logger.log(Level.INFO, "Loading local disks was canceled."); //NON-NLS
380 } catch (InterruptedException ex) {
381 logger.log(Level.INFO, "Loading local disks was interrupted."); //NON-NLS
382 } catch (Exception ex) {
383 logger.log(Level.SEVERE, "Fatal error when loading local disks", ex); //NON-NLS
384 } finally {
385 if (!this.isCancelled()) {
386 displayErrors();
387 worker = null;
388 loadingDisks = false;
389 disks = new ArrayList<>();
390 disks.addAll(partitions);
391
392 if (disks.size() > 0) {
393 diskTable.setEnabled(true);
394 diskTable.clearSelection();
395
396 Collections.sort(disks, (LocalDisk disk1, LocalDisk disk2) -> disk1.getName().compareToIgnoreCase(disk2.getName()));
397 }
398
399 ready = true;
400 }
401 }
402 diskTable.revalidate();
403 }
404 }
405 }
406}
synchronized static Logger getLogger(String name)
Definition Logger.java:124
void setValueAt(Object aValue, int rowIndex, int columnIndex)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.