Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LocalFilesPanel.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  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import javax.swing.JFileChooser;
27 import org.openide.util.NbBundle;
30 import java.util.logging.Level;
31 import javax.swing.JOptionPane;
34 
38 final class LocalFilesPanel extends javax.swing.JPanel {
39 
40  private static final long serialVersionUID = 1L;
41 
42  private final Set<File> currentFiles = new TreeSet<>(); //keep currents in a set to disallow duplicates per add
43  private boolean enableNext = false;
44  private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
45  private String displayName = "";
46 
50  LocalFilesPanel() {
51  initComponents();
52  customInit();
53  }
54 
55  private void customInit() {
56  localFileChooser.setMultiSelectionEnabled(true);
57  errorLabel.setVisible(false);
58  selectedPaths.setText("");
59  this.displayNameLabel.setText(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.displayNameLabel.text"));
60  }
61 
67  @SuppressWarnings("unchecked")
68  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
69  private void initComponents() {
70 
71  localFileChooser = new javax.swing.JFileChooser();
72  jPanel1 = new javax.swing.JPanel();
73  selectButton = new javax.swing.JButton();
74  clearButton = new javax.swing.JButton();
75  selectedPathsScrollPane = new javax.swing.JScrollPane();
76  selectedPaths = new javax.swing.JTextArea();
77  errorLabel = new javax.swing.JLabel();
78  changeNameButton = new javax.swing.JButton();
79  displayNameLabel = new javax.swing.JLabel();
80 
81  localFileChooser.setApproveButtonText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonText")); // NOI18N
82  localFileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonToolTipText")); // NOI18N
83  localFileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.dialogTitle")); // NOI18N
84  localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
85 
86  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.text")); // NOI18N
87  selectButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.toolTipText")); // NOI18N
88  selectButton.setActionCommand(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.actionCommand")); // NOI18N
89  selectButton.setMaximumSize(new java.awt.Dimension(70, 23));
90  selectButton.setMinimumSize(new java.awt.Dimension(70, 23));
91  selectButton.setPreferredSize(new java.awt.Dimension(70, 23));
92  selectButton.addActionListener(new java.awt.event.ActionListener() {
93  public void actionPerformed(java.awt.event.ActionEvent evt) {
94  selectButtonActionPerformed(evt);
95  }
96  });
97 
98  org.openide.awt.Mnemonics.setLocalizedText(clearButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.text")); // NOI18N
99  clearButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.toolTipText")); // NOI18N
100  clearButton.setMaximumSize(new java.awt.Dimension(70, 23));
101  clearButton.setMinimumSize(new java.awt.Dimension(70, 23));
102  clearButton.setPreferredSize(new java.awt.Dimension(70, 23));
103  clearButton.addActionListener(new java.awt.event.ActionListener() {
104  public void actionPerformed(java.awt.event.ActionEvent evt) {
105  clearButtonActionPerformed(evt);
106  }
107  });
108 
109  selectedPathsScrollPane.setPreferredSize(new java.awt.Dimension(379, 96));
110 
111  selectedPaths.setEditable(false);
112  selectedPaths.setColumns(20);
113  selectedPaths.setRows(5);
114  selectedPaths.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectedPaths.toolTipText")); // NOI18N
115  selectedPathsScrollPane.setViewportView(selectedPaths);
116 
117  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
118  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.errorLabel.text")); // NOI18N
119 
120  org.openide.awt.Mnemonics.setLocalizedText(changeNameButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.changeNameButton.text")); // NOI18N
121  changeNameButton.addActionListener(new java.awt.event.ActionListener() {
122  public void actionPerformed(java.awt.event.ActionEvent evt) {
123  changeNameButtonActionPerformed(evt);
124  }
125  });
126 
127  org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.displayNameLabel.text")); // NOI18N
128 
129  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
130  jPanel1.setLayout(jPanel1Layout);
131  jPanel1Layout.setHorizontalGroup(
132  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133  .addGroup(jPanel1Layout.createSequentialGroup()
134  .addContainerGap()
135  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
137  .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
138  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
139  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
140  .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
141  .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
142  .addGap(2, 2, 2))
143  .addGroup(jPanel1Layout.createSequentialGroup()
144  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145  .addGroup(jPanel1Layout.createSequentialGroup()
146  .addComponent(displayNameLabel)
147  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
148  .addComponent(changeNameButton))
149  .addComponent(errorLabel))
150  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
151  );
152 
153  jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearButton, selectButton});
154 
155  jPanel1Layout.setVerticalGroup(
156  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157  .addGroup(jPanel1Layout.createSequentialGroup()
158  .addGap(0, 0, 0)
159  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160  .addGroup(jPanel1Layout.createSequentialGroup()
161  .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
162  .addGap(36, 36, 36)
163  .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
164  .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
165  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167  .addComponent(changeNameButton)
168  .addComponent(displayNameLabel))
169  .addGap(13, 13, 13)
170  .addComponent(errorLabel)
171  .addContainerGap())
172  );
173 
174  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
175  this.setLayout(layout);
176  layout.setHorizontalGroup(
177  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
179  );
180  layout.setVerticalGroup(
181  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
183  );
184  }// </editor-fold>//GEN-END:initComponents
185 
186  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
187  int returnVal = localFileChooser.showOpenDialog(this);
188 
189  if (returnVal == JFileChooser.APPROVE_OPTION) {
190  File[] files = localFileChooser.getSelectedFiles();
191  StringBuilder allPaths = new StringBuilder();
192  for (File f : files) {
193  currentFiles.add(f);
194  }
195  for (File f : currentFiles) {
196  //loop over set of all files to ensure list is accurate
197  //update label
198  allPaths.append(f.getAbsolutePath()).append("\n");
199  }
200  this.selectedPaths.setText(allPaths.toString());
201  this.selectedPaths.setToolTipText(allPaths.toString());
202  }
203 
204  enableNext = !currentFiles.isEmpty();
205 
206  try {
207  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
208  } catch (Exception e) {
209  logger.log(Level.SEVERE, "LocalFilesPanel listener threw exception", e); //NON-NLS
210  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr"),
211  NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr.msg"),
212  MessageNotifyUtil.MessageType.ERROR);
213  }
214  }//GEN-LAST:event_selectButtonActionPerformed
215 
216  private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
217  reset();
218  }//GEN-LAST:event_clearButtonActionPerformed
219 
220  private void changeNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeNameButtonActionPerformed
221  final String selectedDisplayName = JOptionPane.showInputDialog("New Display Name: ");
222  if (selectedDisplayName != null && !selectedDisplayName.isEmpty()) {
223  this.displayName = selectedDisplayName;
224  this.displayNameLabel.setText("Display Name: " + this.displayName);
225  }
226  }//GEN-LAST:event_changeNameButtonActionPerformed
227 
231  void reset() {
232  currentFiles.clear();
233  selectedPaths.setText("");
234  enableNext = false;
235  errorLabel.setVisible(false);
236  displayName = "";
237  this.displayNameLabel.setText(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.displayNameLabel.text"));
238  try {
239  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
240  } catch (Exception e) {
241  logger.log(Level.SEVERE, "LocalFilesPanel listener threw exception", e); //NON-NLS
242  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr"),
243  NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr.msg"),
244  MessageNotifyUtil.MessageType.ERROR);
245  }
246  }
252  List<String> getContentPaths() {
253  List<String> pathsList = new ArrayList<>();
254  if (currentFiles == null) {
255  return pathsList;
256  }
257  for (File f : currentFiles) {
258  pathsList.add(f.getAbsolutePath());
259  }
260  return pathsList;
261  }
262 
269  boolean validatePanel() {
270  // display warning if there is one (but don't disable "next" button)
271  warnIfPathIsInvalid(getContentPaths());
272  return enableNext;
273  }
274 
281  @NbBundle.Messages("LocalFilesPanel.pathValidation.error=WARNING: Exception while gettting opon case.")
282  private void warnIfPathIsInvalid(final List<String> pathsList) {
283  errorLabel.setVisible(false);
284 
285  try {
286  final Case.CaseType currentCaseType = Case.getOpenCase().getCaseType();
287 
288  for (String currentPath : pathsList) {
289  if (!PathValidator.isValid(currentPath, currentCaseType)) {
290  errorLabel.setVisible(true);
291  errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"));
292  return;
293  }
294  }
295  } catch (NoCurrentCaseException ex) {
296  errorLabel.setVisible(true);
297  errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_error());
298  }
299  }
300 
306  String getFileSetName() {
307  return this.displayName;
308  }
309 
310  // Variables declaration - do not modify//GEN-BEGIN:variables
311  private javax.swing.JButton changeNameButton;
312  private javax.swing.JButton clearButton;
313  private javax.swing.JLabel displayNameLabel;
314  private javax.swing.JLabel errorLabel;
315  private javax.swing.JPanel jPanel1;
316  private javax.swing.JFileChooser localFileChooser;
317  private javax.swing.JButton selectButton;
318  private javax.swing.JTextArea selectedPaths;
319  private javax.swing.JScrollPane selectedPathsScrollPane;
320  // End of variables declaration//GEN-END:variables
321 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.