Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GroupListPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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.filequery;
20 
21 import com.google.common.eventbus.Subscribe;
22 import java.util.List;
23 import java.util.Map;
24 import javax.swing.DefaultListCellRenderer;
25 import javax.swing.DefaultListModel;
26 import javax.swing.JList;
27 import javax.swing.JOptionPane;
28 import org.openide.util.NbBundle.Messages;
31 
35 class GroupListPanel extends javax.swing.JPanel {
36 
37  private static final long serialVersionUID = 1L;
38  private FileType resultType = null;
39  private Map<GroupKey, Integer> groupMap = null;
40  private List<FileSearchFiltering.FileFilter> searchfilters;
41  private FileSearch.AttributeType groupingAttribute;
42  private FileGroup.GroupSortingAlgorithm groupSort;
43  private FileSorter.SortingMethod fileSortMethod;
44  private GroupKey selectedGroupKey;
45 
49  GroupListPanel() {
50  initComponents();
51  }
52 
58  @Subscribe
59  void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
60  resultType = searchStartedEvent.getType();
61  groupKeyList.setListData(new GroupKey[0]);
62  }
63 
64  @Messages({"GroupsListPanel.noResults.message.text=No results were found for the selected filters.",
65  "GroupsListPanel.noResults.title.text=No results found"})
72  @Subscribe
73  void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
74  groupMap = searchCompleteEvent.getGroupMap();
75  searchfilters = searchCompleteEvent.getFilters();
76  groupingAttribute = searchCompleteEvent.getGroupingAttr();
77  groupSort = searchCompleteEvent.getGroupSort();
78  fileSortMethod = searchCompleteEvent.getFileSort();
79  groupKeyList.setListData(groupMap.keySet().toArray(new GroupKey[groupMap.keySet().size()]));
80  if (groupKeyList.getModel().getSize() > 0) {
81  groupKeyList.setSelectedIndex(0);
82  } else {
83  JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
84  Bundle.GroupsListPanel_noResults_message_text(),
85  Bundle.GroupsListPanel_noResults_title_text(),
86  JOptionPane.INFORMATION_MESSAGE);
87  }
88  }
89 
95  @SuppressWarnings("unchecked")
96  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
97  private void initComponents() {
98 
99  javax.swing.JScrollPane groupListScrollPane = new javax.swing.JScrollPane();
100  groupKeyList = new javax.swing.JList<>();
101 
102  groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GroupListPanel.class, "GroupListPanel.groupKeyList.border.title"))); // NOI18N
103  groupKeyList.setModel(new DefaultListModel<GroupKey>());
104  groupKeyList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
105  groupKeyList.setCellRenderer(new GroupListRenderer());
106  groupKeyList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
107  public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
108  groupSelected(evt);
109  }
110  });
111  groupListScrollPane.setViewportView(groupKeyList);
112 
113  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
114  this.setLayout(layout);
115  layout.setHorizontalGroup(
116  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117  .addGap(0, 144, Short.MAX_VALUE)
118  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
120  );
121  layout.setVerticalGroup(
122  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123  .addGap(0, 300, Short.MAX_VALUE)
124  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))
126  );
127  }// </editor-fold>//GEN-END:initComponents
128 
132  void resetGroupList() {
133  groupKeyList.setListData(new GroupKey[0]);
134  }
135 
141  private void groupSelected(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_groupSelected
142  if (!evt.getValueIsAdjusting()) {
143  if (groupKeyList.getSelectedValue() != null) {
144  GroupKey selectedGroup = groupKeyList.getSelectedValue();
145  for (GroupKey groupKey : groupMap.keySet()) {
146  if (selectedGroup.equals(groupKey)) {
147  selectedGroupKey = groupKey;
148  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.GroupSelectedEvent(
149  searchfilters, groupingAttribute, groupSort, fileSortMethod, selectedGroupKey, groupMap.get(selectedGroupKey), resultType));
150  break;
151  }
152  }
153  } else {
154  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.NoResultsEvent());
155  }
156  }
157  }//GEN-LAST:event_groupSelected
158 
159  // Variables declaration - do not modify//GEN-BEGIN:variables
160  private javax.swing.JList<GroupKey> groupKeyList;
161  // End of variables declaration//GEN-END:variables
162 
167  private class GroupListRenderer extends DefaultListCellRenderer {
168 
169  private static final long serialVersionUID = 1L;
170 
171  @Override
172  public java.awt.Component getListCellRendererComponent(
173  JList<?> list,
174  Object value,
175  int index,
176  boolean isSelected,
177  boolean cellHasFocus) {
178  Object newValue = value;
179  if (newValue instanceof GroupKey) {
180  String valueString = newValue.toString();
181  setToolTipText(valueString);
182  //if paths would be longer than 37 characters shorten them to be 37 characters
183  if (groupingAttribute instanceof FileSearch.ParentPathAttribute && valueString.length() > 37) {
184  valueString = valueString.substring(0, 16) + " ... " + valueString.substring(valueString.length() - 16);
185  }
186  newValue = valueString + " (" + groupMap.get(newValue) + ")";
187  }
188  super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
189  return this;
190  }
191  }
192 
193 }
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.