19 package org.sleuthkit.autopsy.report.taggedhashes;
21 import java.awt.Component;
22 import java.awt.event.MouseAdapter;
23 import java.awt.event.MouseEvent;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.LinkedHashMap;
27 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.JCheckBox;
31 import javax.swing.JLabel;
32 import javax.swing.JList;
33 import javax.swing.JOptionPane;
34 import javax.swing.ListCellRenderer;
35 import javax.swing.ListModel;
36 import javax.swing.event.ListDataListener;
49 class AddTaggedHashesToHashDbConfigPanel
extends javax.swing.JPanel {
51 private static final long serialVersionUID = 1L;
52 private final static String NO_DATABASES_TEXT =
"No updateable hash sets";
53 private List<TagName> tagNames;
54 private final Map<String, Boolean> tagNameSelections =
new LinkedHashMap<>();
55 private final TagNamesListModel tagsNamesListModel =
new TagNamesListModel();
56 private final TagsNamesListCellRenderer tagsNamesRenderer =
new TagsNamesListCellRenderer();
57 private final Map<String, HashDb> hashSets =
new HashMap<>();
58 private HashDb selectedHashSet = null;
60 AddTaggedHashesToHashDbConfigPanel() {
62 customizeComponents();
65 private void customizeComponents() {
66 populateTagNameComponents();
67 populateHashSetComponents();
70 private void populateTagNameComponents() {
73 tagNames = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
74 }
catch (TskCoreException ex) {
75 Logger.getLogger(AddTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
76 JOptionPane.showMessageDialog(null,
"Error getting tag names for case.",
"Tag Names Not Found", JOptionPane.ERROR_MESSAGE);
82 for (TagName tagName : tagNames) {
83 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
89 tagNamesListBox.setModel(tagsNamesListModel);
90 tagNamesListBox.setCellRenderer(tagsNamesRenderer);
91 tagNamesListBox.setVisibleRowCount(-1);
92 tagNamesListBox.addMouseListener(
new MouseAdapter() {
94 public void mousePressed(MouseEvent evt) {
95 JList<?> list = (JList) evt.getSource();
96 int index = list.locationToIndex(evt.getPoint());
97 String value = tagsNamesListModel.getElementAt(index);
98 tagNameSelections.put(value, !tagNameSelections.get(value));
104 private void populateHashSetComponents() {
108 hashSetsComboBox.removeAllItems();
112 List<HashDb> updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets();
113 if (!updateableHashSets.isEmpty()) {
114 for (HashDb hashDb : updateableHashSets) {
115 hashSets.put(hashDb.getHashSetName(), hashDb);
116 hashSetsComboBox.addItem(hashDb.getHashSetName());
118 hashSetsComboBox.setEnabled(
true);
120 hashSetsComboBox.addItem(NO_DATABASES_TEXT);
121 hashSetsComboBox.setEnabled(
false);
130 List<TagName> getSelectedTagNames() {
131 List<TagName> selectedTagNames =
new ArrayList<>();
132 for (TagName tagName : tagNames) {
133 if (tagNameSelections.get(tagName.getDisplayName())) {
134 selectedTagNames.add(tagName);
137 return selectedTagNames;
145 HashDb getSelectedHashDatabase() {
146 return selectedHashSet;
154 return tagNames.size();
159 return tagNames.get(index).getDisplayName();
173 private static final long serialVersionUID = 1L;
178 setEnabled(list.isEnabled());
179 setSelected(tagNameSelections.get(value));
180 setFont(list.getFont());
181 setBackground(list.getBackground());
182 setForeground(list.getForeground());
195 @SuppressWarnings(
"unchecked")
197 private
void initComponents() {
199 jScrollPane1 =
new javax.swing.JScrollPane();
200 tagNamesListBox =
new javax.swing.JList<>();
201 selectAllButton =
new javax.swing.JButton();
202 deselectAllButton =
new javax.swing.JButton();
203 jLabel1 =
new javax.swing.JLabel();
204 hashSetsComboBox =
new javax.swing.JComboBox<>();
205 configureHashDatabasesButton =
new javax.swing.JButton();
206 jLabel2 =
new javax.swing.JLabel();
208 jScrollPane1.setViewportView(tagNamesListBox);
210 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.selectAllButton.text"));
211 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
212 public void actionPerformed(java.awt.event.ActionEvent evt) {
213 selectAllButtonActionPerformed(evt);
217 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.deselectAllButton.text"));
218 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
219 public void actionPerformed(java.awt.event.ActionEvent evt) {
220 deselectAllButtonActionPerformed(evt);
224 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.jLabel1.text"));
226 hashSetsComboBox.addActionListener(
new java.awt.event.ActionListener() {
227 public void actionPerformed(java.awt.event.ActionEvent evt) {
228 hashSetsComboBoxActionPerformed(evt);
232 org.openide.awt.Mnemonics.setLocalizedText(configureHashDatabasesButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.configureHashDatabasesButton.text"));
233 configureHashDatabasesButton.addActionListener(
new java.awt.event.ActionListener() {
234 public void actionPerformed(java.awt.event.ActionEvent evt) {
235 configureHashDatabasesButtonActionPerformed(evt);
239 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.jLabel2.text"));
241 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
242 this.setLayout(layout);
243 layout.setHorizontalGroup(
244 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245 .addGroup(layout.createSequentialGroup()
247 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addComponent(jLabel2)
249 .addComponent(jLabel1)
250 .addGroup(layout.createSequentialGroup()
251 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addComponent(jScrollPane1)
253 .addGroup(layout.createSequentialGroup()
254 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256 .addComponent(configureHashDatabasesButton)))
257 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
258 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
259 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
260 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
263 layout.setVerticalGroup(
264 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addGroup(layout.createSequentialGroup()
267 .addComponent(jLabel1)
268 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
269 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270 .addGroup(layout.createSequentialGroup()
271 .addComponent(selectAllButton)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
273 .addComponent(deselectAllButton))
274 .addComponent(jScrollPane1))
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
276 .addComponent(jLabel2)
278 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
279 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
280 .addComponent(configureHashDatabasesButton))
285 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
286 for (TagName tagName : tagNames) {
287 tagNameSelections.put(tagName.getDisplayName(), Boolean.TRUE);
289 tagNamesListBox.repaint();
292 private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
293 String key = (String)hashSetsComboBox.getSelectedItem();
294 selectedHashSet = hashSets.get(key);
297 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
298 for (TagName tagName : tagNames) {
299 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
301 tagNamesListBox.repaint();
304 private void configureHashDatabasesButtonActionPerformed(java.awt.event.ActionEvent evt) {
305 HashLookupSettingsPanel configPanel =
new HashLookupSettingsPanel();
307 if (JOptionPane.showConfirmDialog(null, configPanel,
"Hash Set Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
309 populateHashSetComponents();
311 configPanel.cancel();
312 populateHashSetComponents();
317 private javax.swing.JButton configureHashDatabasesButton;
318 private javax.swing.JButton deselectAllButton;
319 private javax.swing.JComboBox<String> hashSetsComboBox;
320 private javax.swing.JLabel jLabel1;
321 private javax.swing.JLabel jLabel2;
322 private javax.swing.JScrollPane jScrollPane1;
323 private javax.swing.JButton selectAllButton;
324 private javax.swing.JList<String> tagNamesListBox;
String getElementAt(int index)
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)
void removeListDataListener(ListDataListener l)
void addListDataListener(ListDataListener l)