19 package org.sleuthkit.autopsy.discovery.ui;
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;
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;
45 final class GroupListPanel
extends javax.swing.JPanel {
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;
69 void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
70 type = searchStartedEvent.getType();
71 groupKeyList.setListData(
new GroupKey[0]);
74 @Messages({
"GroupsListPanel.noFileResults.message.text=No files were found for the selected filters.\n\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"
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"})
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);
108 JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
109 Bundle.GroupsListPanel_noFileResults_message_text(),
110 Bundle.GroupsListPanel_noResults_title_text(),
111 JOptionPane.PLAIN_MESSAGE);
113 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
123 void handleSearchCancelledEvent(DiscoveryEventUtils.SearchCancelledEvent searchCancelledEvent) {
124 SwingUtilities.invokeLater(() -> {
125 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
134 @SuppressWarnings(
"unchecked")
136 private
void initComponents() {
138 javax.swing.JScrollPane groupListScrollPane =
new javax.swing.JScrollPane();
139 groupKeyList =
new javax.swing.JList<>();
141 groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(GroupListPanel.class,
"GroupListPanel.groupKeyList.border.title")));
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) {
150 groupListScrollPane.setViewportView(groupKeyList);
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))
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))
171 void resetGroupList() {
172 SwingUtilities.invokeLater(() -> {
173 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
175 groupKeyList.setListData(
new GroupKey[0]);
183 private void groupSelected(javax.swing.event.ListSelectionEvent evt) {
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));
196 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.NoResultsEvent());
203 private javax.swing.JList<GroupKey> groupKeyList;
212 private static final long serialVersionUID = 1L;
220 boolean cellHasFocus) {
221 Object newValue = value;
223 String valueString = newValue.toString();
224 setToolTipText(valueString);
225 valueString +=
" (" + groupMap.get(newValue) +
")";
230 FontRenderContext context = ((Graphics2D) list.getGraphics()).getFontRenderContext();
233 double stringWidth = getFont().getStringBounds(valueString, context).getWidth();
235 int listWidth = list.getWidth() - 10;
237 if (stringWidth > listWidth) {
238 double avgCharWidth = Math.floor(stringWidth / valueString.length());
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);
246 newValue = valueString;
248 super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)