19 package org.sleuthkit.autopsy.casemodule;
22 import java.util.ArrayList;
23 import java.util.List;
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.event.DocumentEvent;
32 import javax.swing.event.DocumentListener;
33 import org.apache.commons.io.FilenameUtils;
34 import org.apache.commons.lang3.StringUtils;
35 import org.openide.util.NbBundle.Messages;
42 @SuppressWarnings(
"PMD.SingularField")
43 final class LogicalEvidenceFilePanel extends javax.swing.JPanel implements DocumentListener {
45 private static final long serialVersionUID = 1L;
47 private final Set<File> currentFiles =
new TreeSet<>();
48 private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
49 private String displayName =
"";
54 private LogicalEvidenceFilePanel() {
56 logicalEvidenceFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
57 logicalEvidenceFileChooser.setAcceptAllFileFilterUsed(
false);
58 logicalEvidenceFileChooser.setMultiSelectionEnabled(
false);
59 logicalEvidenceFileChooser.setFileFilter(LocalFilesDSProcessor.getLogicalEvidenceFilter());
67 static LogicalEvidenceFilePanel createInstance() {
68 synchronized (LogicalEvidenceFilePanel.class) {
69 final LogicalEvidenceFilePanel instance =
new LogicalEvidenceFilePanel();
71 instance.logicalEvidencePathField.getDocument().addDocumentListener(instance);
81 @SuppressWarnings(
"unchecked")
83 private
void initComponents() {
85 logicalEvidenceFileChooser =
new javax.swing.JFileChooser();
86 selectButton =
new javax.swing.JButton();
87 logicalEvidencePathField =
new javax.swing.JTextField();
88 errorLabel =
new javax.swing.JLabel();
90 logicalEvidenceFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.logicalEvidenceFileChooser.approveButtonText"));
91 logicalEvidenceFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.logicalEvidenceFileChooser.approveButtonToolTipText"));
92 logicalEvidenceFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.logicalEvidenceFileChooser.dialogTitle"));
93 logicalEvidenceFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
95 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.selectButton.text"));
96 selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.selectButton.toolTipText"));
97 selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.selectButton.actionCommand"));
98 selectButton.setMaximumSize(
new java.awt.Dimension(70, 23));
99 selectButton.setMinimumSize(
new java.awt.Dimension(70, 23));
100 selectButton.setPreferredSize(
new java.awt.Dimension(70, 23));
101 selectButton.addActionListener(
new java.awt.event.ActionListener() {
102 public void actionPerformed(java.awt.event.ActionEvent evt) {
103 selectButtonActionPerformed(evt);
107 logicalEvidencePathField.setText(
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.logicalEvidencePathField.text"));
108 logicalEvidencePathField.setPreferredSize(
new java.awt.Dimension(379, 20));
110 errorLabel.setForeground(
new java.awt.Color(255, 0, 0));
111 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(LogicalEvidenceFilePanel.class,
"LogicalEvidenceFilePanel.errorLabel.text"));
113 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
114 this.setLayout(layout);
115 layout.setHorizontalGroup(
116 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117 .addGroup(layout.createSequentialGroup()
119 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120 .addGroup(layout.createSequentialGroup()
121 .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
123 .addGroup(layout.createSequentialGroup()
124 .addComponent(logicalEvidencePathField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
125 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126 .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
129 layout.setVerticalGroup(
130 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131 .addGroup(layout.createSequentialGroup()
133 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
134 .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
135 .addComponent(logicalEvidencePathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
137 .addComponent(errorLabel)
138 .addContainerGap(105, Short.MAX_VALUE))
143 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
144 final int returnVal = logicalEvidenceFileChooser.showOpenDialog(
this);
146 if (returnVal == JFileChooser.APPROVE_OPTION) {
147 final File file = logicalEvidenceFileChooser.getSelectedFile();
148 final StringBuilder allPaths =
new StringBuilder();
149 currentFiles.add(file);
150 allPaths.append(file.getAbsolutePath());
151 logicalEvidencePathField.setText(allPaths.toString());
152 logicalEvidencePathField.setToolTipText(allPaths.toString());
161 currentFiles.clear();
162 logicalEvidencePathField.setText(
"");
163 logicalEvidencePathField.setToolTipText(
"");
167 private javax.swing.JLabel errorLabel;
168 private javax.swing.JFileChooser logicalEvidenceFileChooser;
169 private javax.swing.JTextField logicalEvidencePathField;
170 private javax.swing.JButton selectButton;
181 "LogicalEvidenceFilePanel.validatePanel.nonL01Error.text=Only files with the .l01 file extension are supported here.",
182 "LogicalEvidenceFilePanel.pathValidation.dataSourceOnCDriveError=Warning: Path to multi-user data source is on \"C:\" drive",
183 "LogicalEvidenceFilePanel.pathValidation.getOpenCase.Error=Warning: Exception while getting open case."
185 boolean validatePanel() {
186 errorLabel.setVisible(
false);
188 final String path = logicalEvidencePathField.getText();
189 if (StringUtils.isBlank(path)) {
194 if (!PathValidator.isValid(path, Case.getCurrentCaseThrows().getCaseType())) {
195 errorLabel.setVisible(
true);
196 errorLabel.setText(Bundle.LogicalEvidenceFilePanel_pathValidation_dataSourceOnCDriveError());
199 }
catch (NoCurrentCaseException ex) {
200 errorLabel.setVisible(
true);
201 errorLabel.setText(Bundle.LogicalEvidenceFilePanel_pathValidation_getOpenCase_Error());
205 if (!LocalFilesDSProcessor.getLogicalEvidenceFilter().accept(
new File(path))) {
206 errorLabel.setVisible(
true);
207 errorLabel.setText(Bundle.LogicalEvidenceFilePanel_validatePanel_nonL01Error_text());
211 displayName = FilenameUtils.getName(path);
212 return new File(path).isFile();
220 List<String> getContentPaths() {
221 final List<String> pathsList =
new ArrayList<>();
222 if (currentFiles == null) {
225 for (
final File f : currentFiles) {
226 pathsList.add(f.getAbsolutePath());
236 String getFileSetName() {
241 public void insertUpdate(
final DocumentEvent docEvent) {
246 public void removeUpdate(
final DocumentEvent docEvent) {
251 public void changedUpdate(
final DocumentEvent docEvent) {
256 "LogicalEvidenceFilePanel.moduleErr.name=Module Error",
257 "LogicalEvidenceFilePanel.moduleErr.msg=A module caused an error listening to LogicalEvidenceFilePanel updates. See log to determine which module. Some data could be incomplete."
259 private void fireChange() {
261 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
262 }
catch (Exception e) {
263 logger.log(Level.SEVERE,
"LogicalEvidenceFilePanel listener threw exception", e);
264 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LogicalEvidenceFilePanel.moduleErr"),
265 NbBundle.getMessage(
this.getClass(),
"LogicalEvidenceFilePanel.moduleErr.msg"),
266 MessageNotifyUtil.MessageType.ERROR);