Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
GlobalEditListPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.awt.EventQueue;
22 import java.awt.event.ActionListener;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.io.File;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.logging.Level;
30 import java.util.regex.Pattern;
31 import java.util.regex.PatternSyntaxException;
32 import javax.swing.JFileChooser;
33 import javax.swing.JTable;
34 import javax.swing.ListSelectionModel;
35 import javax.swing.event.ListSelectionEvent;
36 import javax.swing.event.ListSelectionListener;
37 import javax.swing.filechooser.FileNameExtensionFilter;
38 import javax.swing.table.AbstractTableModel;
39 import javax.swing.table.TableColumn;
40 import org.netbeans.spi.options.OptionsPanelController;
41 import org.openide.util.NbBundle;
45 import java.awt.Component;
46 import java.awt.Dimension;
47 import java.awt.FlowLayout;
48 import javax.swing.ImageIcon;
49 import javax.swing.JCheckBox;
50 import javax.swing.JLabel;
51 import javax.swing.JOptionPane;
52 import javax.swing.JPanel;
53 import javax.swing.JTextField;
54 import static javax.swing.SwingConstants.CENTER;
55 import javax.swing.table.DefaultTableCellRenderer;
56 import org.openide.util.NbBundle.Messages;
57 
61 class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionListener, OptionsPanel {
62 
63  private static final Logger logger = Logger.getLogger(GlobalEditListPanel.class.getName());
64  private static final long serialVersionUID = 1L;
65  private final KeywordTableModel tableModel;
66  private KeywordList currentKeywordList;
67 
71  GlobalEditListPanel() {
72  tableModel = new KeywordTableModel();
73  initComponents();
74  customizeComponents();
75  }
76 
77  private void customizeComponents() {
78  newWordButton.setToolTipText((NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.addWordToolTip")));
79  exportButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.exportToFile"));
80  saveListButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.saveCurrentWIthNewNameToolTip"));
81  deleteWordButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.removeSelectedMsg"));
82 
83  keywordTable.getParent().setBackground(keywordTable.getBackground());
84  final int width = jScrollPane1.getPreferredSize().width;
85  keywordTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
86  TableColumn column;
87  for (int i = 0; i < keywordTable.getColumnCount(); i++) {
88  column = keywordTable.getColumnModel().getColumn(i);
89  if (i == 0) {
90  column.setPreferredWidth(((int) (width * 0.90)));
91  } else {
92  column.setPreferredWidth(((int) (width * 0.10)));
93  column.setCellRenderer(new CheckBoxRenderer());
94  }
95  }
96  keywordTable.setCellSelectionEnabled(false);
97  keywordTable.setRowSelectionAllowed(true);
98 
99  final ListSelectionModel lsm = keywordTable.getSelectionModel();
100  lsm.addListSelectionListener(new ListSelectionListener() {
101  @Override
102  public void valueChanged(ListSelectionEvent e) {
103  if (lsm.isSelectionEmpty() || currentKeywordList.isEditable() || IngestManager.getInstance().isIngestRunning()) {
104  deleteWordButton.setEnabled(false);
105  } else {
106  deleteWordButton.setEnabled(true);
107  }
108  }
109  });
110 
111  setButtonStates();
112 
113  setButtonStates();
114 
115  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
116  @Override
117  public void propertyChange(PropertyChangeEvent evt) {
118  Object source = evt.getSource();
119  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
120  EventQueue.invokeLater(new Runnable() {
121  @Override
122  public void run() {
123  setButtonStates();
124  }
125  });
126  }
127  }
128  });
129  }
130 
131  void setButtonStates() {
132  boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
133  boolean isListSelected = currentKeywordList != null;
134 
135  // items that only need a selected list
136  boolean canEditList = ((isListSelected == true) && (isIngestRunning == false));
137  ingestMessagesCheckbox.setEnabled(canEditList);
138  ingestMessagesCheckbox.setSelected(currentKeywordList != null && currentKeywordList.getIngestMessages());
139  listOptionsLabel.setEnabled(canEditList);
140  listOptionsSeparator.setEnabled(canEditList);
141 
142  // items that need an unlocked list w/out ingest running
143  boolean isListLocked = ((isListSelected == false) || (currentKeywordList.isEditable()));
144  boolean canAddWord = isListSelected && !isIngestRunning && !isListLocked;
145  newWordButton.setEnabled(canAddWord);
146  keywordOptionsLabel.setEnabled(canAddWord);
147  keywordOptionsSeparator.setEnabled(canAddWord);
148  deleteListButton.setEnabled(canAddWord);
149 
150  // items that need a non-empty list
151  if ((currentKeywordList == null) || (currentKeywordList.getKeywords().isEmpty())) {
152  saveListButton.setEnabled(false);
153  exportButton.setEnabled(false);
154  deleteWordButton.setEnabled(false);
155  } else {
156  saveListButton.setEnabled(true);
157  exportButton.setEnabled(true);
158  // We do not set deleteWordButton because it will be set by the list select model code when a word is selected.
159  }
160  }
161 
167  @SuppressWarnings("unchecked")
168  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
169  private void initComponents() {
170 
171  listEditorPanel = new javax.swing.JPanel();
172  jScrollPane1 = new javax.swing.JScrollPane();
173  keywordTable = new javax.swing.JTable();
174  addKeywordPanel = new javax.swing.JPanel();
175  newWordButton = new javax.swing.JButton();
176  deleteWordButton = new javax.swing.JButton();
177  ingestMessagesCheckbox = new javax.swing.JCheckBox();
178  keywordsLabel = new javax.swing.JLabel();
179  keywordOptionsLabel = new javax.swing.JLabel();
180  listOptionsLabel = new javax.swing.JLabel();
181  keywordOptionsSeparator = new javax.swing.JSeparator();
182  listOptionsSeparator = new javax.swing.JSeparator();
183  deleteListButton = new javax.swing.JButton();
184  saveListButton = new javax.swing.JButton();
185  exportButton = new javax.swing.JButton();
186 
187  setMinimumSize(new java.awt.Dimension(0, 0));
188 
189  listEditorPanel.setMinimumSize(new java.awt.Dimension(0, 0));
190 
191  jScrollPane1.setPreferredSize(new java.awt.Dimension(340, 300));
192 
193  keywordTable.setModel(tableModel);
194  keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
195  keywordTable.setGridColor(new java.awt.Color(153, 153, 153));
196  keywordTable.setMaximumSize(new java.awt.Dimension(30000, 30000));
197  keywordTable.getTableHeader().setReorderingAllowed(false);
198  jScrollPane1.setViewportView(keywordTable);
199 
200  newWordButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/new16.png"))); // NOI18N
201  newWordButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.addWordButton.text")); // NOI18N
202  newWordButton.addActionListener(new java.awt.event.ActionListener() {
203  public void actionPerformed(java.awt.event.ActionEvent evt) {
204  newWordButtonActionPerformed(evt);
205  }
206  });
207 
208  deleteWordButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/delete16.png"))); // NOI18N
209  deleteWordButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.deleteWordButton.text")); // NOI18N
210  deleteWordButton.addActionListener(new java.awt.event.ActionListener() {
211  public void actionPerformed(java.awt.event.ActionEvent evt) {
212  deleteWordButtonActionPerformed(evt);
213  }
214  });
215 
216  javax.swing.GroupLayout addKeywordPanelLayout = new javax.swing.GroupLayout(addKeywordPanel);
217  addKeywordPanel.setLayout(addKeywordPanelLayout);
218  addKeywordPanelLayout.setHorizontalGroup(
219  addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addGroup(addKeywordPanelLayout.createSequentialGroup()
221  .addComponent(newWordButton)
222  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223  .addComponent(deleteWordButton)
224  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
225  );
226  addKeywordPanelLayout.setVerticalGroup(
227  addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addGroup(addKeywordPanelLayout.createSequentialGroup()
229  .addGap(0, 0, 0)
230  .addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
231  .addComponent(newWordButton)
232  .addComponent(deleteWordButton))
233  .addGap(72, 72, 72))
234  );
235 
236  ingestMessagesCheckbox.setSelected(true);
237  ingestMessagesCheckbox.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.ingestMessagesCheckbox.text")); // NOI18N
238  ingestMessagesCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.ingestMessagesCheckbox.toolTipText")); // NOI18N
239  ingestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
240  public void actionPerformed(java.awt.event.ActionEvent evt) {
241  ingestMessagesCheckboxActionPerformed(evt);
242  }
243  });
244 
245  keywordsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.keywordsLabel.text")); // NOI18N
246 
247  keywordOptionsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.keywordOptionsLabel.text")); // NOI18N
248 
249  listOptionsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.listOptionsLabel.text")); // NOI18N
250 
251  deleteListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/delete16.png"))); // NOI18N
252  deleteListButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.deleteListButton.text")); // NOI18N
253  deleteListButton.addActionListener(new java.awt.event.ActionListener() {
254  public void actionPerformed(java.awt.event.ActionEvent evt) {
255  deleteListButtonActionPerformed(evt);
256  }
257  });
258 
259  saveListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/save16.png"))); // NOI18N
260  saveListButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.saveListButton.text")); // NOI18N
261 
262  exportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/export16.png"))); // NOI18N
263  exportButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.exportButton.text")); // NOI18N
264  exportButton.addActionListener(new java.awt.event.ActionListener() {
265  public void actionPerformed(java.awt.event.ActionEvent evt) {
266  exportButtonActionPerformed(evt);
267  }
268  });
269 
270  javax.swing.GroupLayout listEditorPanelLayout = new javax.swing.GroupLayout(listEditorPanel);
271  listEditorPanel.setLayout(listEditorPanelLayout);
272  listEditorPanelLayout.setHorizontalGroup(
273  listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274  .addGroup(listEditorPanelLayout.createSequentialGroup()
275  .addContainerGap()
276  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277  .addGroup(listEditorPanelLayout.createSequentialGroup()
278  .addGap(10, 10, 10)
279  .addComponent(addKeywordPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
280  .addGroup(listEditorPanelLayout.createSequentialGroup()
281  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282  .addGroup(listEditorPanelLayout.createSequentialGroup()
283  .addComponent(listOptionsLabel)
284  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
285  .addComponent(listOptionsSeparator))
286  .addGroup(listEditorPanelLayout.createSequentialGroup()
287  .addComponent(keywordOptionsLabel)
288  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
289  .addComponent(keywordOptionsSeparator))
290  .addGroup(listEditorPanelLayout.createSequentialGroup()
291  .addGap(10, 10, 10)
292  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE))
293  .addGroup(listEditorPanelLayout.createSequentialGroup()
294  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
295  .addComponent(keywordsLabel)
296  .addGroup(listEditorPanelLayout.createSequentialGroup()
297  .addGap(10, 10, 10)
298  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299  .addComponent(ingestMessagesCheckbox)
300  .addGroup(listEditorPanelLayout.createSequentialGroup()
301  .addComponent(exportButton)
302  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
303  .addComponent(saveListButton)
304  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305  .addComponent(deleteListButton)))))
306  .addGap(0, 0, Short.MAX_VALUE)))
307  .addContainerGap())))
308  );
309  listEditorPanelLayout.setVerticalGroup(
310  listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listEditorPanelLayout.createSequentialGroup()
312  .addContainerGap()
313  .addComponent(keywordsLabel)
314  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
316  .addGap(10, 10, 10)
317  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318  .addGroup(listEditorPanelLayout.createSequentialGroup()
319  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
320  .addComponent(keywordOptionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
321  .addComponent(keywordOptionsLabel))
322  .addGap(7, 7, 7)
323  .addComponent(addKeywordPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
324  .addGap(0, 0, 0)
325  .addComponent(listOptionsLabel))
326  .addGroup(listEditorPanelLayout.createSequentialGroup()
327  .addGap(123, 123, 123)
328  .addComponent(listOptionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)))
329  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
330  .addComponent(ingestMessagesCheckbox)
331  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
333  .addComponent(exportButton)
334  .addComponent(saveListButton)
335  .addComponent(deleteListButton))
336  .addContainerGap())
337  );
338 
339  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
340  this.setLayout(layout);
341  layout.setHorizontalGroup(
342  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
343  .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
344  );
345  layout.setVerticalGroup(
346  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347  .addGroup(layout.createSequentialGroup()
348  .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
349  .addGap(5, 5, 5))
350  );
351  }// </editor-fold>//GEN-END:initComponents
352 
353  private void newWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newWordButtonActionPerformed
354  JCheckBox chRegex = new JCheckBox(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.chRegex.text"));
355  chRegex.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.kwReToolTip"));
356  JTextField addWordField = new JTextField(25);
357  addWordField.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.enterNewWordToolTip"));
358 
359  JPanel addKeywordPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
360  addKeywordPanel.add(new JLabel(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addKeyword.message")));
361  addKeywordPanel.add(addWordField);
362  addKeywordPanel.add(chRegex);
363 
364  addKeywordPanel.setPreferredSize(new Dimension(250, 80));
365 
366  int result = JOptionPane.showConfirmDialog(null, addKeywordPanel,
367  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addKeyword.title"),
368  JOptionPane.OK_CANCEL_OPTION);
369 
370  if (result == JOptionPane.OK_OPTION) {
371  String newWord = addWordField.getText().trim();
372  boolean isLiteral = !chRegex.isSelected();
373  final Keyword keyword = new Keyword(newWord, isLiteral);
374 
375  if (newWord.equals("")) {
376  return;
377  } else if (currentKeywordList.hasKeyword(keyword)) {
378  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
379  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addWordButtonAction.kwAlreadyExistsMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
380  return;
381  }
382 
383  //check if valid
384  boolean valid = true;
385  try {
386  Pattern.compile(newWord);
387  } catch (PatternSyntaxException ex1) {
388  valid = false;
389  } catch (IllegalArgumentException ex2) {
390  valid = false;
391  }
392  if (!valid) {
393  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
394  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.invalidKwMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
395  return;
396  }
397 
398  //add & reset checkbox
399  tableModel.addKeyword(keyword);
400  XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
401  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
402  setFocusOnKeywordTextBox();
403  setButtonStates();
404  } else {
405  return;
406  }
407  }//GEN-LAST:event_newWordButtonActionPerformed
408 
409  private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWordButtonActionPerformed
410  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.removeKwMsg"), NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.deleteWordButtonActionPerformed.delConfirmMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
411 
412  tableModel.deleteSelected(keywordTable.getSelectedRows());
413  XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
414  setButtonStates();
415  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
416  }
417  }//GEN-LAST:event_deleteWordButtonActionPerformed
418 
419  private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
420 
421  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
422  "KeywordSearchEditListPanel.exportButtonAction.featureName.text");
423 
424  JFileChooser chooser = new JFileChooser();
425  final String EXTENSION = "xml"; //NON-NLS
426  FileNameExtensionFilter filter = new FileNameExtensionFilter(
427  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileFilterLabel"), EXTENSION);
428  chooser.setFileFilter(filter);
429  chooser.setSelectedFile(new File(currentKeywordList.getName()));
430  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
431 
432  int returnVal = chooser.showSaveDialog(this);
433  if (returnVal == JFileChooser.APPROVE_OPTION) {
434  File selFile = chooser.getSelectedFile();
435  if (selFile == null) {
436  return;
437  }
438 
439  //force append extension if not given
440  String fileAbs = selFile.getAbsolutePath();
441  if (!fileAbs.endsWith("." + EXTENSION)) {
442  fileAbs = fileAbs + "." + EXTENSION;
443  selFile = new File(fileAbs);
444  }
445 
446  boolean shouldWrite = true;
447  if (selFile.exists()) {
448  shouldWrite = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME,
449  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileExistPrompt",
450  selFile.getName()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
451  }
452  if (!shouldWrite) {
453  return;
454  }
455 
456  XmlKeywordSearchList reader = XmlKeywordSearchList.getCurrent();
457 
458  List<KeywordList> toWrite = new ArrayList<>();
459  toWrite.add(reader.getList(currentKeywordList.getName()));
460  final XmlKeywordSearchList exporter = new XmlKeywordSearchList(fileAbs);
461  boolean written = exporter.saveLists(toWrite);
462  if (written) {
463  KeywordSearchUtil.displayDialog(FEATURE_NAME,
464  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.kwListExportedMsg"),
465  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
466  }
467  }
468  }//GEN-LAST:event_exportButtonActionPerformed
469 
470  private void ingestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ingestMessagesCheckboxActionPerformed
471  currentKeywordList.setIngestMessages(ingestMessagesCheckbox.isSelected());
472  XmlKeywordSearchList updater = XmlKeywordSearchList.getCurrent();
473  updater.addList(currentKeywordList);
474  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
475  }//GEN-LAST:event_ingestMessagesCheckboxActionPerformed
476 
477  private void deleteListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteListButtonActionPerformed
478  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
479  }//GEN-LAST:event_deleteListButtonActionPerformed
480 
481  // Variables declaration - do not modify//GEN-BEGIN:variables
482  private javax.swing.JPanel addKeywordPanel;
483  private javax.swing.JButton deleteListButton;
484  private javax.swing.JButton deleteWordButton;
485  private javax.swing.JButton exportButton;
486  private javax.swing.JCheckBox ingestMessagesCheckbox;
487  private javax.swing.JScrollPane jScrollPane1;
488  private javax.swing.JLabel keywordOptionsLabel;
489  private javax.swing.JSeparator keywordOptionsSeparator;
490  private javax.swing.JTable keywordTable;
491  private javax.swing.JLabel keywordsLabel;
492  private javax.swing.JPanel listEditorPanel;
493  private javax.swing.JLabel listOptionsLabel;
494  private javax.swing.JSeparator listOptionsSeparator;
495  private javax.swing.JButton newWordButton;
496  private javax.swing.JButton saveListButton;
497  // End of variables declaration//GEN-END:variables
498 
499  @Override
500  public void valueChanged(ListSelectionEvent e) {
501  //respond to list selection changes in KeywordSearchListManagementPanel
502  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
503  if (!listSelectionModel.isSelectionEmpty()) {
504  int index = listSelectionModel.getMinSelectionIndex();
505 
506  listSelectionModel.setSelectionInterval(index, index);
507  XmlKeywordSearchList loader = XmlKeywordSearchList.getCurrent();
508 
509  currentKeywordList = loader.getListsL(false).get(index);
510  tableModel.resync();
511  setButtonStates();
512  } else {
513  currentKeywordList = null;
514  tableModel.resync();
515  setButtonStates();
516  }
517  }
518 
519  @Override
520  public void store() {
521  // Implemented by parent panel
522  }
523 
524  @Override
525  public void load() {
526  // Implemented by parent panel
527  }
528 
529  KeywordList getCurrentKeywordList() {
530  return currentKeywordList;
531  }
532 
533  void setCurrentKeywordList(KeywordList list) {
534  currentKeywordList = list;
535  }
536 
537  void addDeleteButtonActionPerformed(ActionListener l) {
538  deleteListButton.addActionListener(l);
539  }
540 
541  void addSaveButtonActionPerformed(ActionListener l) {
542  saveListButton.addActionListener(l);
543  }
544 
545  private class KeywordTableModel extends AbstractTableModel {
546 
547  @Override
548  public int getColumnCount() {
549  return 2;
550  }
551 
552  @Override
553  public int getRowCount() {
554  return currentKeywordList == null ? 0 : currentKeywordList.getKeywords().size();
555  }
556 
557  @Override
558  public String getColumnName(int column) {
559  String colName = null;
560 
561  switch (column) {
562  case 0:
563  colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.kwColName");
564  break;
565  case 1:
566  colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.regExColName");
567  break;
568  default:
569  ;
570 
571  }
572  return colName;
573  }
574 
575  @Override
576  public Object getValueAt(int rowIndex, int columnIndex) {
577  Object ret = null;
578  if (currentKeywordList == null) {
579  return "";
580  }
581  Keyword word = currentKeywordList.getKeywords().get(rowIndex);
582  switch (columnIndex) {
583  case 0:
584  ret = (Object) word.getSearchTerm();
585  break;
586  case 1:
587  ret = (Object) !word.searchTermIsLiteral();
588  break;
589  default:
590  logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
591  break;
592  }
593  return ret;
594  }
595 
596  @Override
597  public boolean isCellEditable(int rowIndex, int columnIndex) {
598  return false;
599  }
600 
601  @Override
602  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
603  }
604 
605  @Override
606  public Class<?> getColumnClass(int c) {
607  return getValueAt(0, c).getClass();
608  }
609 
610  void addKeyword(Keyword keyword) {
611  if (!currentKeywordList.hasKeyword(keyword)) {
612  currentKeywordList.getKeywords().add(keyword);
613  }
614  fireTableDataChanged();
615  }
616 
617  void resync() {
618  fireTableDataChanged();
619  }
620 
621  //delete selected from handle, events are fired from the handle
622  void deleteSelected(int[] selected) {
623  List<Keyword> words = currentKeywordList.getKeywords();
624  Arrays.sort(selected);
625  for (int arrayi = selected.length - 1; arrayi >= 0; arrayi--) {
626  words.remove(selected[arrayi]);
627  }
628  resync();
629  }
630  }
631 
636  private class CheckBoxRenderer extends DefaultTableCellRenderer {
637 
638  private static final long serialVersionUID = 1L;
639  final ImageIcon theCheck = new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/checkmark.png")); // NON-NLS
640 
641  CheckBoxRenderer() {
642  setHorizontalAlignment(CENTER);
643  }
644 
645  @Override
646  @Messages("IsRegularExpression=Keyword is a regular expression")
647  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
648 
649  if ((value instanceof Boolean)) {
650  if ((Boolean) value) {
651  setIcon(theCheck);
652  setToolTipText(Bundle.IsRegularExpression());
653  } else {
654  setIcon(null);
655  setToolTipText(null);
656  }
657  }
658  return this;
659  }
660  }
661 
665  void setFocusOnKeywordTextBox() {
666  newWordButton.requestFocus();
667  }
668 }
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

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