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

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