Autopsy  4.1
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 2013 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.awt.Dialog;
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.TreeSet;
27 import javax.swing.JFileChooser;
28 import javax.swing.JPanel;
29 
30 import org.openide.util.NbBundle;
33 import java.util.logging.Level;
34 import javax.swing.JOptionPane;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
41 
45 class LocalFilesPanel extends JPanel {
46 
47  private Set<File> currentFiles = new TreeSet<File>(); //keep currents in a set to disallow duplicates per add
48  private boolean enableNext = false;
49  private static LocalFilesPanel instance;
50  public static final String FILES_SEP = ",";
51  private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
52  private String displayName = "";
53 
57  private LocalFilesPanel() {
58  initComponents();
59  customInit();
60  }
61 
62  static synchronized LocalFilesPanel getDefault() {
63  if (instance == null) {
64  instance = new LocalFilesPanel();
65  }
66  return instance;
67  }
68 
69  private void customInit() {
70  localFileChooser.setMultiSelectionEnabled(true);
71  errorLabel.setVisible(false);
72  selectedPaths.setText("");
73  this.displayNameLabel.setText(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.displayNameLabel.text"));
74  }
75 
76  //@Override
77  public String getContentPaths() {
78  //TODO consider interface change to return list of paths instead
79 
80  if (currentFiles == null) {
81  return "";
82  }
83  StringBuilder b = new StringBuilder();
84  for (File f : currentFiles) {
85  b.append(f.getAbsolutePath());
86  b.append(FILES_SEP);
87  }
88  return b.toString();
89  }
90 
91  //@Override
92  public void setContentPath(String s) {
93  //for the local file panel we don't need to restore the last paths used
94  //when the wizard restarts
95  }
96 
97  //@Override
98  public String getContentType() {
99  return NbBundle.getMessage(this.getClass(), "LocalFilesPanel.contentType.text");
100  }
101 
102  //@Override
103  public boolean validatePanel() {
104 
105  // display warning if there is one (but don't disable "next" button)
106  warnIfPathIsInvalid(getContentPaths());
107 
108  return enableNext;
109  }
110 
117  private void warnIfPathIsInvalid(String path) {
118  errorLabel.setVisible(false);
119 
120  // Path variable for "Local files" module is a coma separated string containg multiple paths
121  List<String> pathsList = Arrays.asList(path.split(","));
122  CaseType currentCaseType = Case.getCurrentCase().getCaseType();
123 
124  for (String currentPath : pathsList) {
125  if (!PathValidator.isValid(currentPath, currentCaseType)) {
126  errorLabel.setVisible(true);
127  errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"));
128  return;
129  }
130  }
131  }
132 
133  //@Override
134  public void select() {
135  reset();
136  }
137 
138  //@Override
139  public void reset() {
140  currentFiles.clear();
141  selectedPaths.setText("");
142  enableNext = false;
143  errorLabel.setVisible(false);
144  displayName = "";
145  this.displayNameLabel.setText(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.displayNameLabel.text"));
146  }
147 
148  public String getFileSetName() {
149  return this.displayName;
150  }
151 
152  @Override
153  public String toString() {
154  return NbBundle.getMessage(this.getClass(), "LocalFilesDSProcessor.toString.text");
155  }
156 
162  @SuppressWarnings("unchecked")
163  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
164  private void initComponents() {
165 
166  localFileChooser = new javax.swing.JFileChooser();
167  jScrollPane1 = new javax.swing.JScrollPane();
168  jTextArea1 = new javax.swing.JTextArea();
169  selectButton = new javax.swing.JButton();
170  infoLabel = new javax.swing.JLabel();
171  clearButton = new javax.swing.JButton();
172  jScrollPane2 = new javax.swing.JScrollPane();
173  selectedPaths = new javax.swing.JTextArea();
174  errorLabel = new javax.swing.JLabel();
175  jButton1 = new javax.swing.JButton();
176  displayNameLabel = new javax.swing.JLabel();
177 
178  localFileChooser.setApproveButtonText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonText")); // NOI18N
179  localFileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonToolTipText")); // NOI18N
180  localFileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.dialogTitle")); // NOI18N
181  localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
182 
183  jTextArea1.setColumns(20);
184  jTextArea1.setRows(5);
185  jScrollPane1.setViewportView(jTextArea1);
186 
187  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.text")); // NOI18N
188  selectButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.toolTipText")); // NOI18N
189  selectButton.setActionCommand(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.actionCommand")); // NOI18N
190  selectButton.addActionListener(new java.awt.event.ActionListener() {
191  public void actionPerformed(java.awt.event.ActionEvent evt) {
192  selectButtonActionPerformed(evt);
193  }
194  });
195 
196  org.openide.awt.Mnemonics.setLocalizedText(infoLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.infoLabel.text")); // NOI18N
197 
198  org.openide.awt.Mnemonics.setLocalizedText(clearButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.text")); // NOI18N
199  clearButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.toolTipText")); // NOI18N
200  clearButton.addActionListener(new java.awt.event.ActionListener() {
201  public void actionPerformed(java.awt.event.ActionEvent evt) {
202  clearButtonActionPerformed(evt);
203  }
204  });
205 
206  selectedPaths.setEditable(false);
207  selectedPaths.setColumns(20);
208  selectedPaths.setRows(5);
209  selectedPaths.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectedPaths.toolTipText")); // NOI18N
210  jScrollPane2.setViewportView(selectedPaths);
211 
212  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
213  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.errorLabel.text")); // NOI18N
214 
215  org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.jButton1.text")); // NOI18N
216  jButton1.addActionListener(new java.awt.event.ActionListener() {
217  public void actionPerformed(java.awt.event.ActionEvent evt) {
218  jButton1ActionPerformed(evt);
219  }
220  });
221 
222  org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.displayNameLabel.text")); // NOI18N
223 
224  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
225  this.setLayout(layout);
226  layout.setHorizontalGroup(
227  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
229  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230  .addGroup(layout.createSequentialGroup()
231  .addComponent(infoLabel)
232  .addGap(0, 0, Short.MAX_VALUE))
233  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE))
234  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
235  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
236  .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
237  .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
238  .addGap(2, 2, 2))
239  .addGroup(layout.createSequentialGroup()
240  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
241  .addComponent(errorLabel)
242  .addGroup(layout.createSequentialGroup()
243  .addComponent(displayNameLabel)
244  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
245  .addComponent(jButton1)))
246  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
247  );
248  layout.setVerticalGroup(
249  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250  .addGroup(layout.createSequentialGroup()
251  .addComponent(infoLabel)
252  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
254  .addGroup(layout.createSequentialGroup()
255  .addComponent(selectButton)
256  .addGap(36, 36, 36)
257  .addComponent(clearButton))
258  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
259  .addGap(18, 18, 18)
260  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
261  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
262  .addComponent(displayNameLabel))
263  .addGap(13, 13, 13)
264  .addComponent(errorLabel)
265  .addGap(7, 7, 7))
266  );
267  }// </editor-fold>//GEN-END:initComponents
268 
269  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
270  int returnVal = localFileChooser.showOpenDialog(this);
271  if (returnVal == JFileChooser.APPROVE_OPTION) {
272  File[] files = localFileChooser.getSelectedFiles();
273  for (File f : files) {
274  currentFiles.add(f);
275  }
276 
277  //update label
278  StringBuilder allPaths = new StringBuilder();
279  for (File f : currentFiles) {
280  allPaths.append(f.getAbsolutePath()).append("\n");
281  }
282  this.selectedPaths.setText(allPaths.toString());
283  this.selectedPaths.setToolTipText(allPaths.toString());
284 
285  }
286 
287  if (!currentFiles.isEmpty()) {
288  enableNext = true;
289  } else {
290  enableNext = false;
291  }
292 
293  try {
294  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
295  } catch (Exception e) {
296  logger.log(Level.SEVERE, "LocalFilesPanel listener threw exception", e); //NON-NLS
297  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr"),
298  NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr.msg"),
299  MessageNotifyUtil.MessageType.ERROR);
300  }
301  }//GEN-LAST:event_selectButtonActionPerformed
302 
303  private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
304  reset();
305 
306  }//GEN-LAST:event_clearButtonActionPerformed
307 
308  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
309  String displayName = JOptionPane.showInputDialog("New Display Name: ");
310  if (displayName != null && !displayName.equals("")) {
311  this.displayName = displayName;
312  this.displayNameLabel.setText("Display Name: " + this.displayName);
313  }
314  }//GEN-LAST:event_jButton1ActionPerformed
315 
316  // Variables declaration - do not modify//GEN-BEGIN:variables
317  private javax.swing.JButton clearButton;
318  private javax.swing.JLabel displayNameLabel;
319  private javax.swing.JLabel errorLabel;
320  private javax.swing.JLabel infoLabel;
321  private javax.swing.JButton jButton1;
322  private javax.swing.JScrollPane jScrollPane1;
323  private javax.swing.JScrollPane jScrollPane2;
324  private javax.swing.JTextArea jTextArea1;
325  private javax.swing.JFileChooser localFileChooser;
326  private javax.swing.JButton selectButton;
327  private javax.swing.JTextArea selectedPaths;
328  // End of variables declaration//GEN-END:variables
329 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.