Autopsy  4.8.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 
21 import java.awt.Component;
22 import org.openide.util.NbBundle;
23 
24 import java.io.File;
25 import javax.swing.JFileChooser;
26 import javax.swing.JPanel;
27 import javax.swing.event.DocumentEvent;
28 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 (UserPreferences.getIsMultiUserModeEnabled()) {
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();
92  }
93 
100  void setCaseParentDir(String caseParentDir) {
101  caseParentDirTextField.setText(caseParentDir);
102  validateSettings();
103  }
104 
111  String getCaseParentDir() {
112  String parentDir = this.caseParentDirTextField.getText();
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() {
153  caseParentDirWarningLabel.setVisible(false);
154  String parentDir = getCaseParentDir();
155  if (!PathValidator.isValidForMultiUserCase(parentDir, getCaseType())) {
156  caseParentDirWarningLabel.setVisible(true);
157  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"));
158  }
159 
164  if(!PathValidator.isValidForRunningOnTarget(parentDir)){
165  caseParentDirWarningLabel.setVisible(true);
166  if(PlatformUtil.isWindowsOS()){
167  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveWindowsError.text" ));
168  } else if(System.getProperty("os.name").toLowerCase().contains("nux")) {
169  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnInternalDriveLinuxError.text"));
170  }
171  }
172 
178  String caseName = getCaseName();
179  if (!caseName.equals("") && !parentDir.equals("")) {
180  caseDirTextField.setText(parentDir + caseName);
181  wizPanel.setIsFinish(true);
182  } else {
183  caseDirTextField.setText("");
184  wizPanel.setIsFinish(false);
185  }
186  }
187 
192  private class TextFieldListener implements DocumentListener {
193 
194  @Override
195  public void insertUpdate(DocumentEvent e) {
196  handleUpdate();
197  }
198 
199  @Override
200  public void removeUpdate(DocumentEvent e) {
201  handleUpdate();
202  }
203 
204  @Override
205  public void changedUpdate(DocumentEvent e) {
206  handleUpdate();
207  }
208 
209  }
210 
216  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
217  private void initComponents() {
218 
219  caseTypeButtonGroup = new javax.swing.ButtonGroup();
220  caseNameLabel = new javax.swing.JLabel();
221  caseDirLabel = new javax.swing.JLabel();
222  caseNameTextField = new javax.swing.JTextField();
223  caseParentDirTextField = new javax.swing.JTextField();
224  caseDirBrowseButton = new javax.swing.JButton();
225  jLabel2 = new javax.swing.JLabel();
226  caseDirTextField = new javax.swing.JTextField();
227  singleUserCaseRadioButton = new javax.swing.JRadioButton();
228  multiUserCaseRadioButton = new javax.swing.JRadioButton();
229  caseParentDirWarningLabel = new javax.swing.JLabel();
230  caseTypeLabel = new javax.swing.JLabel();
231 
232  caseNameLabel.setFont(caseNameLabel.getFont().deriveFont(caseNameLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
233  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameLabel.text_1")); // NOI18N
234 
235  caseDirLabel.setFont(caseDirLabel.getFont().deriveFont(caseDirLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
236  org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirLabel.text")); // NOI18N
237 
238  caseNameTextField.setFont(caseNameTextField.getFont().deriveFont(caseNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
239  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameTextField.text_1")); // NOI18N
240 
241  caseParentDirTextField.setFont(caseParentDirTextField.getFont().deriveFont(caseParentDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
242  caseParentDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirTextField.text")); // NOI18N
243 
244  caseDirBrowseButton.setFont(caseDirBrowseButton.getFont().deriveFont(caseDirBrowseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
245  org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirBrowseButton.text")); // NOI18N
246  caseDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
247  public void actionPerformed(java.awt.event.ActionEvent evt) {
248  caseDirBrowseButtonActionPerformed(evt);
249  }
250  });
251 
252  jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
253  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.jLabel2.text_1")); // NOI18N
254 
255  caseDirTextField.setEditable(false);
256  caseDirTextField.setFont(caseDirTextField.getFont().deriveFont(caseDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
257  caseDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirTextField.text_1")); // NOI18N
258 
259  caseTypeButtonGroup.add(singleUserCaseRadioButton);
260  singleUserCaseRadioButton.setFont(singleUserCaseRadioButton.getFont().deriveFont(singleUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
261  org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.singleUserCaseRadioButton.text")); // NOI18N
262  singleUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
263  public void actionPerformed(java.awt.event.ActionEvent evt) {
264  singleUserCaseRadioButtonActionPerformed(evt);
265  }
266  });
267 
268  caseTypeButtonGroup.add(multiUserCaseRadioButton);
269  multiUserCaseRadioButton.setFont(multiUserCaseRadioButton.getFont().deriveFont(multiUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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.setFont(caseParentDirWarningLabel.getFont().deriveFont(caseParentDirWarningLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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  caseTypeLabel.setFont(caseTypeLabel.getFont().deriveFont(caseTypeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
282  org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseTypeLabel.text")); // NOI18N
283 
284  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
285  this.setLayout(layout);
286  layout.setHorizontalGroup(
287  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288  .addGroup(layout.createSequentialGroup()
289  .addContainerGap()
290  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291  .addGroup(layout.createSequentialGroup()
292  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293  .addComponent(jLabel2)
294  .addGroup(layout.createSequentialGroup()
295  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
296  .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
297  .addGroup(layout.createSequentialGroup()
298  .addComponent(caseNameLabel)
299  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
300  .addComponent(caseNameTextField))
301  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
302  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
303  .addComponent(caseDirLabel)
304  .addComponent(caseTypeLabel))
305  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
306  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
307  .addGroup(layout.createSequentialGroup()
308  .addComponent(singleUserCaseRadioButton)
309  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
310  .addComponent(multiUserCaseRadioButton)
311  .addGap(0, 192, Short.MAX_VALUE))
312  .addComponent(caseParentDirTextField))))
313  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
314  .addComponent(caseDirBrowseButton)))
315  .addContainerGap())
316  .addGroup(layout.createSequentialGroup()
317  .addComponent(caseParentDirWarningLabel)
318  .addGap(0, 0, Short.MAX_VALUE))))
319  );
320 
321  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
322 
323  layout.setVerticalGroup(
324  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
325  .addGroup(layout.createSequentialGroup()
326  .addContainerGap()
327  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
328  .addComponent(caseNameLabel)
329  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
330  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
331  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
332  .addComponent(caseDirLabel)
333  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
334  .addComponent(caseDirBrowseButton))
335  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
336  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
337  .addComponent(singleUserCaseRadioButton)
338  .addComponent(multiUserCaseRadioButton)
339  .addComponent(caseTypeLabel))
340  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
341  .addComponent(jLabel2)
342  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
343  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
344  .addGap(27, 27, 27)
345  .addComponent(caseParentDirWarningLabel)
346  .addContainerGap(115, Short.MAX_VALUE))
347  );
348  }// </editor-fold>//GEN-END:initComponents
349 
357  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
358  fileChooser.setDragEnabled(false);
359  if (!caseParentDirTextField.getText().trim().equals("")) {
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.JButton caseDirBrowseButton;
381  private javax.swing.JLabel caseDirLabel;
382  private javax.swing.JTextField caseDirTextField;
383  private javax.swing.JLabel caseNameLabel;
384  private javax.swing.JTextField caseNameTextField;
385  private javax.swing.JTextField caseParentDirTextField;
386  private javax.swing.JLabel caseParentDirWarningLabel;
387  private javax.swing.ButtonGroup caseTypeButtonGroup;
388  private javax.swing.JLabel caseTypeLabel;
389  private javax.swing.JLabel jLabel2;
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-2018 Basis Technology. Generated on: Thu Oct 4 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.