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.LinkedHashMap;
26 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.JCheckBox;
30 import javax.swing.JLabel;
31 import javax.swing.JList;
32 import javax.swing.JOptionPane;
33 import javax.swing.ListCellRenderer;
34 import javax.swing.ListModel;
35 import javax.swing.event.ListDataListener;
49 class AddTaggedHashesToHashDbConfigPanel
extends javax.swing.JPanel {
51 private static final long serialVersionUID = 1L;
52 private List<TagName> tagNames;
53 private final Map<String, Boolean> tagNameSelections =
new LinkedHashMap<>();
54 private final TagNamesListModel tagsNamesListModel =
new TagNamesListModel();
55 private final TagsNamesListCellRenderer tagsNamesRenderer =
new TagsNamesListCellRenderer();
56 private HashDb selectedHashSet = null;
58 AddTaggedHashesToHashDbConfigPanel() {
60 customizeComponents();
63 private void customizeComponents() {
64 populateTagNameComponents();
65 populateHashSetComponents();
68 private void populateTagNameComponents() {
71 tagNames = Case.getOpenCase().getServices().getTagsManager().getTagNamesInUse();
72 }
catch (TskCoreException ex) {
73 Logger.getLogger(AddTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
74 JOptionPane.showMessageDialog(
this,
"Error getting tag names for case.",
"Tag Names Not Found", JOptionPane.ERROR_MESSAGE);
75 }
catch (NoCurrentCaseException ex) {
76 Logger.getLogger(AddTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
77 JOptionPane.showMessageDialog(
this,
"Error getting tag names for case.",
"Exception while getting open case.", JOptionPane.ERROR_MESSAGE);
83 for (TagName tagName : tagNames) {
84 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
90 tagNamesListBox.setModel(tagsNamesListModel);
91 tagNamesListBox.setCellRenderer(tagsNamesRenderer);
92 tagNamesListBox.setVisibleRowCount(-1);
93 tagNamesListBox.addMouseListener(
new MouseAdapter() {
95 public void mousePressed(MouseEvent evt) {
96 JList<?> list = (JList) evt.getSource();
97 int index = list.locationToIndex(evt.getPoint());
99 String value = tagsNamesListModel.getElementAt(index);
100 tagNameSelections.put(value, !tagNameSelections.get(value));
107 private void populateHashSetComponents() {
110 hashSetsComboBox.removeAllItems();
114 List<HashDb> updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets();
115 if (!updateableHashSets.isEmpty()) {
116 for (HashDb hashDb : updateableHashSets) {
117 hashSetsComboBox.addItem(hashDb);
119 hashSetsComboBox.setEnabled(
true);
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))))
264 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deselectAllButton, selectAllButton});
266 layout.setVerticalGroup(
267 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addGroup(layout.createSequentialGroup()
270 .addComponent(jLabel1)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addGroup(layout.createSequentialGroup()
274 .addComponent(selectAllButton)
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
276 .addComponent(deselectAllButton))
277 .addComponent(jScrollPane1))
278 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
279 .addComponent(jLabel2)
281 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
282 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
283 .addComponent(configureHashDatabasesButton))
288 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
289 for (TagName tagName : tagNames) {
290 tagNameSelections.put(tagName.getDisplayName(), Boolean.TRUE);
292 tagNamesListBox.repaint();
295 private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
296 selectedHashSet = (HashDb)hashSetsComboBox.getSelectedItem();
299 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
300 for (TagName tagName : tagNames) {
301 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
303 tagNamesListBox.repaint();
306 private void configureHashDatabasesButtonActionPerformed(java.awt.event.ActionEvent evt) {
307 HashLookupSettingsPanel configPanel =
new HashLookupSettingsPanel();
309 if (JOptionPane.showConfirmDialog(
this, configPanel,
"Hash Set Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
311 populateHashSetComponents();
313 configPanel.cancel();
314 populateHashSetComponents();
319 private javax.swing.JButton configureHashDatabasesButton;
320 private javax.swing.JButton deselectAllButton;
321 private javax.swing.JComboBox<HashDb> hashSetsComboBox;
322 private javax.swing.JLabel jLabel1;
323 private javax.swing.JLabel jLabel2;
324 private javax.swing.JScrollPane jScrollPane1;
325 private javax.swing.JButton selectAllButton;
326 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)