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 JFileChooser fileChooser =
new JFileChooser();
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() {
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"));
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"));
179 String caseName = getCaseName();
180 if (!caseName.equals(
"") && !parentDir.equals(
"")) {
181 caseDirTextField.setText(parentDir + caseName);
182 wizPanel.setIsFinish(
true);
184 caseDirTextField.setText(
"");
185 wizPanel.setIsFinish(
false);
218 private void initComponents() {
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 caseDataStoredLabel =
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();
233 org.openide.awt.Mnemonics.setLocalizedText(caseNameLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseNameLabel.text_1"));
235 org.openide.awt.Mnemonics.setLocalizedText(caseDirLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirLabel.text"));
237 caseNameTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseNameTextField.text_1"));
239 caseParentDirTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseParentDirTextField.text"));
241 org.openide.awt.Mnemonics.setLocalizedText(caseDirBrowseButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirBrowseButton.text"));
242 caseDirBrowseButton.addActionListener(
new java.awt.event.ActionListener() {
243 public void actionPerformed(java.awt.event.ActionEvent evt) {
244 caseDirBrowseButtonActionPerformed(evt);
248 org.openide.awt.Mnemonics.setLocalizedText(caseDataStoredLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDataStoredLabel.text_1"));
250 caseDirTextField.setEditable(
false);
251 caseDirTextField.setText(
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseDirTextField.text_1"));
253 caseTypeButtonGroup.add(singleUserCaseRadioButton);
254 org.openide.awt.Mnemonics.setLocalizedText(singleUserCaseRadioButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.singleUserCaseRadioButton.text"));
255 singleUserCaseRadioButton.addActionListener(
new java.awt.event.ActionListener() {
256 public void actionPerformed(java.awt.event.ActionEvent evt) {
257 singleUserCaseRadioButtonActionPerformed(evt);
261 caseTypeButtonGroup.add(multiUserCaseRadioButton);
262 org.openide.awt.Mnemonics.setLocalizedText(multiUserCaseRadioButton,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.multiUserCaseRadioButton.text"));
263 multiUserCaseRadioButton.addActionListener(
new java.awt.event.ActionListener() {
264 public void actionPerformed(java.awt.event.ActionEvent evt) {
265 multiUserCaseRadioButtonActionPerformed(evt);
269 caseParentDirWarningLabel.setForeground(
new java.awt.Color(255, 0, 0));
270 org.openide.awt.Mnemonics.setLocalizedText(caseParentDirWarningLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseParentDirWarningLabel.text"));
272 org.openide.awt.Mnemonics.setLocalizedText(caseTypeLabel,
org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class,
"NewCaseVisualPanel1.caseTypeLabel.text"));
274 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
275 this.setLayout(layout);
276 layout.setHorizontalGroup(
277 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278 .addGroup(layout.createSequentialGroup()
280 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281 .addGroup(layout.createSequentialGroup()
282 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283 .addComponent(caseDataStoredLabel)
284 .addGroup(layout.createSequentialGroup()
285 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
286 .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING)
287 .addGroup(layout.createSequentialGroup()
288 .addComponent(caseNameLabel)
289 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
290 .addComponent(caseNameTextField))
291 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
292 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293 .addComponent(caseDirLabel)
294 .addComponent(caseTypeLabel))
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297 .addGroup(layout.createSequentialGroup()
298 .addComponent(singleUserCaseRadioButton)
299 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
300 .addComponent(multiUserCaseRadioButton)
301 .addGap(0, 192, Short.MAX_VALUE))
302 .addComponent(caseParentDirTextField))))
303 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
304 .addComponent(caseDirBrowseButton)))
306 .addGroup(layout.createSequentialGroup()
307 .addComponent(caseParentDirWarningLabel)
308 .addGap(0, 0, Short.MAX_VALUE))))
311 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {caseDirLabel, caseNameLabel, caseTypeLabel});
313 layout.setVerticalGroup(
314 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315 .addGroup(layout.createSequentialGroup()
317 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318 .addComponent(caseNameLabel)
319 .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
321 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
322 .addComponent(caseDirLabel)
323 .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
324 .addComponent(caseDirBrowseButton))
325 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
326 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
327 .addComponent(singleUserCaseRadioButton)
328 .addComponent(multiUserCaseRadioButton)
329 .addComponent(caseTypeLabel))
330 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
331 .addComponent(caseDataStoredLabel)
332 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
333 .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
335 .addComponent(caseParentDirWarningLabel)
336 .addContainerGap(115, Short.MAX_VALUE))
347 private void caseDirBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
348 fileChooser.setDragEnabled(
false);
349 if (!caseParentDirTextField.getText().trim().equals(
"")) {
350 fileChooser.setCurrentDirectory(
new File(caseParentDirTextField.getText()));
352 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
353 int choice = fileChooser.showDialog((Component) evt.getSource(), NbBundle.getMessage(this.getClass(),
354 "NewCaseVisualPanel1.caseDirBrowse.selectButton.text"));
355 if (JFileChooser.APPROVE_OPTION == choice) {
356 String path = fileChooser.getSelectedFile().getPath();
357 caseParentDirTextField.setText(path);
361 private void singleUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
365 private void multiUserCaseRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
370 private javax.swing.JLabel caseDataStoredLabel;
371 private javax.swing.JButton caseDirBrowseButton;
372 private javax.swing.JLabel caseDirLabel;
373 private javax.swing.JTextField caseDirTextField;
374 private javax.swing.JLabel caseNameLabel;
375 private javax.swing.JTextField caseNameTextField;
376 private javax.swing.JTextField caseParentDirTextField;
377 private javax.swing.JLabel caseParentDirWarningLabel;
378 private javax.swing.ButtonGroup caseTypeButtonGroup;
379 private javax.swing.JLabel caseTypeLabel;
380 private javax.swing.JRadioButton multiUserCaseRadioButton;
381 private javax.swing.JRadioButton singleUserCaseRadioButton;
391 public void insertUpdate(DocumentEvent e) {
392 this.wizPanel.fireChangeEvent();
404 public void removeUpdate(DocumentEvent e) {
405 this.wizPanel.fireChangeEvent();
415 public void changedUpdate(DocumentEvent e) {
416 this.wizPanel.fireChangeEvent();
427 public void updateUI(DocumentEvent e) {
429 String caseName = getCaseName();
430 String parentDir = getCaseParentDir();
432 if (!caseName.equals(
"") && !parentDir.equals(
"")) {
433 caseDirTextField.setText(parentDir + caseName);
434 wizPanel.setIsFinish(
true);
436 caseDirTextField.setText(
"");
437 wizPanel.setIsFinish(
false);
void insertUpdate(DocumentEvent e)
void removeUpdate(DocumentEvent e)
void changedUpdate(DocumentEvent e)