19 package org.sleuthkit.autopsy.casemodule;
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyChangeSupport;
25 import java.util.TreeSet;
26 import javax.swing.JFileChooser;
27 import javax.swing.JPanel;
29 import org.openide.util.NbBundle;
32 import java.util.logging.Level;
37 class LocalFilesPanel
extends JPanel {
39 private PropertyChangeSupport pcs = null;
40 private Set<File> currentFiles =
new TreeSet<File>();
41 private boolean enableNext =
false;
42 private static LocalFilesPanel instance;
43 public static final String FILES_SEP =
",";
44 private static final Logger logger = Logger.
getLogger(LocalFilesPanel.class.getName());
48 private LocalFilesPanel() {
53 static synchronized LocalFilesPanel getDefault() {
54 if (instance == null) {
55 instance =
new LocalFilesPanel();
60 private void customInit() {
61 localFileChooser.setMultiSelectionEnabled(
true);
62 selectedPaths.setText(
"");
67 public String getContentPaths() {
70 if (currentFiles == null) {
73 StringBuilder b =
new StringBuilder();
74 for (File f : currentFiles) {
75 b.append(f.getAbsolutePath() );
82 public void setContentPath(String s) {
88 public String getContentType() {
89 return NbBundle.getMessage(this.getClass(),
"LocalFilesPanel.contentType.text");
93 public boolean validatePanel() {
98 public void select() {
103 public void reset() {
104 currentFiles.clear();
105 selectedPaths.setText(
"");
112 public synchronized void addPropertyChangeListener(PropertyChangeListener pcl) {
113 super.addPropertyChangeListener(pcl);
116 pcs =
new PropertyChangeSupport(
this);
119 pcs.addPropertyChangeListener(pcl);
123 public void removePropertyChangeListener(PropertyChangeListener pcl) {
124 super.removePropertyChangeListener(pcl);
126 pcs.removePropertyChangeListener(pcl);
131 public String toString() {
132 return NbBundle.getMessage(this.getClass(),
"LocalFilesDSProcessor.toString.text");
140 @SuppressWarnings(
"unchecked")
142 private
void initComponents() {
144 localFileChooser =
new javax.swing.JFileChooser();
145 jScrollPane1 =
new javax.swing.JScrollPane();
146 jTextArea1 =
new javax.swing.JTextArea();
147 selectButton =
new javax.swing.JButton();
148 infoLabel =
new javax.swing.JLabel();
149 clearButton =
new javax.swing.JButton();
150 jScrollPane2 =
new javax.swing.JScrollPane();
151 selectedPaths =
new javax.swing.JTextArea();
153 localFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonText"));
154 localFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonToolTipText"));
155 localFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.dialogTitle"));
156 localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
158 jTextArea1.setColumns(20);
159 jTextArea1.setRows(5);
160 jScrollPane1.setViewportView(jTextArea1);
162 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.text"));
163 selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.toolTipText"));
164 selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.actionCommand"));
165 selectButton.addActionListener(
new java.awt.event.ActionListener() {
166 public void actionPerformed(java.awt.event.ActionEvent evt) {
167 selectButtonActionPerformed(evt);
171 org.openide.awt.Mnemonics.setLocalizedText(infoLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.infoLabel.text"));
173 org.openide.awt.Mnemonics.setLocalizedText(clearButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.text"));
174 clearButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.toolTipText"));
175 clearButton.addActionListener(
new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
177 clearButtonActionPerformed(evt);
181 selectedPaths.setEditable(
false);
182 selectedPaths.setColumns(20);
183 selectedPaths.setRows(5);
184 selectedPaths.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectedPaths.toolTipText"));
185 jScrollPane2.setViewportView(selectedPaths);
187 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
188 this.setLayout(layout);
189 layout.setHorizontalGroup(
190 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191 .addGroup(layout.createSequentialGroup()
192 .addComponent(infoLabel)
193 .addGap(0, 0, Short.MAX_VALUE))
194 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
195 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
196 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
197 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
198 .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
199 .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
202 layout.setVerticalGroup(
203 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGroup(layout.createSequentialGroup()
205 .addComponent(infoLabel)
207 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(layout.createSequentialGroup()
209 .addComponent(selectButton)
210 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
211 .addComponent(clearButton))
212 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
217 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
218 int returnVal = localFileChooser.showOpenDialog(
this);
219 if (returnVal == JFileChooser.APPROVE_OPTION) {
220 File [] files = localFileChooser.getSelectedFiles();
221 for (File f : files) {
226 StringBuilder allPaths =
new StringBuilder();
227 for (File f : currentFiles) {
228 allPaths.append(f.getAbsolutePath()).append(
"\n");
230 this.selectedPaths.setText(allPaths.toString());
231 this.selectedPaths.setToolTipText(allPaths.toString());
235 if (!currentFiles.isEmpty()) {
243 pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
245 catch (Exception e) {
246 logger.log(Level.SEVERE,
"LocalFilesPanel listener threw exception", e);
247 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
248 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
249 MessageNotifyUtil.MessageType.ERROR);
253 private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
260 private javax.swing.JButton clearButton;
261 private javax.swing.JLabel infoLabel;
262 private javax.swing.JScrollPane jScrollPane1;
263 private javax.swing.JScrollPane jScrollPane2;
264 private javax.swing.JTextArea jTextArea1;
265 private javax.swing.JFileChooser localFileChooser;
266 private javax.swing.JButton selectButton;
267 private javax.swing.JTextArea selectedPaths;
static Logger getLogger(String name)