Autopsy  4.7.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;
32 
36 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
37 final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
38 
39  private final JFileChooser fileChooser = new JFileChooser();
40  private final NewCaseWizardPanel1 wizPanel;
41 
47  NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) {
48  this.wizPanel = wizPanel;
49  initComponents();
50  TextFieldListener listener = new TextFieldListener();
51  caseNameTextField.getDocument().addDocumentListener(listener);
52  caseParentDirTextField.getDocument().addDocumentListener(listener);
53  caseParentDirWarningLabel.setVisible(false);
54  }
55 
61  void readSettings() {
62  caseNameTextField.setText("");
63  if (UserPreferences.getIsMultiUserModeEnabled()) {
64  multiUserCaseRadioButton.setEnabled(true);
65  multiUserCaseRadioButton.setSelected(true);
66  } else {
67  multiUserCaseRadioButton.setEnabled(false);
68  singleUserCaseRadioButton.setSelected(true);
69  }
70  validateSettings();
71  }
72 
79  @Override
80  public String getName() {
81  return NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.getName.text");
82  }
83 
89  String getCaseName() {
90  return this.caseNameTextField.getText();
91  }
92 
99  void setCaseParentDir(String caseParentDir) {
100  caseParentDirTextField.setText(caseParentDir);
101  validateSettings();
102  }
103 
110  String getCaseParentDir() {
111  String parentDir = this.caseParentDirTextField.getText();
112  if (parentDir.endsWith(File.separator) == false) {
113  parentDir = parentDir + File.separator;
114  }
115  return parentDir;
116  }
117 
123  CaseType getCaseType() {
124  CaseType value = CaseType.SINGLE_USER_CASE;
125  if (singleUserCaseRadioButton.isSelected()) {
126  value = CaseType.SINGLE_USER_CASE;
127  } else if (multiUserCaseRadioButton.isSelected()) {
128  value = CaseType.MULTI_USER_CASE;
129  }
130  return value;
131  }
132 
138  private void handleUpdate() {
139  wizPanel.fireChangeEvent();
140  validateSettings();
141  }
142 
147  private void validateSettings() {
152  caseParentDirWarningLabel.setVisible(false);
153  String parentDir = getCaseParentDir();
154  if (!PathValidator.isValid(parentDir, getCaseType())) {
155  caseParentDirWarningLabel.setVisible(true);
156  caseParentDirWarningLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"));
157  }
158 
164  String caseName = getCaseName();
165  if (!caseName.equals("") && !parentDir.equals("")) {
166  caseDirTextField.setText(parentDir + caseName);
167  wizPanel.setIsFinish(true);
168  } else {
169  caseDirTextField.setText("");
170  wizPanel.setIsFinish(false);
171  }
172  }
173 
178  private class TextFieldListener implements DocumentListener {
179 
180  @Override
181  public void insertUpdate(DocumentEvent e) {
182  handleUpdate();
183  }
184 
185  @Override
186  public void removeUpdate(DocumentEvent e) {
187  handleUpdate();
188  }
189 
190  @Override
191  public void changedUpdate(DocumentEvent e) {
192  handleUpdate();
193  }
194 
195  }
196 
202  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
203  private void initComponents() {
204 
205  caseTypeButtonGroup = new javax.swing.ButtonGroup();
206  caseNameLabel = new javax.swing.JLabel();
207  caseDirLabel = new javax.swing.JLabel();
208  caseNameTextField = new javax.swing.JTextField();
209  caseParentDirTextField = new javax.swing.JTextField();
210  caseDirBrowseButton = new javax.swing.JButton();
211  jLabel2 = new javax.swing.JLabel();
212  caseDirTextField = new javax.swing.JTextField();
213  singleUserCaseRadioButton = new javax.swing.JRadioButton();
214  multiUserCaseRadioButton = new javax.swing.JRadioButton();
215  caseParentDirWarningLabel = new javax.swing.JLabel();
216  caseTypeLabel = new javax.swing.JLabel();
217 
218  caseNameLabel.setFont(caseNameLabel.getFont().deriveFont(caseNameLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
219  org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameLabel.text_1")); // NOI18N
220 
221  caseDirLabel.setFont(caseDirLabel.getFont().deriveFont(caseDirLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
222  org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirLabel.text")); // NOI18N
223 
224  caseNameTextField.setFont(caseNameTextField.getFont().deriveFont(caseNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
225  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseNameTextField.text_1")); // NOI18N
226 
227  caseParentDirTextField.setFont(caseParentDirTextField.getFont().deriveFont(caseParentDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
228  caseParentDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirTextField.text")); // NOI18N
229 
230  caseDirBrowseButton.setFont(caseDirBrowseButton.getFont().deriveFont(caseDirBrowseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
231  org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirBrowseButton.text")); // NOI18N
232  caseDirBrowseButton.addActionListener(new java.awt.event.ActionListener() {
233  public void actionPerformed(java.awt.event.ActionEvent evt) {
234  caseDirBrowseButtonActionPerformed(evt);
235  }
236  });
237 
238  jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
239  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.jLabel2.text_1")); // NOI18N
240 
241  caseDirTextField.setEditable(false);
242  caseDirTextField.setFont(caseDirTextField.getFont().deriveFont(caseDirTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
243  caseDirTextField.setText(org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseDirTextField.text_1")); // NOI18N
244 
245  caseTypeButtonGroup.add(singleUserCaseRadioButton);
246  singleUserCaseRadioButton.setFont(singleUserCaseRadioButton.getFont().deriveFont(singleUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
247  org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.singleUserCaseRadioButton.text")); // NOI18N
248  singleUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
249  public void actionPerformed(java.awt.event.ActionEvent evt) {
250  singleUserCaseRadioButtonActionPerformed(evt);
251  }
252  });
253 
254  caseTypeButtonGroup.add(multiUserCaseRadioButton);
255  multiUserCaseRadioButton.setFont(multiUserCaseRadioButton.getFont().deriveFont(multiUserCaseRadioButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
256  org.openide.awt.Mnemonics.setLocalizedText(multiUserCaseRadioButton, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.multiUserCaseRadioButton.text")); // NOI18N
257  multiUserCaseRadioButton.addActionListener(new java.awt.event.ActionListener() {
258  public void actionPerformed(java.awt.event.ActionEvent evt) {
259  multiUserCaseRadioButtonActionPerformed(evt);
260  }
261  });
262 
263  caseParentDirWarningLabel.setFont(caseParentDirWarningLabel.getFont().deriveFont(caseParentDirWarningLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
264  caseParentDirWarningLabel.setForeground(new java.awt.Color(255, 0, 0));
265  org.openide.awt.Mnemonics.setLocalizedText(caseParentDirWarningLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseParentDirWarningLabel.text")); // NOI18N
266 
267  caseTypeLabel.setFont(caseTypeLabel.getFont().deriveFont(caseTypeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
268  org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.caseTypeLabel.text")); // NOI18N
269 
270  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
271  this.setLayout(layout);
272  layout.setHorizontalGroup(
273  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274  .addGroup(layout.createSequentialGroup()
275  .addContainerGap()
276  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277  .addGroup(layout.createSequentialGroup()
278  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279  .addComponent(jLabel2)
280  .addGroup(layout.createSequentialGroup()
281  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
282  .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
283  .addGroup(layout.createSequentialGroup()
284  .addComponent(caseNameLabel)
285  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
286  .addComponent(caseNameTextField))
287  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
288  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289  .addComponent(caseDirLabel)
290  .addComponent(caseTypeLabel))
291  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
292  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293  .addGroup(layout.createSequentialGroup()
294  .addComponent(singleUserCaseRadioButton)
295  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296  .addComponent(multiUserCaseRadioButton)
297  .addGap(0, 192, Short.MAX_VALUE))
298  .addComponent(caseParentDirTextField))))
299  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
300  .addComponent(caseDirBrowseButton)))
301  .addContainerGap())
302  .addGroup(layout.createSequentialGroup()
303  .addComponent(caseParentDirWarningLabel)
304  .addGap(0, 0, Short.MAX_VALUE))))
305  );
306 
307  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
308 
309  layout.setVerticalGroup(
310  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311  .addGroup(layout.createSequentialGroup()
312  .addContainerGap()
313  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
314  .addComponent(caseNameLabel)
315  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
316  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
317  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318  .addComponent(caseDirLabel)
319  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
320  .addComponent(caseDirBrowseButton))
321  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
322  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
323  .addComponent(singleUserCaseRadioButton)
324  .addComponent(multiUserCaseRadioButton)
325  .addComponent(caseTypeLabel))
326  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327  .addComponent(jLabel2)
328  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
330  .addGap(27, 27, 27)
331  .addComponent(caseParentDirWarningLabel)
332  .addContainerGap(115, Short.MAX_VALUE))
333  );
334  }// </editor-fold>//GEN-END:initComponents
335 
343  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
344  fileChooser.setDragEnabled(false);
345  if (!caseParentDirTextField.getText().trim().equals("")) {
346  fileChooser.setCurrentDirectory(new File(caseParentDirTextField.getText()));
347  }
348  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
349  int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
350  "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
351  if (JFileChooser.APPROVE_OPTION == choice) {
352  String path = fileChooser.getSelectedFile().getPath();
353  caseParentDirTextField.setText(path);
354  }
355  }//GEN-LAST:event_caseDirBrowseButtonActionPerformed
356 
357  private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleUserCaseRadioButtonActionPerformed
358  handleUpdate();
359  }//GEN-LAST:event_singleUserCaseRadioButtonActionPerformed
360 
361  private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiUserCaseRadioButtonActionPerformed
362  handleUpdate();
363  }//GEN-LAST:event_multiUserCaseRadioButtonActionPerformed
364 
365  // Variables declaration - do not modify//GEN-BEGIN:variables
366  private javax.swing.JButton caseDirBrowseButton;
367  private javax.swing.JLabel caseDirLabel;
368  private javax.swing.JTextField caseDirTextField;
369  private javax.swing.JLabel caseNameLabel;
370  private javax.swing.JTextField caseNameTextField;
371  private javax.swing.JTextField caseParentDirTextField;
372  private javax.swing.JLabel caseParentDirWarningLabel;
373  private javax.swing.ButtonGroup caseTypeButtonGroup;
374  private javax.swing.JLabel caseTypeLabel;
375  private javax.swing.JLabel jLabel2;
376  private javax.swing.JRadioButton multiUserCaseRadioButton;
377  private javax.swing.JRadioButton singleUserCaseRadioButton;
378  // End of variables declaration//GEN-END:variables
379 
386  @Override
387  public void insertUpdate(DocumentEvent e) {
388  this.wizPanel.fireChangeEvent();
389  updateUI(e);
390  }
391 
399  @Override
400  public void removeUpdate(DocumentEvent e) {
401  this.wizPanel.fireChangeEvent();
402  updateUI(e);
403  }
404 
410  @Override
411  public void changedUpdate(DocumentEvent e) {
412  this.wizPanel.fireChangeEvent();
413  updateUI(e);
414  }
415 
423  public void updateUI(DocumentEvent e) {
424 
425  String caseName = getCaseName();
426  String parentDir = getCaseParentDir();
427 
428  if (!caseName.equals("") && !parentDir.equals("")) {
429  caseDirTextField.setText(parentDir + caseName);
430  wizPanel.setIsFinish(true);
431  } else {
432  caseDirTextField.setText("");
433  wizPanel.setIsFinish(false);
434  }
435  }
436 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.