19 package org.sleuthkit.autopsy.casemodule;
 
   21 import java.awt.Dialog;
 
   23 import java.util.Arrays;
 
   24 import java.util.List;
 
   26 import java.util.TreeSet;
 
   27 import javax.swing.JFileChooser;
 
   28 import javax.swing.JPanel;
 
   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;
 
   45 class LocalFilesPanel 
extends JPanel {
 
   47     private Set<File> currentFiles = 
new TreeSet<File>(); 
 
   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 = 
"";
 
   57     private LocalFilesPanel() {
 
   62     static synchronized LocalFilesPanel getDefault() {
 
   63         if (instance == null) {
 
   64             instance = 
new LocalFilesPanel();
 
   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"));
 
   77     public String getContentPaths() {
 
   80         if (currentFiles == null) {
 
   83         StringBuilder b = 
new StringBuilder();
 
   84         for (File f : currentFiles) {
 
   85             b.append(f.getAbsolutePath());
 
   92     public void setContentPath(String s) {
 
   98     public String getContentType() {
 
   99         return NbBundle.getMessage(this.getClass(), 
"LocalFilesPanel.contentType.text");
 
  103     public boolean validatePanel() {
 
  106         warnIfPathIsInvalid(getContentPaths());
 
  117     private void warnIfPathIsInvalid(String path) {
 
  118         errorLabel.setVisible(
false);
 
  121         List<String> pathsList = Arrays.asList(path.split(
","));
 
  122         CaseType currentCaseType = Case.getCurrentCase().getCaseType();
 
  124         for (String currentPath : pathsList) {
 
  125             if (!PathValidator.isValid(currentPath, currentCaseType)) {
 
  126                 errorLabel.setVisible(
true);
 
  127                 errorLabel.setText(NbBundle.getMessage(
this.getClass(), 
"DataSourceOnCDriveError.text"));
 
  134     public void select() {
 
  139     public void reset() {
 
  140         currentFiles.clear();
 
  141         selectedPaths.setText(
"");
 
  143         errorLabel.setVisible(
false);
 
  145         this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(), 
"LocalFilesPanel.displayNameLabel.text"));
 
  148     public String getFileSetName() {
 
  149         return this.displayName;
 
  153     public String toString() {
 
  154         return NbBundle.getMessage(this.getClass(), 
"LocalFilesDSProcessor.toString.text");
 
  162     @SuppressWarnings(
"unchecked")
 
  164     private 
void initComponents() {
 
  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();
 
  178         localFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.localFileChooser.approveButtonText")); 
 
  179         localFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.localFileChooser.approveButtonToolTipText")); 
 
  180         localFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.localFileChooser.dialogTitle")); 
 
  181         localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
 
  183         jTextArea1.setColumns(20);
 
  184         jTextArea1.setRows(5);
 
  185         jScrollPane1.setViewportView(jTextArea1);
 
  187         org.openide.awt.Mnemonics.setLocalizedText(selectButton, 
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.selectButton.text")); 
 
  188         selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.selectButton.toolTipText")); 
 
  189         selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.selectButton.actionCommand")); 
 
  190         selectButton.addActionListener(
new java.awt.event.ActionListener() {
 
  191             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  192                 selectButtonActionPerformed(evt);
 
  196         org.openide.awt.Mnemonics.setLocalizedText(infoLabel, 
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.infoLabel.text")); 
 
  198         org.openide.awt.Mnemonics.setLocalizedText(clearButton, 
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.clearButton.text")); 
 
  199         clearButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.clearButton.toolTipText")); 
 
  200         clearButton.addActionListener(
new java.awt.event.ActionListener() {
 
  201             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  202                 clearButtonActionPerformed(evt);
 
  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")); 
 
  210         jScrollPane2.setViewportView(selectedPaths);
 
  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")); 
 
  215         org.openide.awt.Mnemonics.setLocalizedText(jButton1, 
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.jButton1.text")); 
 
  216         jButton1.addActionListener(
new java.awt.event.ActionListener() {
 
  217             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  218                 jButton1ActionPerformed(evt);
 
  222         org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel, 
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, 
"LocalFilesPanel.displayNameLabel.text")); 
 
  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))
 
  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))
 
  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)
 
  257                         .addComponent(clearButton))
 
  258                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  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))
 
  264                 .addComponent(errorLabel)
 
  269     private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  270         int returnVal = localFileChooser.showOpenDialog(
this);
 
  271         if (returnVal == JFileChooser.APPROVE_OPTION) {
 
  272             File[] files = localFileChooser.getSelectedFiles();
 
  273             for (File f : files) {
 
  278             StringBuilder allPaths = 
new StringBuilder();
 
  279             for (File f : currentFiles) {
 
  280                 allPaths.append(f.getAbsolutePath()).append(
"\n");
 
  282             this.selectedPaths.setText(allPaths.toString());
 
  283             this.selectedPaths.setToolTipText(allPaths.toString());
 
  287         if (!currentFiles.isEmpty()) {
 
  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); 
 
  297             MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(), 
"LocalFilesPanel.moduleErr"),
 
  298                     NbBundle.getMessage(
this.getClass(), 
"LocalFilesPanel.moduleErr.msg"),
 
  299                     MessageNotifyUtil.MessageType.ERROR);
 
  303     private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  308     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 
  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);
 
  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;