Autopsy  4.16.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.ui;
20 
22 import com.google.common.eventbus.Subscribe;
23 import java.awt.Cursor;
24 import java.awt.Graphics2D;
25 import java.awt.font.FontRenderContext;
26 import java.util.List;
27 import java.util.Map;
28 import javax.swing.DefaultListCellRenderer;
29 import javax.swing.DefaultListModel;
30 import javax.swing.JList;
31 import javax.swing.JOptionPane;
32 import javax.swing.SwingUtilities;
33 import org.openide.util.NbBundle.Messages;
41 
45 final class GroupListPanel extends javax.swing.JPanel {
46 
47  private static final long serialVersionUID = 1L;
48  private Type type = null;
49  private Map<GroupKey, Integer> groupMap = null;
50  private List<AbstractFilter> searchfilters;
51  private DiscoveryAttributes.AttributeType groupingAttribute;
52  private Group.GroupSortingAlgorithm groupSort;
53  private ResultsSorter.SortingMethod resultSortMethod;
54  private GroupKey selectedGroupKey;
55 
59  GroupListPanel() {
60  initComponents();
61  }
62 
68  @Subscribe
69  void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
70  type = searchStartedEvent.getType();
71  groupKeyList.setListData(new GroupKey[0]);
72  }
73 
74  @Messages({"GroupsListPanel.noFileResults.message.text=No files were found for the selected filters.\n\n"
75  + "Reminder:\n"
76  + " -The File Type Identification module must be run on each data source you want to find results in.\n"
77  + " -The Hash Lookup module must be run on each data source if you want to filter by past occurrence.\n"
78  + " -The Picture Analyzer module must be run on each data source if you are filtering by User Created content.",
79  "GroupsListPanel.noDomainResults.message.text=No domains were found for the selected filters.\n\n"
80  + "Reminder:\n"
81  + " -The Recent Activity module must be run on each data source you want to find results in.\n"
82  + " -The Central Repository module must be run on each data source if you want to filter or sort by past occurrences.\n"
83  + " -The iOS Analyzer (iLEAPP) module must be run on each data source which contains data from an iOS device.\n",
84  "GroupsListPanel.noResults.title.text=No results found"})
91  @Subscribe
92  void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
93  groupMap = searchCompleteEvent.getGroupMap();
94  searchfilters = searchCompleteEvent.getFilters();
95  groupingAttribute = searchCompleteEvent.getGroupingAttr();
96  groupSort = searchCompleteEvent.getGroupSort();
97  resultSortMethod = searchCompleteEvent.getResultSort();
98  groupKeyList.setListData(groupMap.keySet().toArray(new GroupKey[groupMap.keySet().size()]));
99  SwingUtilities.invokeLater(() -> {
100  if (groupKeyList.getModel().getSize() > 0) {
101  groupKeyList.setSelectedIndex(0);
102  } else if (type == DOMAIN) {
103  JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
104  Bundle.GroupsListPanel_noDomainResults_message_text(),
105  Bundle.GroupsListPanel_noResults_title_text(),
106  JOptionPane.PLAIN_MESSAGE);
107  } else {
108  JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
109  Bundle.GroupsListPanel_noFileResults_message_text(),
110  Bundle.GroupsListPanel_noResults_title_text(),
111  JOptionPane.PLAIN_MESSAGE);
112  }
113  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
114  });
115  }
116 
122  @Subscribe
123  void handleSearchCancelledEvent(DiscoveryEventUtils.SearchCancelledEvent searchCancelledEvent) {
124  SwingUtilities.invokeLater(() -> {
125  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
126  });
127  }
128 
134  @SuppressWarnings("unchecked")
135  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
136  private void initComponents() {
137 
138  javax.swing.JScrollPane groupListScrollPane = new javax.swing.JScrollPane();
139  groupKeyList = new javax.swing.JList<>();
140 
141  groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GroupListPanel.class, "GroupListPanel.groupKeyList.border.title"))); // NOI18N
142  groupKeyList.setModel(new DefaultListModel<GroupKey>());
143  groupKeyList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
144  groupKeyList.setCellRenderer(new GroupListRenderer());
145  groupKeyList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
146  public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
147  groupSelected(evt);
148  }
149  });
150  groupListScrollPane.setViewportView(groupKeyList);
151 
152  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
153  this.setLayout(layout);
154  layout.setHorizontalGroup(
155  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156  .addGap(0, 144, Short.MAX_VALUE)
157  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
159  );
160  layout.setVerticalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addGap(0, 300, Short.MAX_VALUE)
163  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164  .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))
165  );
166  }// </editor-fold>//GEN-END:initComponents
167 
171  void resetGroupList() {
172  SwingUtilities.invokeLater(() -> {
173  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
174  });
175  groupKeyList.setListData(new GroupKey[0]);
176  }
177 
183  private void groupSelected(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_groupSelected
184  if (!evt.getValueIsAdjusting()) {
185  if (groupKeyList.getSelectedValue() != null) {
186  GroupKey selectedGroup = groupKeyList.getSelectedValue();
187  for (GroupKey groupKey : groupMap.keySet()) {
188  if (selectedGroup.equals(groupKey)) {
189  selectedGroupKey = groupKey;
190  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.GroupSelectedEvent(
191  searchfilters, groupingAttribute, groupSort, resultSortMethod, selectedGroupKey, groupMap.get(selectedGroupKey), type));
192  break;
193  }
194  }
195  } else {
196  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.NoResultsEvent());
197 
198  }
199  }
200  }//GEN-LAST:event_groupSelected
201 
202  // Variables declaration - do not modify//GEN-BEGIN:variables
203  private javax.swing.JList<GroupKey> groupKeyList;
204  // End of variables declaration//GEN-END:variables
205 
210  private class GroupListRenderer extends DefaultListCellRenderer {
211 
212  private static final long serialVersionUID = 1L;
213 
214  @Override
215  public java.awt.Component getListCellRendererComponent(
216  JList<?> list,
217  Object value,
218  int index,
219  boolean isSelected,
220  boolean cellHasFocus) {
221  Object newValue = value;
222  if (newValue instanceof GroupKey) {
223  String valueString = newValue.toString();
224  setToolTipText(valueString);
225  valueString += " (" + groupMap.get(newValue) + ")";
226 
227  if (groupingAttribute instanceof DiscoveryAttributes.ParentPathAttribute) {
228  // Using the list FontRenderContext instead of this because
229  // the label RenderContext was sometimes null, but this should work.
230  FontRenderContext context = ((Graphics2D) list.getGraphics()).getFontRenderContext();
231 
232  //Determine the width of the string with the given font.
233  double stringWidth = getFont().getStringBounds(valueString, context).getWidth();
234  // subtracting 10 from the width as a littl inset.
235  int listWidth = list.getWidth() - 10;
236 
237  if (stringWidth > listWidth) {
238  double avgCharWidth = Math.floor(stringWidth / valueString.length());
239 
240  // The extra 5 is to account for the " ... " that is being added back.
241  int charToRemove = (int) Math.ceil((stringWidth - listWidth) / avgCharWidth) + 5;
242  int charactersToShow = (int) Math.ceil((valueString.length() - charToRemove) / 2);
243  valueString = valueString.substring(0, charactersToShow) + " ... " + valueString.substring(valueString.length() - charactersToShow);
244  }
245  }
246  newValue = valueString;
247  }
248  super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
249  return this;
250  }
251  }
252 
253 }
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

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