19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.Dialog;
22 import java.beans.PropertyChangeListener;
23 import java.beans.PropertyChangeSupport;
25 import java.util.Arrays;
26 import java.util.List;
28 import java.util.TreeSet;
29 import javax.swing.JFileChooser;
30 import javax.swing.JPanel;
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;
47 class LocalFilesPanel
extends JPanel {
49 private PropertyChangeSupport pcs = null;
50 private Set<File> currentFiles =
new TreeSet<File>();
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 =
"";
60 private LocalFilesPanel() {
65 static synchronized LocalFilesPanel getDefault() {
66 if (instance == null) {
67 instance =
new LocalFilesPanel();
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"));
80 public String getContentPaths() {
83 if (currentFiles == null) {
86 StringBuilder b =
new StringBuilder();
87 for (File f : currentFiles) {
88 b.append(f.getAbsolutePath());
95 public void setContentPath(String s) {
101 public String getContentType() {
102 return NbBundle.getMessage(this.getClass(),
"LocalFilesPanel.contentType.text");
106 public boolean validatePanel() {
109 warnIfPathIsInvalid(getContentPaths());
120 private void warnIfPathIsInvalid(String path) {
121 errorLabel.setVisible(
false);
124 List<String> pathsList = Arrays.asList(path.split(
","));
125 CaseType currentCaseType = Case.getCurrentCase().getCaseType();
127 for (String currentPath : pathsList) {
128 if (!PathValidator.isValid(currentPath, currentCaseType)) {
129 errorLabel.setVisible(
true);
130 errorLabel.setText(NbBundle.getMessage(
this.getClass(),
"DataSourceOnCDriveError.text"));
137 public void select() {
142 public void reset() {
143 currentFiles.clear();
144 selectedPaths.setText(
"");
146 errorLabel.setVisible(
false);
148 this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.displayNameLabel.text"));
152 public synchronized void addPropertyChangeListener(PropertyChangeListener pcl) {
153 super.addPropertyChangeListener(pcl);
156 pcs =
new PropertyChangeSupport(
this);
159 pcs.addPropertyChangeListener(pcl);
163 public void removePropertyChangeListener(PropertyChangeListener pcl) {
164 super.removePropertyChangeListener(pcl);
166 pcs.removePropertyChangeListener(pcl);
169 public String getFileSetName() {
170 return this.displayName;
174 public String toString() {
175 return NbBundle.getMessage(this.getClass(),
"LocalFilesDSProcessor.toString.text");
183 @SuppressWarnings(
"unchecked")
185 private
void initComponents() {
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();
199 localFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonText"));
200 localFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonToolTipText"));
201 localFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.dialogTitle"));
202 localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
204 jTextArea1.setColumns(20);
205 jTextArea1.setRows(5);
206 jScrollPane1.setViewportView(jTextArea1);
208 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.text"));
209 selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.toolTipText"));
210 selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.actionCommand"));
211 selectButton.addActionListener(
new java.awt.event.ActionListener() {
212 public void actionPerformed(java.awt.event.ActionEvent evt) {
213 selectButtonActionPerformed(evt);
217 org.openide.awt.Mnemonics.setLocalizedText(infoLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.infoLabel.text"));
219 org.openide.awt.Mnemonics.setLocalizedText(clearButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.text"));
220 clearButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.toolTipText"));
221 clearButton.addActionListener(
new java.awt.event.ActionListener() {
222 public void actionPerformed(java.awt.event.ActionEvent evt) {
223 clearButtonActionPerformed(evt);
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"));
231 jScrollPane2.setViewportView(selectedPaths);
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"));
236 org.openide.awt.Mnemonics.setLocalizedText(jButton1,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.jButton1.text"));
237 jButton1.addActionListener(
new java.awt.event.ActionListener() {
238 public void actionPerformed(java.awt.event.ActionEvent evt) {
239 jButton1ActionPerformed(evt);
243 org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.displayNameLabel.text"));
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))
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))
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)
278 .addComponent(clearButton))
279 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
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))
285 .addComponent(errorLabel)
290 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
291 int returnVal = localFileChooser.showOpenDialog(
this);
292 if (returnVal == JFileChooser.APPROVE_OPTION) {
293 File[] files = localFileChooser.getSelectedFiles();
294 for (File f : files) {
299 StringBuilder allPaths =
new StringBuilder();
300 for (File f : currentFiles) {
301 allPaths.append(f.getAbsolutePath()).append(
"\n");
303 this.selectedPaths.setText(allPaths.toString());
304 this.selectedPaths.setToolTipText(allPaths.toString());
308 if (!currentFiles.isEmpty()) {
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);
318 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
319 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
320 MessageNotifyUtil.MessageType.ERROR);
324 private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
329 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
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);
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;