Autopsy  4.13.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  jLabel2 = 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  caseNameLabel.setFont(caseNameLabel.getFont().deriveFont(caseNameLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
234  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameLabel.text_1")); // NOI18N
235 
236  caseDirLabel.setFont(caseDirLabel.getFont().deriveFont(caseDirLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
237  org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirLabel.text")); // NOI18N
238 
239  caseNameTextField.setFont(caseNameTextField.getFont().deriveFont(caseNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
240  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameTextField.text_1")); // NOI18N
241 
242  caseParentDirTextField.setFont(caseParentDirTextField.getFont().deriveFont(caseParentDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
243  caseParentDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirTextField.text")); // NOI18N
244 
245  caseDirBrowseButton.setFont(caseDirBrowseButton.getFont().deriveFont(caseDirBrowseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
246  org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirBrowseButton.text")); // NOI18N
247  caseDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
248  public void actionPerformed(java.awt.event.ActionEvent evt) {
249  caseDirBrowseButtonActionPerformed(evt);
250  }
251  });
252 
253  jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
254  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.jLabel2.text_1")); // NOI18N
255 
256  caseDirTextField.setEditable(false);
257  caseDirTextField.setFont(caseDirTextField.getFont().deriveFont(caseDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
258  caseDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirTextField.text_1")); // NOI18N
259 
260  caseTypeButtonGroup.add(singleUserCaseRadioButton);
261  singleUserCaseRadioButton.setFont(singleUserCaseRadioButton.getFont().deriveFont(singleUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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  multiUserCaseRadioButton.setFont(multiUserCaseRadioButton.getFont().deriveFont(multiUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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.setFont(caseParentDirWarningLabel.getFont().deriveFont(caseParentDirWarningLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
279  caseParentDirWarningLabel.setForeground(new java.awt.Color(255, 0, 0));
280  org.openide.awt.Mnemonics.setLocalizedText(caseParentDirWarningLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirWarningLabel.text")); // NOI18N
281 
282  caseTypeLabel.setFont(caseTypeLabel.getFont().deriveFont(caseTypeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
283  org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseTypeLabel.text")); // NOI18N
284 
285  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
286  this.setLayout(layout);
287  layout.setHorizontalGroup(
288  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289  .addGroup(layout.createSequentialGroup()
290  .addContainerGap()
291  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292  .addGroup(layout.createSequentialGroup()
293  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294  .addComponent(jLabel2)
295  .addGroup(layout.createSequentialGroup()
296  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
297  .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
298  .addGroup(layout.createSequentialGroup()
299  .addComponent(caseNameLabel)
300  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
301  .addComponent(caseNameTextField))
302  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
303  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304  .addComponent(caseDirLabel)
305  .addComponent(caseTypeLabel))
306  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
307  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308  .addGroup(layout.createSequentialGroup()
309  .addComponent(singleUserCaseRadioButton)
310  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
311  .addComponent(multiUserCaseRadioButton)
312  .addGap(0, 192, Short.MAX_VALUE))
313  .addComponent(caseParentDirTextField))))
314  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
315  .addComponent(caseDirBrowseButton)))
316  .addContainerGap())
317  .addGroup(layout.createSequentialGroup()
318  .addComponent(caseParentDirWarningLabel)
319  .addGap(0, 0, Short.MAX_VALUE))))
320  );
321 
322  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
323 
324  layout.setVerticalGroup(
325  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326  .addGroup(layout.createSequentialGroup()
327  .addContainerGap()
328  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
329  .addComponent(caseNameLabel)
330  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
331  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
332  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
333  .addComponent(caseDirLabel)
334  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
335  .addComponent(caseDirBrowseButton))
336  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
337  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
338  .addComponent(singleUserCaseRadioButton)
339  .addComponent(multiUserCaseRadioButton)
340  .addComponent(caseTypeLabel))
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
342  .addComponent(jLabel2)
343  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
344  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
345  .addGap(27, 27, 27)
346  .addComponent(caseParentDirWarningLabel)
347  .addContainerGap(115, Short.MAX_VALUE))
348  );
349  }// </editor-fold>//GEN-END:initComponents
350 
358  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
359  fileChooser.setDragEnabled(false);
360  if (!caseParentDirTextField.getText().trim().equals("")) {
361  fileChooser.setCurrentDirectory(new File(caseParentDirTextField.getText()));
362  }
363  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
364  int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
365  "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
366  if (JFileChooser.APPROVE_OPTION == choice) {
367  String path = fileChooser.getSelectedFile().getPath();
368  caseParentDirTextField.setText(path);
369  }
370  }//GEN-LAST:event_caseDirBrowseButtonActionPerformed
371 
372  private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleUserCaseRadioButtonActionPerformed
373  handleUpdate();
374  }//GEN-LAST:event_singleUserCaseRadioButtonActionPerformed
375 
376  private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiUserCaseRadioButtonActionPerformed
377  handleUpdate();
378  }//GEN-LAST:event_multiUserCaseRadioButtonActionPerformed
379 
380  // Variables declaration - do not modify//GEN-BEGIN:variables
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.JLabel jLabel2;
391  private javax.swing.JRadioButton multiUserCaseRadioButton;
392  private javax.swing.JRadioButton singleUserCaseRadioButton;
393  // End of variables declaration//GEN-END:variables
394 
401  @Override
402  public void insertUpdate(DocumentEvent e) {
403  this.wizPanel.fireChangeEvent();
404  updateUI(e);
405  }
406 
414  @Override
415  public void removeUpdate(DocumentEvent e) {
416  this.wizPanel.fireChangeEvent();
417  updateUI(e);
418  }
419 
425  @Override
426  public void changedUpdate(DocumentEvent e) {
427  this.wizPanel.fireChangeEvent();
428  updateUI(e);
429  }
430 
438  public void updateUI(DocumentEvent e) {
439 
440  String caseName = getCaseName();
441  String parentDir = getCaseParentDir();
442 
443  if (!caseName.equals("") && !parentDir.equals("")) {
444  caseDirTextField.setText(parentDir + caseName);
445  wizPanel.setIsFinish(true);
446  } else {
447  caseDirTextField.setText("");
448  wizPanel.setIsFinish(false);
449  }
450  }
451 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.