19 package org.sleuthkit.autopsy.casemodule;
22 import java.awt.Component;
23 import org.openide.util.NbBundle;
26 import javax.swing.JFileChooser;
27 import javax.swing.JPanel;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
38 @SuppressWarnings(
"PMD.SingularField")
39 final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
41 private final JFileChooserFactory fileChooserHelper =
new JFileChooserFactory();
42 private final NewCaseWizardPanel1 wizPanel;
49 NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) {
50 this.wizPanel = wizPanel;
52 TextFieldListener listener =
new TextFieldListener();
53 caseNameTextField.getDocument().addDocumentListener(listener);
54 caseParentDirTextField.getDocument().addDocumentListener(listener);
55 caseParentDirWarningLabel.setVisible(
false);
64 caseNameTextField.setText(
"");
65 if (FeatureAccessUtils.canCreateMultiUserCases()) {
66 multiUserCaseRadioButton.setEnabled(
true);
67 multiUserCaseRadioButton.setSelected(
true);
69 multiUserCaseRadioButton.setEnabled(
false);
70 singleUserCaseRadioButton.setSelected(
true);
82 public String getName() {
83 return NbBundle.getMessage(this.getClass(),
"NewCaseVisualPanel1.getName.text");
91 String getCaseName() {
92 return this.caseNameTextField.getText().trim();
101 void setCaseParentDir(String caseParentDir) {
102 caseParentDirTextField.setText(caseParentDir);
112 String getCaseParentDir() {
113 String parentDir = this.caseParentDirTextField.getText().trim();
114 if (parentDir.endsWith(File.separator) ==
false) {
115 parentDir = parentDir + File.separator;
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;
140 private void handleUpdate() {
141 wizPanel.fireChangeEvent();
149 private void validateSettings() {
155 caseParentDirWarningLabel.setVisible(
false);
156 String parentDir = getCaseParentDir();
157 if (!PathValidator.isValidForCaseType(parentDir, getCaseType())) {
158 if (getCaseType() == CaseType.MULTI_USER_CASE) {
159 caseParentDirWarningLabel.setVisible(
true);
160 caseParentDirWarningLabel.setText(NbBundle.getMessage(
this.getClass(),
"NewCaseVisualPanel1.CaseFolderOnCDriveError.text"));
163 caseParentDirWarningLabel.setVisible(
true);
164 caseParentDirWarningLabel.setText(NbBundle.getMessage(
this.getClass(),
"NewCaseVisualPanel1.uncPath.error"));
165 wizPanel.setIsFinish(
false);
174 if(!PathValidator.isValidForRunningOnTarget(parentDir)){
175 caseParentDirWarningLabel.setVisible(
true);
176 if(PlatformUtil.isWindowsOS()){
177 caseParentDirWarningLabel.setText(NbBundle.getMessage(
this.getClass(),
"NewCaseVisualPanel1.CaseFolderOnInternalDriveWindowsError.text" ));
178 }
else if(System.getProperty(
"os.name").toLowerCase().contains(
"nux")) {
179 caseParentDirWarningLabel.setText(NbBundle.getMessage(
this.getClass(),
"NewCaseVisualPanel1.CaseFolderOnInternalDriveLinuxError.text"));
188 String caseName = getCaseName();
189 if (!caseName.equals(
"") && !parentDir.equals(
"")) {
190 caseDirTextField.setText(parentDir + caseName);
191 wizPanel.setIsFinish(
true);
193 caseDirTextField.setText(
"");
194 wizPanel.setIsFinish(
false);
227 private void initComponents() {
229 caseTypeButtonGroup =
new javax.swing.ButtonGroup();
230 caseNameLabel =
new javax.swing.JLabel();
231 caseDirLabel =
new javax.swing.JLabel();
232 caseNameTextField =
new javax.swing.JTextField();
233 caseParentDirTextField =
new javax.swing.JTextField();
234 caseDirBrowseButton =
new javax.swing.JButton();
235 caseDataStoredLabel =
new javax.swing.JLabel();
236 caseDirTextField =
new javax.swing.JTextField();
237 singleUserCaseRadioButton =
new javax.swing.JRadioButton();
238 multiUserCaseRadioButton =
new javax.swing.JRadioButton();
239 caseParentDirWarningLabel =
new javax.swing.JLabel();
240 caseTypeLabel =
new javax.swing.JLabel();
242 org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseNameLabel.text_1"));
244 org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirLabel.text"));
246 caseNameTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseNameTextField.text_1"));
248 caseParentDirTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseParentDirTextField.text"));
250 org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirBrowseButton.text"));
251 caseDirBrowseButton.addActionListener(
new java.awt.event.ActionListener() {
252 public void actionPerformed(java.awt.event.ActionEvent evt) {
253 caseDirBrowseButtonActionPerformed(evt);
257 org.openide.awt.Mnemonics.setLocalizedText(caseDataStoredLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDataStoredLabel.text_1"));
259 caseDirTextField.setEditable(
false);
260 caseDirTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirTextField.text_1"));
262 caseTypeButtonGroup.add(singleUserCaseRadioButton);
263 org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.singleUserCaseRadioButton.text"));
264 singleUserCaseRadioButton.addActionListener(
new java.awt.event.ActionListener() {
265 public void actionPerformed(java.awt.event.ActionEvent evt) {
266 singleUserCaseRadioButtonActionPerformed(evt);
270 caseTypeButtonGroup.add(multiUserCaseRadioButton);
271 org.openide.awt.Mnemonics.setLocalizedText(multiUserCaseRadioButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.multiUserCaseRadioButton.text"));
272 multiUserCaseRadioButton.addActionListener(
new java.awt.event.ActionListener() {
273 public void actionPerformed(java.awt.event.ActionEvent evt) {
274 multiUserCaseRadioButtonActionPerformed(evt);
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"));
281 org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseTypeLabel.text"));
283 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
284 this.setLayout(layout);
285 layout.setHorizontalGroup(
286 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287 .addGroup(layout.createSequentialGroup()
289 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290 .addGroup(layout.createSequentialGroup()
291 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addComponent(caseDataStoredLabel)
293 .addGroup(layout.createSequentialGroup()
294 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
295 .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
296 .addGroup(layout.createSequentialGroup()
297 .addComponent(caseNameLabel)
298 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
299 .addComponent(caseNameTextField))
300 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
301 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addComponent(caseDirLabel)
303 .addComponent(caseTypeLabel))
304 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addGroup(layout.createSequentialGroup()
307 .addComponent(singleUserCaseRadioButton)
308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
309 .addComponent(multiUserCaseRadioButton)
310 .addGap(0, 192, Short.MAX_VALUE))
311 .addComponent(caseParentDirTextField))))
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
313 .addComponent(caseDirBrowseButton)))
315 .addGroup(layout.createSequentialGroup()
316 .addComponent(caseParentDirWarningLabel)
317 .addGap(0, 0, Short.MAX_VALUE))))
320 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
322 layout.setVerticalGroup(
323 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324 .addGroup(layout.createSequentialGroup()
326 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
327 .addComponent(caseNameLabel)
328 .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
329 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
330 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331 .addComponent(caseDirLabel)
332 .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
333 .addComponent(caseDirBrowseButton))
334 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
335 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
336 .addComponent(singleUserCaseRadioButton)
337 .addComponent(multiUserCaseRadioButton)
338 .addComponent(caseTypeLabel))
339 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
340 .addComponent(caseDataStoredLabel)
341 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342 .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
344 .addComponent(caseParentDirWarningLabel)
345 .addContainerGap(115, Short.MAX_VALUE))
356 private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
357 JFileChooser fileChooser = fileChooserHelper.getChooser();
358 fileChooser.setDragEnabled(
false);
359 if (!caseParentDirTextField.getText().trim().isEmpty()) {
360 fileChooser.setCurrentDirectory(
new File(caseParentDirTextField.getText()));
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);
371 private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
375 private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
380 private javax.swing.JLabel caseDataStoredLabel;
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.JRadioButton multiUserCaseRadioButton;
391 private javax.swing.JRadioButton singleUserCaseRadioButton;
401 public void insertUpdate(DocumentEvent e) {
402 this.wizPanel.fireChangeEvent();
414 public void removeUpdate(DocumentEvent e) {
415 this.wizPanel.fireChangeEvent();
425 public void changedUpdate(DocumentEvent e) {
426 this.wizPanel.fireChangeEvent();
437 public void updateUI(DocumentEvent e) {
439 String caseName = getCaseName();
440 String parentDir = getCaseParentDir();
442 if (!caseName.equals(
"") && !parentDir.equals(
"")) {
443 caseDirTextField.setText(parentDir + caseName);
444 wizPanel.setIsFinish(
true);
446 caseDirTextField.setText(
"");
447 wizPanel.setIsFinish(
false);
void insertUpdate(DocumentEvent e)
void removeUpdate(DocumentEvent e)
void changedUpdate(DocumentEvent e)