25 package org.sleuthkit.autopsy.casemodule;
28 import java.nio.file.Paths;
29 import java.awt.event.ActionListener;
32 import java.util.logging.Level;
33 import org.openide.util.NbBundle;
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.table.DefaultTableModel;
38 import org.openide.DialogDescriptor;
39 import org.openide.DialogDisplayer;
40 import org.openide.NotifyDescriptor;
41 import org.openide.util.actions.CallableSystemAction;
48 class CasePropertiesForm
extends javax.swing.JPanel {
50 private static final long serialVersionUID = 1L;
52 private Case current = null;
53 private static JPanel caller;
57 private String shrinkPath(String path,
int targetLength) {
58 if (path.length() > targetLength) {
61 int partsLength = targetLength - fill.length();
63 String front = path.substring(0, partsLength / 4);
64 int frontSep = front.lastIndexOf(File.separatorChar);
66 front = front.substring(0, frontSep + 1);
69 String back = path.substring(partsLength * 3 / 4);
70 int backSep = back.indexOf(File.separatorChar);
72 back = back.substring(backSep);
74 return back + fill + front;
83 CasePropertiesForm(Case currentCase, String crDate, String caseDir, Map<Long, String> imgPaths)
throws CaseMetadata.CaseMetadataException {
85 caseNameTextField.setText(currentCase.getName());
86 caseNumberTextField.setText(currentCase.getNumber());
87 examinerTextField.setText(currentCase.getExaminer());
88 crDateTextField.setText(crDate);
89 caseDirTextArea.setText(caseDir);
90 current = currentCase;
92 CaseMetadata caseMetadata =
new CaseMetadata(Paths.get(currentCase.getConfigFilePath()));
93 tbDbName.setText(caseMetadata.getCaseDatabaseName());
94 Case.CaseType caseType = caseMetadata.getCaseType();
95 tbDbType.setText(caseType.getLocalizedDisplayName());
96 if (caseType == Case.CaseType.SINGLE_USER_CASE) {
97 deleteCaseButton.setEnabled(
true);
99 deleteCaseButton.setEnabled(
false);
102 int totalImages = imgPaths.size();
106 String[] headers = {imagesTable.getColumnName(0),
107 imagesTable.getColumnName(1)};
108 String[][] rows =
new String[totalImages][];
111 for (
long key : imgPaths.keySet()) {
112 String path = imgPaths.get(key);
113 String shortenPath = shrinkPath(path, 70);
114 rows[i++] =
new String[]{shortenPath};
118 DefaultTableModel model =
new DefaultTableModel(rows, headers) {
121 public boolean isCellEditable(
int row,
int column) {
126 imagesTable.setModel(model);
187 @SuppressWarnings(
"unchecked")
189 private
void initComponents() {
191 jScrollPane1 =
new javax.swing.JScrollPane();
192 jTextArea1 =
new javax.swing.JTextArea();
193 casePropLabel =
new javax.swing.JLabel();
194 caseNameLabel =
new javax.swing.JLabel();
195 crDateLabel =
new javax.swing.JLabel();
196 caseDirLabel =
new javax.swing.JLabel();
197 crDateTextField =
new javax.swing.JTextField();
198 caseNameTextField =
new javax.swing.JTextField();
199 updateCaseNameButton =
new javax.swing.JButton();
200 genInfoLabel =
new javax.swing.JLabel();
201 imgInfoLabel =
new javax.swing.JLabel();
202 OKButton =
new javax.swing.JButton();
203 imagesTableScrollPane =
new javax.swing.JScrollPane();
204 imagesTable =
new javax.swing.JTable();
205 jScrollPane2 =
new javax.swing.JScrollPane();
206 caseDirTextArea =
new javax.swing.JTextArea();
207 deleteCaseButton =
new javax.swing.JButton();
208 caseNumberLabel =
new javax.swing.JLabel();
209 examinerLabel =
new javax.swing.JLabel();
210 caseNumberTextField =
new javax.swing.JTextField();
211 examinerTextField =
new javax.swing.JTextField();
212 lbDbType =
new javax.swing.JLabel();
213 tbDbType =
new javax.swing.JTextField();
214 lbDbName =
new javax.swing.JLabel();
215 tbDbName =
new javax.swing.JTextField();
217 jTextArea1.setColumns(20);
218 jTextArea1.setRows(5);
219 jScrollPane1.setViewportView(jTextArea1);
221 casePropLabel.setFont(casePropLabel.getFont().deriveFont(casePropLabel.getFont().getStyle() | java.awt.Font.BOLD, 24));
222 casePropLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
223 casePropLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.casePropLabel.text"));
225 caseNameLabel.setFont(caseNameLabel.getFont().deriveFont(caseNameLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
226 caseNameLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNameLabel.text"));
228 crDateLabel.setFont(crDateLabel.getFont().deriveFont(crDateLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
229 crDateLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.crDateLabel.text"));
231 caseDirLabel.setFont(caseDirLabel.getFont().deriveFont(caseDirLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
232 caseDirLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseDirLabel.text"));
234 crDateTextField.setEditable(
false);
235 crDateTextField.setFont(crDateTextField.getFont().deriveFont(crDateTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
236 crDateTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.crDateTextField.text"));
238 caseNameTextField.setFont(caseNameTextField.getFont().deriveFont(caseNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
239 caseNameTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNameTextField.text"));
241 updateCaseNameButton.setFont(updateCaseNameButton.getFont().deriveFont(updateCaseNameButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
242 updateCaseNameButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.updateCaseNameButton.text"));
243 updateCaseNameButton.addActionListener(
new java.awt.event.ActionListener() {
244 public void actionPerformed(java.awt.event.ActionEvent evt) {
245 updateCaseNameButtonActionPerformed(evt);
249 genInfoLabel.setFont(genInfoLabel.getFont().deriveFont(genInfoLabel.getFont().getStyle() | java.awt.Font.BOLD, 14));
250 genInfoLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.genInfoLabel.text"));
252 imgInfoLabel.setFont(imgInfoLabel.getFont().deriveFont(imgInfoLabel.getFont().getStyle() | java.awt.Font.BOLD, 14));
253 imgInfoLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.imgInfoLabel.text"));
255 OKButton.setFont(OKButton.getFont().deriveFont(OKButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
256 OKButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.OKButton.text"));
258 imagesTableScrollPane.setFont(imagesTableScrollPane.getFont().deriveFont(imagesTableScrollPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
260 imagesTable.setFont(imagesTable.getFont().deriveFont(imagesTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
261 imagesTable.setModel(
new javax.swing.table.DefaultTableModel(
269 boolean[] canEdit =
new boolean [] {
273 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
274 return canEdit [columnIndex];
277 imagesTable.setShowHorizontalLines(
false);
278 imagesTable.setShowVerticalLines(
false);
279 imagesTable.getTableHeader().setReorderingAllowed(
false);
280 imagesTable.setUpdateSelectionOnSort(
false);
281 imagesTableScrollPane.setViewportView(imagesTable);
282 if (imagesTable.getColumnModel().getColumnCount() > 0) {
283 imagesTable.getColumnModel().getColumn(0).setHeaderValue(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.imagesTable.columnModel.title0"));
284 imagesTable.getColumnModel().getColumn(1).setHeaderValue(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.imagesTable.columnModel.title1"));
287 jScrollPane2.setFont(jScrollPane2.getFont().deriveFont(jScrollPane2.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
289 caseDirTextArea.setEditable(
false);
290 caseDirTextArea.setBackground(
new java.awt.Color(240, 240, 240));
291 caseDirTextArea.setColumns(20);
292 caseDirTextArea.setRows(1);
293 caseDirTextArea.setRequestFocusEnabled(
false);
294 jScrollPane2.setViewportView(caseDirTextArea);
296 deleteCaseButton.setFont(deleteCaseButton.getFont().deriveFont(deleteCaseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
297 deleteCaseButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.deleteCaseButton.text"));
298 deleteCaseButton.addActionListener(
new java.awt.event.ActionListener() {
299 public void actionPerformed(java.awt.event.ActionEvent evt) {
300 deleteCaseButtonActionPerformed(evt);
304 caseNumberLabel.setFont(caseNumberLabel.getFont().deriveFont(caseNumberLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
305 caseNumberLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNumberLabel.text"));
307 examinerLabel.setFont(examinerLabel.getFont().deriveFont(examinerLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
308 examinerLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.examinerLabel.text"));
310 caseNumberTextField.setEditable(
false);
311 caseNumberTextField.setFont(caseNumberTextField.getFont().deriveFont(caseNumberTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
312 caseNumberTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNumberTextField.text"));
314 examinerTextField.setEditable(
false);
315 examinerTextField.setFont(examinerTextField.getFont().deriveFont(examinerTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
316 examinerTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.examinerTextField.text"));
318 lbDbType.setFont(lbDbType.getFont().deriveFont(lbDbType.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
319 lbDbType.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.lbDbType.text"));
321 tbDbType.setEditable(
false);
322 tbDbType.setFont(tbDbType.getFont().deriveFont(tbDbType.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
323 tbDbType.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.tbDbType.text"));
325 lbDbName.setFont(lbDbName.getFont().deriveFont(lbDbName.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
326 lbDbName.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.lbDbName.text"));
328 tbDbName.setEditable(
false);
329 tbDbName.setFont(tbDbName.getFont().deriveFont(tbDbName.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
330 tbDbName.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.tbDbName.text"));
332 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
333 this.setLayout(layout);
334 layout.setHorizontalGroup(
335 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addGroup(layout.createSequentialGroup()
338 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339 .addComponent(casePropLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
340 .addComponent(imagesTableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
341 .addGroup(layout.createSequentialGroup()
342 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
343 .addComponent(caseNameLabel)
344 .addComponent(caseNumberLabel)
345 .addComponent(examinerLabel)
346 .addComponent(caseDirLabel)
347 .addComponent(crDateLabel)
348 .addComponent(lbDbType))
350 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
351 .addComponent(caseNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
352 .addComponent(caseNumberTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
353 .addComponent(examinerTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
354 .addComponent(crDateTextField)
355 .addComponent(jScrollPane2)
356 .addComponent(tbDbType)
357 .addComponent(tbDbName))
358 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
359 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
360 .addComponent(deleteCaseButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
361 .addComponent(updateCaseNameButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
362 .addGroup(layout.createSequentialGroup()
363 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
364 .addComponent(genInfoLabel)
365 .addComponent(imgInfoLabel)
366 .addGroup(layout.createSequentialGroup()
367 .addGap(181, 181, 181)
368 .addComponent(OKButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
369 .addComponent(lbDbName))
370 .addGap(0, 0, Short.MAX_VALUE)))
373 layout.setVerticalGroup(
374 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
375 .addGroup(layout.createSequentialGroup()
377 .addComponent(casePropLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
379 .addComponent(genInfoLabel)
380 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
381 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
382 .addComponent(caseNameLabel)
383 .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
384 .addComponent(updateCaseNameButton))
385 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
387 .addComponent(caseNumberLabel)
388 .addComponent(caseNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
389 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
390 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
391 .addComponent(examinerLabel)
392 .addComponent(examinerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
393 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
394 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
395 .addComponent(crDateLabel)
396 .addComponent(crDateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
397 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
399 .addGroup(layout.createSequentialGroup()
400 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
402 .addComponent(caseDirLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
403 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
404 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
405 .addComponent(tbDbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
406 .addComponent(lbDbType))
407 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
408 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
409 .addComponent(lbDbName)
410 .addComponent(tbDbName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
412 .addComponent(imgInfoLabel))
413 .addGroup(layout.createSequentialGroup()
415 .addComponent(deleteCaseButton)))
416 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
417 .addComponent(imagesTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
418 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
419 .addComponent(OKButton)
429 private void updateCaseNameButtonActionPerformed(java.awt.event.ActionEvent evt) {
430 String oldCaseName = Case.getCurrentCase().getName();
431 String newCaseName = caseNameTextField.getText();
436 if (!oldCaseName.equals(newCaseName)) {
439 if (newCaseName.trim().equals(
"")) {
440 JOptionPane.showMessageDialog(caller,
441 NbBundle.getMessage(
this.getClass(),
442 "CasePropertiesForm.updateCaseName.msgDlg.empty.msg"),
443 NbBundle.getMessage(
this.getClass(),
444 "CasePropertiesForm.updateCaseName.msgDlg.empty.title"),
445 JOptionPane.ERROR_MESSAGE);
449 if (newCaseName.contains(
"\\") || newCaseName.contains(
"/") || newCaseName.contains(
":")
450 || newCaseName.contains(
"*") || newCaseName.contains(
"?") || newCaseName.contains(
"\"")
451 || newCaseName.contains(
"<") || newCaseName.contains(
">") || newCaseName.contains(
"|")) {
452 String errorMsg = NbBundle
453 .getMessage(this.getClass(),
"CasePropertiesForm.updateCaseName.msgDlg.invalidSymbols.msg");
454 JOptionPane.showMessageDialog(caller, errorMsg,
455 NbBundle.getMessage(
this.getClass(),
456 "CasePropertiesForm.updateCaseName.msgDlg.invalidSymbols.title"),
457 JOptionPane.ERROR_MESSAGE);
460 String confMsg = NbBundle
461 .getMessage(this.getClass(),
"CasePropertiesForm.updateCaseName.confMsg.msg", oldCaseName,
463 NotifyDescriptor d =
new NotifyDescriptor.Confirmation(confMsg,
464 NbBundle.getMessage(
this.getClass(),
465 "CasePropertiesForm.updateCaseName.confMsg.title"),
466 NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
467 d.setValue(NotifyDescriptor.NO_OPTION);
469 Object res = DialogDisplayer.getDefault().notify(d);
470 if (res != null && res == DialogDescriptor.YES_OPTION) {
472 String oldPath = current.getConfigFilePath();
474 current.updateCaseName(oldCaseName, oldPath, newCaseName, oldPath);
475 }
catch (Exception ex) {
476 Logger.getLogger(CasePropertiesForm.class.getName()).log(Level.WARNING,
"Error: problem updating case name.", ex);
484 private void deleteCaseButtonActionPerformed(java.awt.event.ActionEvent evt) {
485 CallableSystemAction.get(CaseDeleteAction.class).actionPerformed(evt);
493 public void setOKButtonActionListener(ActionListener e) {
494 OKButton.addActionListener(e);
498 private javax.swing.JButton OKButton;
499 private javax.swing.JLabel caseDirLabel;
500 private javax.swing.JTextArea caseDirTextArea;
501 private javax.swing.JLabel caseNameLabel;
502 private javax.swing.JTextField caseNameTextField;
503 private javax.swing.JLabel caseNumberLabel;
504 private javax.swing.JTextField caseNumberTextField;
505 private javax.swing.JLabel casePropLabel;
506 private javax.swing.JLabel crDateLabel;
507 private javax.swing.JTextField crDateTextField;
508 private javax.swing.JButton deleteCaseButton;
509 private javax.swing.JLabel examinerLabel;
510 private javax.swing.JTextField examinerTextField;
511 private javax.swing.JLabel genInfoLabel;
512 private javax.swing.JTable imagesTable;
513 private javax.swing.JScrollPane imagesTableScrollPane;
514 private javax.swing.JLabel imgInfoLabel;
515 private javax.swing.JScrollPane jScrollPane1;
516 private javax.swing.JScrollPane jScrollPane2;
517 private javax.swing.JTextArea jTextArea1;
518 private javax.swing.JLabel lbDbName;
519 private javax.swing.JLabel lbDbType;
520 private javax.swing.JTextField tbDbName;
521 private javax.swing.JTextField tbDbType;
522 private javax.swing.JButton updateCaseNameButton;