6 package org.sleuthkit.autopsy.livetriage;
8 import java.util.ArrayList;
10 import java.util.concurrent.CancellationException;
11 import java.util.logging.Level;
12 import java.awt.Dimension;
13 import java.awt.Point;
14 import javax.swing.SwingWorker;
15 import javax.swing.event.ListSelectionEvent;
16 import javax.swing.event.ListSelectionListener;
17 import javax.swing.event.TableModelListener;
18 import javax.swing.table.TableModel;
19 import org.openide.util.NbBundle;
27 class SelectDriveDialog
extends javax.swing.JDialog {
29 private List<LocalDisk> disks =
new ArrayList<>();
30 private final LocalDiskModel model =
new LocalDiskModel();
31 private final java.awt.Frame parent;
32 private String drivePath =
"";
37 @NbBundle.Messages({
"SelectDriveDialog.title=Create Live Triage Drive"})
38 SelectDriveDialog(java.awt.Frame parent,
boolean modal) {
44 bnOk.setEnabled(
false);
45 diskTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
47 public void valueChanged(ListSelectionEvent e) {
48 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
49 bnOk.setEnabled(
true);
51 bnOk.setEnabled(
false);
58 this.setTitle(Bundle.SelectDriveDialog_title());
60 final Dimension parentSize = parent.getSize();
61 final Point parentLocationOnScreen = parent.getLocationOnScreen();
62 final Dimension childSize = this.getSize();
65 x = (parentSize.width - childSize.width) / 2;
66 y = (parentSize.height - childSize.height) / 2;
67 x += parentLocationOnScreen.x;
68 y += parentLocationOnScreen.y;
74 String getSelectedDrive() {
75 return this.drivePath;
83 @SuppressWarnings(
"unchecked")
85 private
void initComponents() {
87 jScrollPane1 =
new javax.swing.JScrollPane();
88 diskTable =
new javax.swing.JTable();
89 jLabel1 =
new javax.swing.JLabel();
90 bnRefresh =
new javax.swing.JButton();
91 bnOk =
new javax.swing.JButton();
92 errorLabel =
new javax.swing.JLabel();
93 jSeparator1 =
new javax.swing.JSeparator();
94 bnCancel =
new javax.swing.JButton();
95 jScrollPane2 =
new javax.swing.JScrollPane();
96 jTextArea1 =
new javax.swing.JTextArea();
98 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
100 diskTable.setModel(model);
101 jScrollPane1.setViewportView(diskTable);
103 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.jLabel1.text"));
105 org.openide.awt.Mnemonics.setLocalizedText(bnRefresh,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnRefresh.text"));
106 bnRefresh.addActionListener(
new java.awt.event.ActionListener() {
107 public void actionPerformed(java.awt.event.ActionEvent evt) {
108 bnRefreshActionPerformed(evt);
112 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnOk.text"));
113 bnOk.addActionListener(
new java.awt.event.ActionListener() {
114 public void actionPerformed(java.awt.event.ActionEvent evt) {
115 bnOkActionPerformed(evt);
119 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.errorLabel.text"));
121 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.bnCancel.text"));
122 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
123 public void actionPerformed(java.awt.event.ActionEvent evt) {
124 bnCancelActionPerformed(evt);
128 jScrollPane2.setBorder(null);
130 jTextArea1.setBackground(
new java.awt.Color(240, 240, 240));
131 jTextArea1.setColumns(20);
132 jTextArea1.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
133 jTextArea1.setRows(5);
134 jTextArea1.setText(
org.openide.util.NbBundle.getMessage(SelectDriveDialog.class,
"SelectDriveDialog.jTextArea1.text"));
135 jTextArea1.setBorder(null);
136 jScrollPane2.setViewportView(jTextArea1);
138 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
139 getContentPane().setLayout(layout);
140 layout.setHorizontalGroup(
141 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142 .addGroup(layout.createSequentialGroup()
144 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
145 .addGroup(layout.createSequentialGroup()
146 .addComponent(bnRefresh, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
147 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
148 .addComponent(bnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
149 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
150 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
151 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
152 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
153 .addComponent(jSeparator1)
154 .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
155 .addComponent(jScrollPane2))
156 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
158 layout.setVerticalGroup(
159 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160 .addGroup(layout.createSequentialGroup()
162 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
163 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
164 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
165 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166 .addComponent(jLabel1)
167 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
168 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
169 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
170 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
171 .addComponent(bnRefresh)
172 .addComponent(bnCancel)
174 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
175 .addComponent(errorLabel)
176 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
182 private void bnRefreshActionPerformed(java.awt.event.ActionEvent evt) {
186 private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {
187 if (diskTable.getSelectedRow() >= 0 && diskTable.getSelectedRow() < disks.size()) {
188 LocalDisk selectedDisk = disks.get(diskTable.getSelectedRow());
189 drivePath = selectedDisk.getPath();
196 private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {
202 private javax.swing.JButton bnCancel;
203 private javax.swing.JButton bnOk;
204 private javax.swing.JButton bnRefresh;
205 private javax.swing.JTable diskTable;
206 private javax.swing.JLabel errorLabel;
207 private javax.swing.JLabel jLabel1;
208 private javax.swing.JScrollPane jScrollPane1;
209 private javax.swing.JScrollPane jScrollPane2;
210 private javax.swing.JSeparator jSeparator1;
211 private javax.swing.JTextArea jTextArea1;
217 @NbBundle.Messages({
"SelectDriveDialog.localDiskModel.loading.msg=",
218 "SelectDriveDialog.localDiskModel.nodrives.msg=Executable could not be found",
219 "SelectDriveDialog.diskTable.column1.title=Disk Name",
220 "SelectDriveDialog.diskTable.column2.title=Disk Size",
221 "SelectDriveDialog.errLabel.disksNotDetected.text=Disks were not detected. On some systems it requires admin privileges",
222 "SelectDriveDialog.errLabel.disksNotDetected.toolTipText=Disks were not detected."
227 private LocalDiskThread worker = null;
228 private boolean ready =
false;
229 private volatile boolean loadingDisks =
false;
232 private final String LOADING = NbBundle.getMessage(this.getClass(),
"SelectDriveDialog.localDiskModel.loading.msg");
233 private final String NO_DRIVES = NbBundle.getMessage(this.getClass(),
"SelectDriveDialog.localDiskModel.nodrives.msg");
238 if (loadingDisks && worker != null) {
239 worker.cancel(
false);
243 errorLabel.setText(
"");
244 diskTable.setEnabled(
false);
247 worker =
new LocalDiskThread();
253 if (disks.isEmpty()) {
267 switch (columnIndex) {
269 return NbBundle.getMessage(this.getClass(),
"SelectDriveDialog.diskTable.column1.title");
271 return NbBundle.getMessage(this.getClass(),
"SelectDriveDialog.diskTable.column2.title");
290 if (disks.isEmpty()) {
293 switch (columnIndex) {
295 return disks.get(rowIndex).getName();
297 return disks.get(rowIndex).getReadableSize();
299 return disks.get(rowIndex).getPath();
307 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
325 class LocalDiskThread
extends SwingWorker<Object, Void> {
328 private List<LocalDisk> partitions =
new ArrayList<>();
331 protected Object doInBackground() throws Exception {
333 partitions =
new ArrayList<>();
342 private void displayErrors() {
343 if (partitions.isEmpty()) {
346 NbBundle.getMessage(
this.getClass(),
"SelectDriveDialog.errLabel.disksNotDetected.text"));
347 errorLabel.setToolTipText(NbBundle.getMessage(
this.getClass(),
348 "SelectDriveDialog.errLabel.disksNotDetected.toolTipText"));
351 NbBundle.getMessage(
this.getClass(),
"SelectDriveDialog.errLabel.drivesNotDetected.text"));
352 errorLabel.setToolTipText(NbBundle.getMessage(
this.getClass(),
353 "SelectDriveDialog.errLabel.drivesNotDetected.toolTipText"));
355 errorLabel.setVisible(
true);
356 diskTable.setEnabled(
false);
361 protected void done() {
364 }
catch (CancellationException ex) {
365 logger.log(Level.INFO,
"Loading local disks was canceled.");
366 }
catch (InterruptedException ex) {
367 logger.log(Level.INFO,
"Loading local disks was interrupted.");
368 }
catch (Exception ex) {
369 logger.log(Level.SEVERE,
"Fatal error when loading local disks", ex);
371 if (!this.isCancelled()) {
374 loadingDisks =
false;
375 disks =
new ArrayList<>();
376 disks.addAll(partitions);
377 if (disks.size() > 0) {
378 diskTable.setEnabled(
true);
379 diskTable.clearSelection();
384 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)