Autopsy  4.14.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-2018 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 JFileChooser fileChooser = new JFileChooser();
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() {
154  caseParentDirWarningLabel.setVisible(false);
155  String parentDir = getCaseParentDir();
156  if (!PathValidator.isValidForMultiUserCase(parentDir, getCaseType())) {
157  caseParentDirWarningLabel.setVisible(true);
158  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"));
159  }
160 
165  if(!PathValidator.isValidForRunningOnTarget(parentDir)){
166  caseParentDirWarningLabel.setVisible(true);
167  if(PlatformUtil.isWindowsOS()){
168  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveWindowsError.text" ));
169  } else if(System.getProperty("os.name").toLowerCase().contains("nux")) {
170  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveLinuxError.text"));
171  }
172  }
173 
179  String caseName = getCaseName();
180  if (!caseName.equals("") && !parentDir.equals("")) {
181  caseDirTextField.setText(parentDir + caseName);
182  wizPanel.setIsFinish(true);
183  } else {
184  caseDirTextField.setText("");
185  wizPanel.setIsFinish(false);
186  }
187  }
188 
193  private class TextFieldListener implements DocumentListener {
194 
195  @Override
196  public void insertUpdate(DocumentEvent e) {
197  handleUpdate();
198  }
199 
200  @Override
201  public void removeUpdate(DocumentEvent e) {
202  handleUpdate();
203  }
204 
205  @Override
206  public void changedUpdate(DocumentEvent e) {
207  handleUpdate();
208  }
209 
210  }
211 
217  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
218  private void initComponents() {
219 
220  caseTypeButtonGroup = new javax.swing.ButtonGroup();
221  caseNameLabel = new javax.swing.JLabel();
222  caseDirLabel = new javax.swing.JLabel();
223  caseNameTextField = new javax.swing.JTextField();
224  caseParentDirTextField = new javax.swing.JTextField();
225  caseDirBrowseButton = new javax.swing.JButton();
226  caseDataStoredLabel = new javax.swing.JLabel();
227  caseDirTextField = new javax.swing.JTextField();
228  singleUserCaseRadioButton = new javax.swing.JRadioButton();
229  multiUserCaseRadioButton = new javax.swing.JRadioButton();
230  caseParentDirWarningLabel = new javax.swing.JLabel();
231  caseTypeLabel = new javax.swing.JLabel();
232 
233  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameLabel.text_1")); // NOI18N
234 
235  org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirLabel.text")); // NOI18N
236 
237  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameTextField.text_1")); // NOI18N
238 
239  caseParentDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirTextField.text")); // NOI18N
240 
241  org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirBrowseButton.text")); // NOI18N
242  caseDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
243  public void actionPerformed(java.awt.event.ActionEvent evt) {
244  caseDirBrowseButtonActionPerformed(evt);
245  }
246  });
247 
248  org.openide.awt.Mnemonics.setLocalizedText(caseDataStoredLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDataStoredLabel.text_1")); // NOI18N
249 
250  caseDirTextField.setEditable(false);
251  caseDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirTextField.text_1")); // NOI18N
252 
253  caseTypeButtonGroup.add(singleUserCaseRadioButton);
254  org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.singleUserCaseRadioButton.text")); // NOI18N
255  singleUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
256  public void actionPerformed(java.awt.event.ActionEvent evt) {
257  singleUserCaseRadioButtonActionPerformed(evt);
258  }
259  });
260 
261  caseTypeButtonGroup.add(multiUserCaseRadioButton);
262  org.openide.awt.Mnemonics.setLocalizedText(multiUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.multiUserCaseRadioButton.text")); // NOI18N
263  multiUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
264  public void actionPerformed(java.awt.event.ActionEvent evt) {
265  multiUserCaseRadioButtonActionPerformed(evt);
266  }
267  });
268 
269  caseParentDirWarningLabel.setForeground(new java.awt.Color(255, 0, 0));
270  org.openide.awt.Mnemonics.setLocalizedText(caseParentDirWarningLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirWarningLabel.text")); // NOI18N
271 
272  org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseTypeLabel.text")); // NOI18N
273 
274  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
275  this.setLayout(layout);
276  layout.setHorizontalGroup(
277  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278  .addGroup(layout.createSequentialGroup()
279  .addContainerGap()
280  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281  .addGroup(layout.createSequentialGroup()
282  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283  .addComponent(caseDataStoredLabel)
284  .addGroup(layout.createSequentialGroup()
285  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
286  .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
287  .addGroup(layout.createSequentialGroup()
288  .addComponent(caseNameLabel)
289  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
290  .addComponent(caseNameTextField))
291  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
292  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293  .addComponent(caseDirLabel)
294  .addComponent(caseTypeLabel))
295  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297  .addGroup(layout.createSequentialGroup()
298  .addComponent(singleUserCaseRadioButton)
299  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
300  .addComponent(multiUserCaseRadioButton)
301  .addGap(0, 192, Short.MAX_VALUE))
302  .addComponent(caseParentDirTextField))))
303  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
304  .addComponent(caseDirBrowseButton)))
305  .addContainerGap())
306  .addGroup(layout.createSequentialGroup()
307  .addComponent(caseParentDirWarningLabel)
308  .addGap(0, 0, Short.MAX_VALUE))))
309  );
310 
311  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
312 
313  layout.setVerticalGroup(
314  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315  .addGroup(layout.createSequentialGroup()
316  .addContainerGap()
317  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318  .addComponent(caseNameLabel)
319  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
320  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
321  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
322  .addComponent(caseDirLabel)
323  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
324  .addComponent(caseDirBrowseButton))
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
326  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
327  .addComponent(singleUserCaseRadioButton)
328  .addComponent(multiUserCaseRadioButton)
329  .addComponent(caseTypeLabel))
330  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
331  .addComponent(caseDataStoredLabel)
332  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
333  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
334  .addGap(27, 27, 27)
335  .addComponent(caseParentDirWarningLabel)
336  .addContainerGap(115, Short.MAX_VALUE))
337  );
338  }// </editor-fold>//GEN-END:initComponents
339 
347  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
348  fileChooser.setDragEnabled(false);
349  if (!caseParentDirTextField.getText().trim().equals("")) {
350  fileChooser.setCurrentDirectory(new File(caseParentDirTextField.getText()));
351  }
352  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
353  int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
354  "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
355  if (JFileChooser.APPROVE_OPTION == choice) {
356  String path = fileChooser.getSelectedFile().getPath();
357  caseParentDirTextField.setText(path);
358  }
359  }//GEN-LAST:event_caseDirBrowseButtonActionPerformed
360 
361  private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleUserCaseRadioButtonActionPerformed
362  handleUpdate();
363  }//GEN-LAST:event_singleUserCaseRadioButtonActionPerformed
364 
365  private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiUserCaseRadioButtonActionPerformed
366  handleUpdate();
367  }//GEN-LAST:event_multiUserCaseRadioButtonActionPerformed
368 
369  // Variables declaration - do not modify//GEN-BEGIN:variables
370  private javax.swing.JLabel caseDataStoredLabel;
371  private javax.swing.JButton caseDirBrowseButton;
372  private javax.swing.JLabel caseDirLabel;
373  private javax.swing.JTextField caseDirTextField;
374  private javax.swing.JLabel caseNameLabel;
375  private javax.swing.JTextField caseNameTextField;
376  private javax.swing.JTextField caseParentDirTextField;
377  private javax.swing.JLabel caseParentDirWarningLabel;
378  private javax.swing.ButtonGroup caseTypeButtonGroup;
379  private javax.swing.JLabel caseTypeLabel;
380  private javax.swing.JRadioButton multiUserCaseRadioButton;
381  private javax.swing.JRadioButton singleUserCaseRadioButton;
382  // End of variables declaration//GEN-END:variables
383 
390  @Override
391  public void insertUpdate(DocumentEvent e) {
392  this.wizPanel.fireChangeEvent();
393  updateUI(e);
394  }
395 
403  @Override
404  public void removeUpdate(DocumentEvent e) {
405  this.wizPanel.fireChangeEvent();
406  updateUI(e);
407  }
408 
414  @Override
415  public void changedUpdate(DocumentEvent e) {
416  this.wizPanel.fireChangeEvent();
417  updateUI(e);
418  }
419 
427  public void updateUI(DocumentEvent e) {
428 
429  String caseName = getCaseName();
430  String parentDir = getCaseParentDir();
431 
432  if (!caseName.equals("") && !parentDir.equals("")) {
433  caseDirTextField.setText(parentDir + caseName);
434  wizPanel.setIsFinish(true);
435  } else {
436  caseDirTextField.setText("");
437  wizPanel.setIsFinish(false);
438  }
439  }
440 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.