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

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.