Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
NewCaseVisualPanel1.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2021 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 
22 import java.awt.Component;
23 import org.openide.util.NbBundle;
24 
25 import java.io.File;
26 import javax.swing.JFileChooser;
27 import javax.swing.JPanel;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
34 
38 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39 final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
40 
41  private final JFileChooserFactory fileChooserHelper = new JFileChooserFactory();
42  private final NewCaseWizardPanel1 wizPanel;
43 
49  NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) {
50  this.wizPanel = wizPanel;
51  initComponents();
52  TextFieldListener listener = new TextFieldListener();
53  caseNameTextField.getDocument().addDocumentListener(listener);
54  caseParentDirTextField.getDocument().addDocumentListener(listener);
55  caseParentDirWarningLabel.setVisible(false);
56  }
57 
63  void readSettings() {
64  caseNameTextField.setText("");
65  if (FeatureAccessUtils.canCreateMultiUserCases()) {
66  multiUserCaseRadioButton.setEnabled(true);
67  multiUserCaseRadioButton.setSelected(true);
68  } else {
69  multiUserCaseRadioButton.setEnabled(false);
70  singleUserCaseRadioButton.setSelected(true);
71  }
72  validateSettings();
73  }
74 
81  @Override
82  public String getName() {
83  return NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.getName.text");
84  }
85 
91  String getCaseName() {
92  return this.caseNameTextField.getText().trim();
93  }
94 
101  void setCaseParentDir(String caseParentDir) {
102  caseParentDirTextField.setText(caseParentDir);
103  validateSettings();
104  }
105 
112  String getCaseParentDir() {
113  String parentDir = this.caseParentDirTextField.getText().trim();
114  if (parentDir.endsWith(File.separator) == false) {
115  parentDir = parentDir + File.separator;
116  }
117  return parentDir;
118  }
119 
125  CaseType getCaseType() {
126  CaseType value = CaseType.SINGLE_USER_CASE;
127  if (singleUserCaseRadioButton.isSelected()) {
128  value = CaseType.SINGLE_USER_CASE;
129  } else if (multiUserCaseRadioButton.isSelected()) {
130  value = CaseType.MULTI_USER_CASE;
131  }
132  return value;
133  }
134 
140  private void handleUpdate() {
141  wizPanel.fireChangeEvent();
142  validateSettings();
143  }
144 
149  private void validateSettings() {
155  caseParentDirWarningLabel.setVisible(false);
156  String parentDir = getCaseParentDir();
157  if (!PathValidator.isValidForCaseType(parentDir, getCaseType())) {
158  if (getCaseType() == CaseType.MULTI_USER_CASE) {
159  caseParentDirWarningLabel.setVisible(true);
160  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"));
161  } else {
162  // disable the "Next" button
163  caseParentDirWarningLabel.setVisible(true);
164  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.uncPath.error"));
165  wizPanel.setIsFinish(false);
166  return;
167  }
168  }
169 
174  if(!PathValidator.isValidForRunningOnTarget(parentDir)){
175  caseParentDirWarningLabel.setVisible(true);
176  if(PlatformUtil.isWindowsOS()){
177  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveWindowsError.text" ));
178  } else if(System.getProperty("os.name").toLowerCase().contains("nux")) {
179  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveLinuxError.text"));
180  }
181  }
182 
188  String caseName = getCaseName();
189  if (!caseName.equals("") && !parentDir.equals("")) {
190  caseDirTextField.setText(parentDir + caseName);
191  wizPanel.setIsFinish(true);
192  } else {
193  caseDirTextField.setText("");
194  wizPanel.setIsFinish(false);
195  }
196  }
197 
202  private class TextFieldListener implements DocumentListener {
203 
204  @Override
205  public void insertUpdate(DocumentEvent e) {
206  handleUpdate();
207  }
208 
209  @Override
210  public void removeUpdate(DocumentEvent e) {
211  handleUpdate();
212  }
213 
214  @Override
215  public void changedUpdate(DocumentEvent e) {
216  handleUpdate();
217  }
218 
219  }
220 
226  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
227  private void initComponents() {
228 
229  caseTypeButtonGroup = new javax.swing.ButtonGroup();
230  caseNameLabel = new javax.swing.JLabel();
231  caseDirLabel = new javax.swing.JLabel();
232  caseNameTextField = new javax.swing.JTextField();
233  caseParentDirTextField = new javax.swing.JTextField();
234  caseDirBrowseButton = new javax.swing.JButton();
235  caseDataStoredLabel = new javax.swing.JLabel();
236  caseDirTextField = new javax.swing.JTextField();
237  singleUserCaseRadioButton = new javax.swing.JRadioButton();
238  multiUserCaseRadioButton = new javax.swing.JRadioButton();
239  caseParentDirWarningLabel = new javax.swing.JLabel();
240  caseTypeLabel = new javax.swing.JLabel();
241 
242  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameLabel.text_1")); // NOI18N
243 
244  org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirLabel.text")); // NOI18N
245 
246  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameTextField.text_1")); // NOI18N
247 
248  caseParentDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirTextField.text")); // NOI18N
249 
250  org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirBrowseButton.text")); // NOI18N
251  caseDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
252  public void actionPerformed(java.awt.event.ActionEvent evt) {
253  caseDirBrowseButtonActionPerformed(evt);
254  }
255  });
256 
257  org.openide.awt.Mnemonics.setLocalizedText(caseDataStoredLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDataStoredLabel.text_1")); // NOI18N
258 
259  caseDirTextField.setEditable(false);
260  caseDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirTextField.text_1")); // NOI18N
261 
262  caseTypeButtonGroup.add(singleUserCaseRadioButton);
263  org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.singleUserCaseRadioButton.text")); // NOI18N
264  singleUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
265  public void actionPerformed(java.awt.event.ActionEvent evt) {
266  singleUserCaseRadioButtonActionPerformed(evt);
267  }
268  });
269 
270  caseTypeButtonGroup.add(multiUserCaseRadioButton);
271  org.openide.awt.Mnemonics.setLocalizedText(multiUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.multiUserCaseRadioButton.text")); // NOI18N
272  multiUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
273  public void actionPerformed(java.awt.event.ActionEvent evt) {
274  multiUserCaseRadioButtonActionPerformed(evt);
275  }
276  });
277 
278  caseParentDirWarningLabel.setForeground(new java.awt.Color(255, 0, 0));
279  org.openide.awt.Mnemonics.setLocalizedText(caseParentDirWarningLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirWarningLabel.text")); // NOI18N
280 
281  org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseTypeLabel.text")); // NOI18N
282 
283  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
284  this.setLayout(layout);
285  layout.setHorizontalGroup(
286  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287  .addGroup(layout.createSequentialGroup()
288  .addContainerGap()
289  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290  .addGroup(layout.createSequentialGroup()
291  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292  .addComponent(caseDataStoredLabel)
293  .addGroup(layout.createSequentialGroup()
294  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
295  .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
296  .addGroup(layout.createSequentialGroup()
297  .addComponent(caseNameLabel)
298  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
299  .addComponent(caseNameTextField))
300  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
301  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302  .addComponent(caseDirLabel)
303  .addComponent(caseTypeLabel))
304  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306  .addGroup(layout.createSequentialGroup()
307  .addComponent(singleUserCaseRadioButton)
308  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
309  .addComponent(multiUserCaseRadioButton)
310  .addGap(0, 192, Short.MAX_VALUE))
311  .addComponent(caseParentDirTextField))))
312  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
313  .addComponent(caseDirBrowseButton)))
314  .addContainerGap())
315  .addGroup(layout.createSequentialGroup()
316  .addComponent(caseParentDirWarningLabel)
317  .addGap(0, 0, Short.MAX_VALUE))))
318  );
319 
320  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
321 
322  layout.setVerticalGroup(
323  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324  .addGroup(layout.createSequentialGroup()
325  .addContainerGap()
326  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
327  .addComponent(caseNameLabel)
328  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
329  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331  .addComponent(caseDirLabel)
332  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
333  .addComponent(caseDirBrowseButton))
334  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
335  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
336  .addComponent(singleUserCaseRadioButton)
337  .addComponent(multiUserCaseRadioButton)
338  .addComponent(caseTypeLabel))
339  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
340  .addComponent(caseDataStoredLabel)
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
343  .addGap(27, 27, 27)
344  .addComponent(caseParentDirWarningLabel)
345  .addContainerGap(115, Short.MAX_VALUE))
346  );
347  }// </editor-fold>//GEN-END:initComponents
348 
356  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
357  JFileChooser fileChooser = fileChooserHelper.getChooser();
358  fileChooser.setDragEnabled(false);
359  if (!caseParentDirTextField.getText().trim().isEmpty()) {
360  fileChooser.setCurrentDirectory(new File(caseParentDirTextField.getText()));
361  }
362  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
363  int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
364  "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
365  if (JFileChooser.APPROVE_OPTION == choice) {
366  String path = fileChooser.getSelectedFile().getPath();
367  caseParentDirTextField.setText(path);
368  }
369  }//GEN-LAST:event_caseDirBrowseButtonActionPerformed
370 
371  private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleUserCaseRadioButtonActionPerformed
372  handleUpdate();
373  }//GEN-LAST:event_singleUserCaseRadioButtonActionPerformed
374 
375  private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiUserCaseRadioButtonActionPerformed
376  handleUpdate();
377  }//GEN-LAST:event_multiUserCaseRadioButtonActionPerformed
378 
379  // Variables declaration - do not modify//GEN-BEGIN:variables
380  private javax.swing.JLabel caseDataStoredLabel;
381  private javax.swing.JButton caseDirBrowseButton;
382  private javax.swing.JLabel caseDirLabel;
383  private javax.swing.JTextField caseDirTextField;
384  private javax.swing.JLabel caseNameLabel;
385  private javax.swing.JTextField caseNameTextField;
386  private javax.swing.JTextField caseParentDirTextField;
387  private javax.swing.JLabel caseParentDirWarningLabel;
388  private javax.swing.ButtonGroup caseTypeButtonGroup;
389  private javax.swing.JLabel caseTypeLabel;
390  private javax.swing.JRadioButton multiUserCaseRadioButton;
391  private javax.swing.JRadioButton singleUserCaseRadioButton;
392  // End of variables declaration//GEN-END:variables
393 
400  @Override
401  public void insertUpdate(DocumentEvent e) {
402  this.wizPanel.fireChangeEvent();
403  updateUI(e);
404  }
405 
413  @Override
414  public void removeUpdate(DocumentEvent e) {
415  this.wizPanel.fireChangeEvent();
416  updateUI(e);
417  }
418 
424  @Override
425  public void changedUpdate(DocumentEvent e) {
426  this.wizPanel.fireChangeEvent();
427  updateUI(e);
428  }
429 
437  public void updateUI(DocumentEvent e) {
438 
439  String caseName = getCaseName();
440  String parentDir = getCaseParentDir();
441 
442  if (!caseName.equals("") && !parentDir.equals("")) {
443  caseDirTextField.setText(parentDir + caseName);
444  wizPanel.setIsFinish(true);
445  } else {
446  caseDirTextField.setText("");
447  wizPanel.setIsFinish(false);
448  }
449  }
450 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.