Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CasePropertiesForm.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 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 
20 /*
21  * CasePropertiesForm.java
22  *
23  * Created on Mar 14, 2011, 1:48:20 PM
24  */
25 
26 package org.sleuthkit.autopsy.casemodule;
27 
28 import java.awt.*;
29 import java.awt.event.ActionListener;
30 import java.io.File;
31 import java.util.Map;
32 import java.util.logging.Level;
33 
34 import org.openide.util.NbBundle;
36 import javax.swing.JOptionPane;
37 import javax.swing.JPanel;
38 import javax.swing.table.DefaultTableModel;
39 import org.openide.DialogDescriptor;
40 import org.openide.DialogDisplayer;
41 import org.openide.NotifyDescriptor;
42 import org.openide.util.actions.CallableSystemAction;
43 
49 class CasePropertiesForm extends javax.swing.JPanel{
50 
51  Case current = null;
52  private static JPanel caller; // panel for error
53 
54  // Shrink a path to fit in targetLength (if necessary), by replaceing part
55  // of the path with "...". Ex: "C:\Users\bob\...\folder\other\Image.img"
56  private String shrinkPath(String path, int targetLength) {
57  if(path.length() > targetLength){
58  String fill = "...";
59 
60  int partsLength = targetLength - fill.length();
61 
62  String front = path.substring(0, partsLength/4);
63  int frontSep = front.lastIndexOf(File.separatorChar);
64  if (frontSep != -1) {
65  front = front.substring(0, frontSep+1);
66  }
67 
68  String back = path.substring(partsLength*3/4);
69  int backSep = back.indexOf(File.separatorChar);
70  if (backSep != -1) {
71  back = back.substring(backSep);
72  }
73  return back + fill + front;
74  } else {
75  return path;
76  }
77  }
78 
79 
81  CasePropertiesForm(Case currentCase, String crDate, String caseDir, Map<Long, String> imgPaths) {
82  initComponents();
83  caseNameTextField.setText(currentCase.getName());
84  caseNumberTextField.setText(currentCase.getNumber());
85  examinerTextField.setText(currentCase.getExaminer());
86  crDateTextField.setText(crDate);
87  caseDirTextArea.setText(caseDir);
88 
89  current = currentCase;
90 
91  int totalImages = imgPaths.size();
92 
93  // create the headers and add all the rows
94  String[] headers = {"Path"}; //NON-NLS
95  String[][] rows = new String[totalImages][];
96 
97  int i = 0;
98  for(long key : imgPaths.keySet()){
99  String path = imgPaths.get(key);
100  String shortenPath = shrinkPath(path, 70);
101  rows[i++] = new String[]{shortenPath};
102  }
103 
104  // create the table inside with the imgPaths information
105  DefaultTableModel model = new DefaultTableModel(rows, headers)
106  {
107  @Override
108  // make the cells in the FileContentTable "read only"
109  public boolean isCellEditable(int row, int column){
110  return false;
111  //return column == lastColumn; // make the last column (Remove button), only the editable
112  }
113  };
114  imagesTable.setModel(model);
115 
116 // // set the size of the remove column
117 // TableColumn removeCol = imagesTable.getColumnModel().getColumn(lastColumn);
118 // removeCol.setPreferredWidth(75);
119 // removeCol.setMaxWidth(75);
120 // removeCol.setMinWidth(75);
121 // removeCol.setResizable(false);
122 
123 // // create the delete action to remove the image from the current case
124 // Action delete = new AbstractAction()
125 // {
126 // @Override
127 // public void actionPerformed(ActionEvent e)
128 // {
129 // // get the image path
130 // JTable table = (JTable)e.getSource();
131 // int modelRow = Integer.valueOf(e.getActionCommand());
132 // String removeColumn = table.getValueAt(modelRow, lastColumn).toString();
133 // // get the image ID
134 // int selectedID = Integer.parseInt(removeColumn.substring(0, removeColumn.indexOf('|')));
135 // String imagePath = removeColumn.substring(removeColumn.indexOf('|') + 1);
136 //
137 // // throw the confirmation first
138 // String confMsg = "Are you sure want to remove image \"" + imagePath + "\" from this case?";
139 // NotifyDescriptor d = new NotifyDescriptor.Confirmation(confMsg, "Create directory", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
140 // d.setValue(NotifyDescriptor.NO_OPTION);
141 //
142 // Object res = DialogDisplayer.getDefault().notify(d);
143 // // if user select "Yes"
144 // if(res != null && res == DialogDescriptor.YES_OPTION){
145 // // remove the image in the case class and in the xml config file
146 // try {
147 // current.removeImage(selectedID, imagePath);
148 // } catch (Exception ex) {
149 // Logger.getLogger(CasePropertiesForm.class.getName()).log(Level.WARNING, "Error: couldn't remove image.", ex);
150 // }
151 // // remove the row of the image path
152 // ((DefaultTableModel)table.getModel()).removeRow(modelRow);
153 // }
154 // }
155 // };
156 //
157 // ButtonColumn buttonColumn = new ButtonColumn(imagesTable, delete, 1, "Remove");
158 // buttonColumn.setMnemonic(KeyEvent.VK_D);
159  }
160 
165  @SuppressWarnings("unchecked")
166  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
167  private void initComponents() {
168 
169  jScrollPane1 = new javax.swing.JScrollPane();
170  jTextArea1 = new javax.swing.JTextArea();
171  casePropLabel = new javax.swing.JLabel();
172  caseNameLabel = new javax.swing.JLabel();
173  crDateLabel = new javax.swing.JLabel();
174  caseDirLabel = new javax.swing.JLabel();
175  crDateTextField = new javax.swing.JTextField();
176  caseNameTextField = new javax.swing.JTextField();
177  updateCaseNameButton = new javax.swing.JButton();
178  genInfoLabel = new javax.swing.JLabel();
179  imgInfoLabel = new javax.swing.JLabel();
180  OKButton = new javax.swing.JButton();
181  imagesTableScrollPane = new javax.swing.JScrollPane();
182  imagesTable = new javax.swing.JTable();
183  jScrollPane2 = new javax.swing.JScrollPane();
184  caseDirTextArea = new javax.swing.JTextArea();
185  deleteCaseButton = new javax.swing.JButton();
186  caseNumberLabel = new javax.swing.JLabel();
187  examinerLabel = new javax.swing.JLabel();
188  caseNumberTextField = new javax.swing.JTextField();
189  examinerTextField = new javax.swing.JTextField();
190 
191  jTextArea1.setColumns(20);
192  jTextArea1.setRows(5);
193  jScrollPane1.setViewportView(jTextArea1);
194 
195  casePropLabel.setFont(casePropLabel.getFont().deriveFont(Font.BOLD, 24));
196  casePropLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
197  casePropLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.casePropLabel.text")); // NOI18N
198 
199  caseNameLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.caseNameLabel.text")); // NOI18N
200 
201  crDateLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.crDateLabel.text")); // NOI18N
202 
203  caseDirLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.caseDirLabel.text")); // NOI18N
204 
205  crDateTextField.setEditable(false);
206  crDateTextField.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.crDateTextField.text")); // NOI18N
207 
208  caseNameTextField.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.caseNameTextField.text")); // NOI18N
209 
210  updateCaseNameButton.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.updateCaseNameButton.text")); // NOI18N
211  updateCaseNameButton.addActionListener(new java.awt.event.ActionListener() {
212  public void actionPerformed(java.awt.event.ActionEvent evt) {
213  updateCaseNameButtonActionPerformed(evt);
214  }
215  });
216 
217  genInfoLabel.setFont(genInfoLabel.getFont().deriveFont(Font.BOLD, 14));
218  genInfoLabel.setText(
219  org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.genInfoLabel.text")); // NOI18N
220 
221  imgInfoLabel.setFont(imgInfoLabel.getFont().deriveFont(Font.BOLD, 14));
222  imgInfoLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.imgInfoLabel.text")); // NOI18N
223 
224  OKButton.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.OKButton.text")); // NOI18N
225 
226  imagesTable.setModel(new javax.swing.table.DefaultTableModel(
227  new Object [][] {
228 
229  },
230  new String [] {
231  "Path", "Remove" //NON-NLS
232  }
233  ) {
234  boolean[] canEdit = new boolean [] {
235  false, true
236  };
237 
238  public boolean isCellEditable(int rowIndex, int columnIndex) {
239  return canEdit [columnIndex];
240  }
241  });
242  imagesTable.setShowHorizontalLines(false);
243  imagesTable.setShowVerticalLines(false);
244  imagesTable.getTableHeader().setReorderingAllowed(false);
245  imagesTable.setUpdateSelectionOnSort(false);
246  imagesTableScrollPane.setViewportView(imagesTable);
247 
248  caseDirTextArea.setBackground(new java.awt.Color(240, 240, 240));
249  caseDirTextArea.setColumns(20);
250  caseDirTextArea.setEditable(false);
251  caseDirTextArea.setRows(1);
252  caseDirTextArea.setRequestFocusEnabled(false);
253  jScrollPane2.setViewportView(caseDirTextArea);
254 
255  deleteCaseButton.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.deleteCaseButton.text")); // NOI18N
256  deleteCaseButton.addActionListener(new java.awt.event.ActionListener() {
257  public void actionPerformed(java.awt.event.ActionEvent evt) {
258  deleteCaseButtonActionPerformed(evt);
259  }
260  });
261 
262  caseNumberLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.caseNumberLabel.text")); // NOI18N
263 
264  examinerLabel.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.examinerLabel.text")); // NOI18N
265 
266  caseNumberTextField.setEditable(false);
267  caseNumberTextField.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.caseNumberTextField.text")); // NOI18N
268 
269  examinerTextField.setEditable(false);
270  examinerTextField.setText(org.openide.util.NbBundle.getMessage(CasePropertiesForm.class, "CasePropertiesForm.examinerTextField.text")); // NOI18N
271 
272  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
273  this.setLayout(layout);
274  layout.setHorizontalGroup(
275  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276  .addGroup(layout.createSequentialGroup()
277  .addContainerGap()
278  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279  .addComponent(casePropLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
280  .addComponent(genInfoLabel)
281  .addComponent(imgInfoLabel)
282  .addComponent(imagesTableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
283  .addGroup(layout.createSequentialGroup()
284  .addGap(181, 181, 181)
285  .addComponent(OKButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
286  .addGroup(layout.createSequentialGroup()
287  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
288  .addGroup(layout.createSequentialGroup()
289  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290  .addComponent(caseNameLabel)
291  .addComponent(caseNumberLabel))
292  .addGap(25, 25, 25)
293  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294  .addComponent(caseNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
295  .addComponent(caseNumberTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)))
296  .addGroup(layout.createSequentialGroup()
297  .addComponent(examinerLabel)
298  .addGap(45, 45, 45)
299  .addComponent(examinerTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))
300  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
301  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302  .addComponent(caseDirLabel)
303  .addComponent(crDateLabel))
304  .addGap(18, 18, 18)
305  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
307  .addComponent(crDateTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))))
308  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
309  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310  .addComponent(updateCaseNameButton)
311  .addComponent(deleteCaseButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
312  .addContainerGap())
313  );
314  layout.setVerticalGroup(
315  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316  .addGroup(layout.createSequentialGroup()
317  .addContainerGap()
318  .addComponent(casePropLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
319  .addGap(18, 18, 18)
320  .addComponent(genInfoLabel)
321  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
322  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
323  .addComponent(caseNameLabel)
324  .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
325  .addComponent(updateCaseNameButton))
326  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
328  .addComponent(caseNumberLabel)
329  .addComponent(caseNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
330  .addGap(18, 18, 18)
331  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
332  .addComponent(examinerLabel)
333  .addComponent(examinerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
334  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
335  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
336  .addComponent(crDateLabel)
337  .addComponent(crDateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
339  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
340  .addGroup(layout.createSequentialGroup()
341  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342  .addComponent(caseDirLabel)
343  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
344  .addGap(39, 39, 39)
345  .addComponent(imgInfoLabel))
346  .addComponent(deleteCaseButton))
347  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
348  .addComponent(imagesTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
349  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350  .addComponent(OKButton)
351  .addContainerGap())
352  );
353  }// </editor-fold>//GEN-END:initComponents
354 
360  private void updateCaseNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateCaseNameButtonActionPerformed
361  String oldCaseName = Case.getCurrentCase().getName();
362  String newCaseName = caseNameTextField.getText();
363  //String oldPath = caseDirTextArea.getText() + File.separator + oldCaseName + ".aut";
364  //String newPath = caseDirTextArea.getText() + File.separator + newCaseName + ".aut";
365 
366  // check if the old and new case name is not equal
367  if(!oldCaseName.equals(newCaseName)){
368 
369  // check if the case name is empty
370  if(newCaseName.trim().equals("")){
371  JOptionPane.showMessageDialog(caller,
372  NbBundle.getMessage(this.getClass(),
373  "CasePropertiesForm.updateCaseName.msgDlg.empty.msg"),
374  NbBundle.getMessage(this.getClass(),
375  "CasePropertiesForm.updateCaseName.msgDlg.empty.title"),
376  JOptionPane.ERROR_MESSAGE);
377  }
378  else{
379  // check if case Name contain one of this following symbol:
380  // \ / : * ? " < > |
381  if(newCaseName.contains("\\") || newCaseName.contains("/") || newCaseName.contains(":") ||
382  newCaseName.contains("*") || newCaseName.contains("?") || newCaseName.contains("\"") ||
383  newCaseName.contains("<") || newCaseName.contains(">") || newCaseName.contains("|")){
384  String errorMsg = NbBundle
385  .getMessage(this.getClass(), "CasePropertiesForm.updateCaseName.msgDlg.invalidSymbols.msg");
386  JOptionPane.showMessageDialog(caller, errorMsg,
387  NbBundle.getMessage(this.getClass(),
388  "CasePropertiesForm.updateCaseName.msgDlg.invalidSymbols.title"),
389  JOptionPane.ERROR_MESSAGE);
390  }
391  else{
392  // ask for the confirmation first
393  String confMsg = NbBundle
394  .getMessage(this.getClass(), "CasePropertiesForm.updateCaseName.confMsg.msg", oldCaseName,
395  newCaseName);
396  NotifyDescriptor d = new NotifyDescriptor.Confirmation(confMsg,
397  NbBundle.getMessage(this.getClass(),
398  "CasePropertiesForm.updateCaseName.confMsg.title"),
399  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
400  d.setValue(NotifyDescriptor.NO_OPTION);
401 
402  Object res = DialogDisplayer.getDefault().notify(d);
403  if(res != null && res == DialogDescriptor.YES_OPTION){
404  // if user select "Yes"
405  String oldPath = current.getConfigFilePath();
406  try {
407  current.updateCaseName(oldCaseName, oldPath , newCaseName, oldPath);
408  } catch (Exception ex) {
409  Logger.getLogger(CasePropertiesForm.class.getName()).log(Level.WARNING, "Error: problem updating case name.", ex); //NON-NLS
410  }
411  }
412  }
413  }
414  }
415  }//GEN-LAST:event_updateCaseNameButtonActionPerformed
416 
417  private void deleteCaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteCaseButtonActionPerformed
418  CallableSystemAction.get(CaseDeleteAction.class).actionPerformed(evt);
419  }//GEN-LAST:event_deleteCaseButtonActionPerformed
420 
421 
427  public void setOKButtonActionListener(ActionListener e){
428  OKButton.addActionListener(e);
429  }
430 
431  // Variables declaration - do not modify//GEN-BEGIN:variables
432  private javax.swing.JButton OKButton;
433  private javax.swing.JLabel caseDirLabel;
434  private javax.swing.JTextArea caseDirTextArea;
435  private javax.swing.JLabel caseNameLabel;
436  private javax.swing.JTextField caseNameTextField;
437  private javax.swing.JLabel caseNumberLabel;
438  private javax.swing.JTextField caseNumberTextField;
439  private javax.swing.JLabel casePropLabel;
440  private javax.swing.JLabel crDateLabel;
441  private javax.swing.JTextField crDateTextField;
442  private javax.swing.JButton deleteCaseButton;
443  private javax.swing.JLabel examinerLabel;
444  private javax.swing.JTextField examinerTextField;
445  private javax.swing.JLabel genInfoLabel;
446  private javax.swing.JTable imagesTable;
447  private javax.swing.JScrollPane imagesTableScrollPane;
448  private javax.swing.JLabel imgInfoLabel;
449  private javax.swing.JScrollPane jScrollPane1;
450  private javax.swing.JScrollPane jScrollPane2;
451  private javax.swing.JTextArea jTextArea1;
452  private javax.swing.JButton updateCaseNameButton;
453  // End of variables declaration//GEN-END:variables
454 
455 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.