Autopsy  4.15.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.discovery;
20 
21 import com.google.common.eventbus.Subscribe;
22 import java.awt.Cursor;
23 import java.util.List;
24 import java.util.Map;
25 import javax.swing.DefaultListCellRenderer;
26 import javax.swing.DefaultListModel;
27 import javax.swing.JList;
28 import javax.swing.JOptionPane;
29 import javax.swing.SwingUtilities;
30 import org.openide.util.NbBundle.Messages;
33 
37 final class GroupListPanel extends javax.swing.JPanel {
38 
39  private static final long serialVersionUID = 1L;
40  private FileType resultType = null;
41  private Map<GroupKey, Integer> groupMap = null;
42  private List<FileSearchFiltering.FileFilter> searchfilters;
43  private FileSearch.AttributeType groupingAttribute;
44  private FileGroup.GroupSortingAlgorithm groupSort;
45  private FileSorter.SortingMethod fileSortMethod;
46  private GroupKey selectedGroupKey;
47 
51  GroupListPanel() {
52  initComponents();
53  }
54 
60  @Subscribe
61  void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
62  resultType = searchStartedEvent.getType();
63  groupKeyList.setListData(new GroupKey[0]);
64  }
65 
66  @Messages({"GroupsListPanel.noResults.message.text=No results were found for the selected filters.",
67  "GroupsListPanel.noResults.title.text=No results found"})
74  @Subscribe
75  void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
76  groupMap = searchCompleteEvent.getGroupMap();
77  searchfilters = searchCompleteEvent.getFilters();
78  groupingAttribute = searchCompleteEvent.getGroupingAttr();
79  groupSort = searchCompleteEvent.getGroupSort();
80  fileSortMethod = searchCompleteEvent.getFileSort();
81  groupKeyList.setListData(groupMap.keySet().toArray(new GroupKey[groupMap.keySet().size()]));
82  SwingUtilities.invokeLater(() -> {
83  if (groupKeyList.getModel().getSize() > 0) {
84  groupKeyList.setSelectedIndex(0);
85  } else {
86  JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
87  Bundle.GroupsListPanel_noResults_message_text(),
88  Bundle.GroupsListPanel_noResults_title_text(),
89  JOptionPane.INFORMATION_MESSAGE);
90  }
91  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
92  });
93  }
94 
100  @Subscribe
101  void handleSearchCancelledEvent(DiscoveryEventUtils.SearchCancelledEvent searchCancelledEvent) {
102  SwingUtilities.invokeLater(() -> {
103  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
104  });
105  }
106 
112  @SuppressWarnings("unchecked")
113  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
114  private void initComponents() {
115 
116  javax.swing.JScrollPane groupListScrollPane = new javax.swing.JScrollPane();
117  groupKeyList = new javax.swing.JList<>();
118 
119  groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GroupListPanel.class, "GroupListPanel.groupKeyList.border.title"))); // NOI18N
120  groupKeyList.setModel(new DefaultListModel<GroupKey>());
121  groupKeyList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
122  groupKeyList.setCellRenderer(new GroupListRenderer());
123  groupKeyList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
124  public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
125  groupSelected(evt);
126  }
127  });
128  groupListScrollPane.setViewportView(groupKeyList);
129 
130  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
131  this.setLayout(layout);
132  layout.setHorizontalGroup(
133  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134  .addGap(0, 144, Short.MAX_VALUE)
135  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
137  );
138  layout.setVerticalGroup(
139  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140  .addGap(0, 300, Short.MAX_VALUE)
141  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))
143  );
144  }// </editor-fold>//GEN-END:initComponents
145 
149  void resetGroupList() {
150  SwingUtilities.invokeLater(() -> {
151  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
152  });
153  groupKeyList.setListData(new GroupKey[0]);
154  }
155 
161  private void groupSelected(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_groupSelected
162  if (!evt.getValueIsAdjusting()) {
163  if (groupKeyList.getSelectedValue() != null) {
164  GroupKey selectedGroup = groupKeyList.getSelectedValue();
165  for (GroupKey groupKey : groupMap.keySet()) {
166  if (selectedGroup.equals(groupKey)) {
167  selectedGroupKey = groupKey;
168  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.GroupSelectedEvent(
169  searchfilters, groupingAttribute, groupSort, fileSortMethod, selectedGroupKey, groupMap.get(selectedGroupKey), resultType));
170  break;
171  }
172  }
173  } else {
174  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.NoResultsEvent());
175 
176  }
177  }
178  }//GEN-LAST:event_groupSelected
179 
180  // Variables declaration - do not modify//GEN-BEGIN:variables
181  private javax.swing.JList<GroupKey> groupKeyList;
182  // End of variables declaration//GEN-END:variables
183 
188  private class GroupListRenderer extends DefaultListCellRenderer {
189 
190  private static final long serialVersionUID = 1L;
191 
192  @Override
193  public java.awt.Component getListCellRendererComponent(
194  JList<?> list,
195  Object value,
196  int index,
197  boolean isSelected,
198  boolean cellHasFocus) {
199  Object newValue = value;
200  if (newValue instanceof GroupKey) {
201  String valueString = newValue.toString();
202  setToolTipText(valueString);
203  //if paths would be longer than 37 characters shorten them to be 37 characters
204  if (groupingAttribute instanceof FileSearch.ParentPathAttribute && valueString.length() > 37) {
205  valueString = valueString.substring(0, 16) + " ... " + valueString.substring(valueString.length() - 16);
206  }
207  newValue = valueString + " (" + groupMap.get(newValue) + ")";
208  }
209  super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
210  return this;
211  }
212  }
213 
214 }
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

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