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

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.