19 package org.sleuthkit.autopsy.report.modules.taggedhashes;
21 import java.awt.Component;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.util.ArrayList;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 import java.util.Objects;
31 import java.util.logging.Level;
32 import javax.swing.JCheckBox;
33 import javax.swing.JLabel;
34 import javax.swing.JList;
35 import javax.swing.JOptionPane;
36 import javax.swing.ListCellRenderer;
37 import javax.swing.ListModel;
38 import javax.swing.event.ListDataListener;
52 @SuppressWarnings(
"PMD.SingularField")
53 class SaveTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel {
55 private static final long serialVersionUID = 1L;
56 private List<TagName> tagNames;
57 private Map<String, Boolean> tagNameSelections =
new LinkedHashMap<>();
58 private TagNamesListModel tagsNamesListModel;
59 private TagsNamesListCellRenderer tagsNamesRenderer;
60 private String selectedHashSetName;
61 private List<HashDb> updateableHashSets =
new ArrayList<>();
63 SaveTaggedHashesToHashDbConfigPanel() {
65 customizeComponents();
73 tagNamesListBox.addMouseListener(
new MouseAdapter() {
75 public void mousePressed(MouseEvent evt) {
76 if (jAllTagsCheckBox.isSelected()) {
79 JList<?> list = (JList) evt.getSource();
80 int index = list.locationToIndex(evt.getPoint());
82 String value = tagsNamesListModel.getElementAt(index);
83 tagNameSelections.put(value, !tagNameSelections.get(value));
89 this.jAllTagsCheckBox.addItemListener(
new ItemListener() {
91 public void itemStateChanged(ItemEvent e) {
92 tagNamesListBox.setEnabled(!jAllTagsCheckBox.isSelected());
93 selectAllButton.setEnabled(!jAllTagsCheckBox.isSelected());
94 deselectAllButton.setEnabled(!jAllTagsCheckBox.isSelected());
95 selectAllTags(jAllTagsCheckBox.isSelected());
100 HashesReportModuleSettings getConfiguration() {
101 return new HashesReportModuleSettings(jAllTagsCheckBox.isSelected(), selectedHashSetName);
104 void setConfiguration(HashesReportModuleSettings settings) {
107 customizeComponents();
110 jAllTagsCheckBox.setSelected(settings.isExportAllTags());
111 if (settings.isExportAllTags()) {
116 if (settings.getHashDbName() != null) {
117 populateHashSetComponents();
118 hashSetsComboBox.setSelectedItem(settings.getHashDbName());
122 private void customizeComponents() {
123 populateTagNameComponents();
125 tagsNamesListModel =
new TagNamesListModel();
126 tagsNamesRenderer =
new TagsNamesListCellRenderer();
127 tagNamesListBox.setModel(tagsNamesListModel);
128 tagNamesListBox.setCellRenderer(tagsNamesRenderer);
129 tagNamesListBox.setVisibleRowCount(-1);
131 populateHashSetComponents();
134 private void populateTagNameComponents() {
136 tagNames =
new ArrayList<>();
137 Map<String, Boolean> updatedTagNameSelections =
new LinkedHashMap<>();
140 tagNames = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
141 }
catch (TskCoreException ex) {
142 Logger.getLogger(SaveTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
143 }
catch (NoCurrentCaseException ex) {
145 if (Case.isCaseOpen()) {
146 Logger.getLogger(SaveTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
153 for (TagName tagName : tagNames) {
154 if (tagNameSelections.get(tagName.getDisplayName()) != null && Objects.equals(tagNameSelections.get(tagName.getDisplayName()), Boolean.TRUE)) {
155 updatedTagNameSelections.put(tagName.getDisplayName(), Boolean.TRUE);
157 updatedTagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
160 tagNameSelections = updatedTagNameSelections;
163 private void populateHashSetComponents() {
166 hashSetsComboBox.removeAllItems();
167 selectedHashSetName =
"";
171 updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets();
172 if (!updateableHashSets.isEmpty()) {
173 for (HashDb hashDb : updateableHashSets) {
174 hashSetsComboBox.addItem(hashDb.getHashSetName());
176 hashSetsComboBox.setEnabled(
true);
178 hashSetsComboBox.setEnabled(
false);
187 List<TagName> getSelectedTagNames() {
188 List<TagName> selectedTagNames =
new ArrayList<>();
189 for (TagName tagName : tagNames) {
190 if (tagNameSelections.get(tagName.getDisplayName())) {
191 selectedTagNames.add(tagName);
194 return selectedTagNames;
202 HashDb getSelectedHashDatabase() {
203 for (HashDb hashDb : updateableHashSets) {
204 if (hashDb.getHashSetName().equals(selectedHashSetName)) {
216 return tagNames.size();
221 return tagNames.get(index).getDisplayName();
235 private static final long serialVersionUID = 1L;
240 setEnabled(list.isEnabled());
241 setSelected(tagNameSelections.get(value));
242 setFont(list.getFont());
243 setBackground(list.getBackground());
244 setForeground(list.getForeground());
257 @SuppressWarnings(
"unchecked")
259 private
void initComponents() {
261 jScrollPane1 =
new javax.swing.JScrollPane();
262 tagNamesListBox =
new javax.swing.JList<>();
263 selectAllButton =
new javax.swing.JButton();
264 deselectAllButton =
new javax.swing.JButton();
265 jLabel1 =
new javax.swing.JLabel();
266 hashSetsComboBox =
new javax.swing.JComboBox<>();
267 configureHashDatabasesButton =
new javax.swing.JButton();
268 jLabel2 =
new javax.swing.JLabel();
269 jAllTagsCheckBox =
new javax.swing.JCheckBox();
271 jScrollPane1.setViewportView(tagNamesListBox);
273 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.selectAllButton.text"));
274 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
275 public void actionPerformed(java.awt.event.ActionEvent evt) {
276 selectAllButtonActionPerformed(evt);
280 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.deselectAllButton.text"));
281 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
282 public void actionPerformed(java.awt.event.ActionEvent evt) {
283 deselectAllButtonActionPerformed(evt);
287 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jLabel1.text"));
289 hashSetsComboBox.addActionListener(
new java.awt.event.ActionListener() {
290 public void actionPerformed(java.awt.event.ActionEvent evt) {
291 hashSetsComboBoxActionPerformed(evt);
295 org.openide.awt.Mnemonics.setLocalizedText(configureHashDatabasesButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.configureHashDatabasesButton.text"));
296 configureHashDatabasesButton.addActionListener(
new java.awt.event.ActionListener() {
297 public void actionPerformed(java.awt.event.ActionEvent evt) {
298 configureHashDatabasesButtonActionPerformed(evt);
302 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jLabel2.text"));
304 org.openide.awt.Mnemonics.setLocalizedText(jAllTagsCheckBox,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jAllTagsCheckBox.text"));
305 jAllTagsCheckBox.addActionListener(
new java.awt.event.ActionListener() {
306 public void actionPerformed(java.awt.event.ActionEvent evt) {
307 jAllTagsCheckBoxActionPerformed(evt);
311 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
312 this.setLayout(layout);
313 layout.setHorizontalGroup(
314 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315 .addGroup(layout.createSequentialGroup()
317 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318 .addGroup(layout.createSequentialGroup()
319 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
321 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
322 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
323 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
324 .addGroup(layout.createSequentialGroup()
325 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addComponent(jAllTagsCheckBox)
327 .addComponent(jLabel1)
328 .addGroup(layout.createSequentialGroup()
329 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
330 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331 .addComponent(configureHashDatabasesButton))
332 .addComponent(jLabel2))
333 .addGap(0, 0, Short.MAX_VALUE)))
337 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deselectAllButton, selectAllButton});
339 layout.setVerticalGroup(
340 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
341 .addGroup(layout.createSequentialGroup()
342 .addComponent(jLabel1)
343 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
344 .addComponent(jAllTagsCheckBox)
345 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
346 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347 .addGroup(layout.createSequentialGroup()
348 .addComponent(selectAllButton)
349 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350 .addComponent(deselectAllButton))
351 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
352 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
353 .addComponent(jLabel2)
355 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
356 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
357 .addComponent(configureHashDatabasesButton))
362 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
366 private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
367 selectedHashSetName = (String)hashSetsComboBox.getSelectedItem();
370 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
371 selectAllTags(
false);
374 private void configureHashDatabasesButtonActionPerformed(java.awt.event.ActionEvent evt) {
375 HashLookupSettingsPanel configPanel =
new HashLookupSettingsPanel();
377 if (JOptionPane.showConfirmDialog(
this, configPanel,
"Hash Set Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
379 populateHashSetComponents();
381 configPanel.cancel();
382 populateHashSetComponents();
386 private void selectAllTags(
boolean select) {
387 Boolean state = Boolean.TRUE;
389 state = Boolean.FALSE;
391 for (TagName tagName : tagNames) {
392 tagNameSelections.put(tagName.getDisplayName(), state);
394 tagNamesListBox.repaint();
396 private void jAllTagsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
401 private javax.swing.JButton configureHashDatabasesButton;
402 private javax.swing.JButton deselectAllButton;
403 private javax.swing.JComboBox<String> hashSetsComboBox;
404 private javax.swing.JCheckBox jAllTagsCheckBox;
405 private javax.swing.JLabel jLabel1;
406 private javax.swing.JLabel jLabel2;
407 private javax.swing.JScrollPane jScrollPane1;
408 private javax.swing.JButton selectAllButton;
409 private javax.swing.JList<String> tagNamesListBox;
void removeListDataListener(ListDataListener l)
String getElementAt(int index)
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)
void addListDataListener(ListDataListener l)