26 package org.sleuthkit.autopsy.casemodule;
29 import java.awt.event.ActionListener;
32 import java.util.logging.Level;
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;
49 class CasePropertiesForm
extends javax.swing.JPanel{
52 private static JPanel caller;
56 private String shrinkPath(String path,
int targetLength) {
57 if(path.length() > targetLength){
60 int partsLength = targetLength - fill.length();
62 String front = path.substring(0, partsLength/4);
63 int frontSep = front.lastIndexOf(File.separatorChar);
65 front = front.substring(0, frontSep+1);
68 String back = path.substring(partsLength*3/4);
69 int backSep = back.indexOf(File.separatorChar);
71 back = back.substring(backSep);
73 return back + fill + front;
81 CasePropertiesForm(Case currentCase, String crDate, String caseDir, Map<Long, String> imgPaths) {
83 caseNameTextField.setText(currentCase.getName());
84 caseNumberTextField.setText(currentCase.getNumber());
85 examinerTextField.setText(currentCase.getExaminer());
86 crDateTextField.setText(crDate);
87 caseDirTextArea.setText(caseDir);
89 current = currentCase;
91 int totalImages = imgPaths.size();
94 String[] headers = {
"Path"};
95 String[][] rows =
new String[totalImages][];
98 for(
long key : imgPaths.keySet()){
99 String path = imgPaths.get(key);
100 String shortenPath = shrinkPath(path, 70);
101 rows[i++] =
new String[]{shortenPath};
105 DefaultTableModel model =
new DefaultTableModel(rows, headers)
109 public boolean isCellEditable(
int row,
int column){
114 imagesTable.setModel(model);
165 @SuppressWarnings(
"unchecked")
167 private
void initComponents() {
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();
191 jTextArea1.setColumns(20);
192 jTextArea1.setRows(5);
193 jScrollPane1.setViewportView(jTextArea1);
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"));
199 caseNameLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNameLabel.text"));
201 crDateLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.crDateLabel.text"));
203 caseDirLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseDirLabel.text"));
205 crDateTextField.setEditable(
false);
206 crDateTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.crDateTextField.text"));
208 caseNameTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNameTextField.text"));
210 updateCaseNameButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.updateCaseNameButton.text"));
211 updateCaseNameButton.addActionListener(
new java.awt.event.ActionListener() {
212 public void actionPerformed(java.awt.event.ActionEvent evt) {
213 updateCaseNameButtonActionPerformed(evt);
217 genInfoLabel.setFont(genInfoLabel.getFont().deriveFont(Font.BOLD, 14));
218 genInfoLabel.setText(
219 org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.genInfoLabel.text"));
221 imgInfoLabel.setFont(imgInfoLabel.getFont().deriveFont(Font.BOLD, 14));
222 imgInfoLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.imgInfoLabel.text"));
224 OKButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.OKButton.text"));
226 imagesTable.setModel(
new javax.swing.table.DefaultTableModel(
234 boolean[] canEdit =
new boolean [] {
238 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
239 return canEdit [columnIndex];
242 imagesTable.setShowHorizontalLines(
false);
243 imagesTable.setShowVerticalLines(
false);
244 imagesTable.getTableHeader().setReorderingAllowed(
false);
245 imagesTable.setUpdateSelectionOnSort(
false);
246 imagesTableScrollPane.setViewportView(imagesTable);
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);
255 deleteCaseButton.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.deleteCaseButton.text"));
256 deleteCaseButton.addActionListener(
new java.awt.event.ActionListener() {
257 public void actionPerformed(java.awt.event.ActionEvent evt) {
258 deleteCaseButtonActionPerformed(evt);
262 caseNumberLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNumberLabel.text"));
264 examinerLabel.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.examinerLabel.text"));
266 caseNumberTextField.setEditable(
false);
267 caseNumberTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.caseNumberTextField.text"));
269 examinerTextField.setEditable(
false);
270 examinerTextField.setText(
org.openide.util.NbBundle.getMessage(CasePropertiesForm.class,
"CasePropertiesForm.examinerTextField.text"));
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()
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))
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)
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))
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))))
314 layout.setVerticalGroup(
315 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316 .addGroup(layout.createSequentialGroup()
318 .addComponent(casePropLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
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))
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))
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)
360 private void updateCaseNameButtonActionPerformed(java.awt.event.ActionEvent evt) {
361 String oldCaseName = Case.getCurrentCase().getName();
362 String newCaseName = caseNameTextField.getText();
367 if(!oldCaseName.equals(newCaseName)){
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);
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);
393 String confMsg = NbBundle
394 .getMessage(this.getClass(),
"CasePropertiesForm.updateCaseName.confMsg.msg", oldCaseName,
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);
402 Object res = DialogDisplayer.getDefault().notify(d);
403 if(res != null && res == DialogDescriptor.YES_OPTION){
405 String oldPath = current.getConfigFilePath();
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);
417 private void deleteCaseButtonActionPerformed(java.awt.event.ActionEvent evt) {
418 CallableSystemAction.get(CaseDeleteAction.class).actionPerformed(evt);
427 public void setOKButtonActionListener(ActionListener e){
428 OKButton.addActionListener(e);
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;