Autopsy  4.6.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  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
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 
306  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
307 
308  layout.setVerticalGroup(
309  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310  .addGroup(layout.createSequentialGroup()
311  .addContainerGap()
312  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
313  .addComponent(caseNameLabel)
314  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
315  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
316  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
317  .addComponent(caseDirLabel)
318  .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
319  .addComponent(caseDirBrowseButton))
320  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
321  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
322  .addComponent(singleUserCaseRadioButton)
323  .addComponent(multiUserCaseRadioButton)
324  .addComponent(caseTypeLabel))
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
326  .addComponent(jLabel2)
327  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
328  .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
329  .addGap(27, 27, 27)
330  .addComponent(caseParentDirWarningLabel)
331  .addContainerGap(115, Short.MAX_VALUE))
332  );
333  }// </editor-fold>//GEN-END:initComponents
334 
342  private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseDirBrowseButtonActionPerformed
343  fileChooser.setDragEnabled(false);
344  if (!caseParentDirTextField.getText().trim().equals("")) {
345  fileChooser.setCurrentDirectory(new File(caseParentDirTextField.getText()));
346  }
347  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
348  int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
349  "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
350  if (JFileChooser.APPROVE_OPTION == choice) {
351  String path = fileChooser.getSelectedFile().getPath();
352  caseParentDirTextField.setText(path);
353  }
354  }//GEN-LAST:event_caseDirBrowseButtonActionPerformed
355 
356  private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleUserCaseRadioButtonActionPerformed
357  handleUpdate();
358  }//GEN-LAST:event_singleUserCaseRadioButtonActionPerformed
359 
360  private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiUserCaseRadioButtonActionPerformed
361  handleUpdate();
362  }//GEN-LAST:event_multiUserCaseRadioButtonActionPerformed
363 
364  // Variables declaration - do not modify//GEN-BEGIN:variables
365  private javax.swing.JButton caseDirBrowseButton;
366  private javax.swing.JLabel caseDirLabel;
367  private javax.swing.JTextField caseDirTextField;
368  private javax.swing.JLabel caseNameLabel;
369  private javax.swing.JTextField caseNameTextField;
370  private javax.swing.JTextField caseParentDirTextField;
371  private javax.swing.JLabel caseParentDirWarningLabel;
372  private javax.swing.ButtonGroup caseTypeButtonGroup;
373  private javax.swing.JLabel caseTypeLabel;
374  private javax.swing.JLabel jLabel2;
375  private javax.swing.JRadioButton multiUserCaseRadioButton;
376  private javax.swing.JRadioButton singleUserCaseRadioButton;
377  // End of variables declaration//GEN-END:variables
378 
385  @Override
386  public void insertUpdate(DocumentEvent e) {
387  this.wizPanel.fireChangeEvent();
388  updateUI(e);
389  }
390 
398  @Override
399  public void removeUpdate(DocumentEvent e) {
400  this.wizPanel.fireChangeEvent();
401  updateUI(e);
402  }
403 
409  @Override
410  public void changedUpdate(DocumentEvent e) {
411  this.wizPanel.fireChangeEvent();
412  updateUI(e);
413  }
414 
422  public void updateUI(DocumentEvent e) {
423 
424  String caseName = getCaseName();
425  String parentDir = getCaseParentDir();
426 
427  if (!caseName.equals("") && !parentDir.equals("")) {
428  caseDirTextField.setText(parentDir + caseName);
429  wizPanel.setIsFinish(true);
430  } else {
431  caseDirTextField.setText("");
432  wizPanel.setIsFinish(false);
433  }
434  }
435 }

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