19 package org.sleuthkit.autopsy.discovery;
21 import com.google.common.eventbus.Subscribe;
22 import java.awt.Component;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.util.HashSet;
26 import java.util.List;
28 import javax.swing.DefaultListCellRenderer;
29 import javax.swing.DefaultListModel;
30 import javax.swing.JList;
31 import javax.swing.JPopupMenu;
32 import javax.swing.SwingUtilities;
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
50 final class DetailsPanel
extends javax.swing.JPanel {
52 private static final long serialVersionUID = 1L;
54 private final DataContentPanel dataContentPanel;
55 private final DefaultListModel<AbstractFile> instancesListModel =
new DefaultListModel<>();
56 private final ListSelectionListener listener;
63 dataContentPanel = DataContentPanel.createInstance();
64 detailsSplitPane.setBottomComponent(dataContentPanel);
66 instancesList.addMouseListener(
new MouseAdapter() {
68 public void mousePressed(MouseEvent e) {
69 if (SwingUtilities.isRightMouseButton(e)) {
70 SwingUtilities.invokeLater(() -> {
71 instancesList.setSelectedIndex(instancesList.locationToIndex(e.getPoint()));
72 Set<AbstractFile> files =
new HashSet<>();
73 files.add(instancesList.getSelectedValue());
74 JPopupMenu menu =
new JPopupMenu();
75 menu.add(
new ViewContextAction(Bundle.ResultsPanel_viewFileInDir_name(), instancesList.getSelectedValue()));
76 menu.add(
new ExternalViewerAction(Bundle.ResultsPanel_openInExternalViewer_name(),
new FileNode(instancesList.getSelectedValue())));
77 menu.add(ViewFileInTimelineAction.createViewFileAction(instancesList.getSelectedValue()));
78 menu.add(
new DiscoveryExtractAction(files));
79 menu.add(AddContentTagAction.getInstance().getMenuForContent(files));
80 menu.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(files));
81 menu.add(AddContentToHashDbAction.getInstance().getMenuForFiles(files));
82 menu.show(instancesList, e.getPoint().x, e.getPoint().y);
87 listener =
new ListSelectionListener() {
89 public void valueChanged(ListSelectionEvent e) {
90 if (!e.getValueIsAdjusting()) {
91 SwingUtilities.invokeLater(() -> {
92 AbstractFile file = getSelectedFile();
94 dataContentPanel.setNode(
new TableFilterNode(
new FileNode(file),
false));
96 dataContentPanel.setNode(null);
102 instancesList.addListSelectionListener(listener);
113 void handleClearSelectionListener(DiscoveryEventUtils.ClearInstanceSelectionEvent clearEvent) {
114 instancesList.clearSelection();
124 synchronized void handlePopulateInstancesListEvent(DiscoveryEventUtils.PopulateInstancesListEvent populateEvent) {
125 SwingUtilities.invokeLater(() -> {
126 List<AbstractFile> files = populateEvent.getInstances();
127 if (files.isEmpty()) {
129 instancesListModel.removeAllElements();
131 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
false));
134 instancesList.removeListSelectionListener(listener);
135 instancesListModel.removeAllElements();
136 for (AbstractFile file : files) {
137 instancesListModel.addElement(file);
140 instancesList.addListSelectionListener(listener);
141 if (!instancesListModel.isEmpty()) {
142 instancesList.setSelectedIndex(0);
145 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
true));
156 synchronized AbstractFile getSelectedFile() {
157 if (instancesList.getSelectedIndex() == -1) {
160 return instancesListModel.getElementAt(instancesList.getSelectedIndex());
169 @SuppressWarnings(
"unchecked")
171 private
void initComponents() {
173 detailsSplitPane =
new javax.swing.JSplitPane();
174 javax.swing.JPanel instancesPanel =
new javax.swing.JPanel();
175 javax.swing.JScrollPane instancesScrollPane =
new javax.swing.JScrollPane();
176 instancesList =
new javax.swing.JList<>();
178 detailsSplitPane.setDividerLocation(80);
179 detailsSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
180 detailsSplitPane.setMinimumSize(
new java.awt.Dimension(200, 0));
181 detailsSplitPane.setPreferredSize(
new java.awt.Dimension(700, 500));
183 instancesPanel.setMinimumSize(
new java.awt.Dimension(0, 60));
184 instancesPanel.setPreferredSize(
new java.awt.Dimension(700, 80));
186 instancesScrollPane.setPreferredSize(
new java.awt.Dimension(775, 60));
188 instancesList.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(DetailsPanel.class,
"DetailsPanel.instancesList.border.title")));
189 instancesList.setModel(instancesListModel);
190 instancesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
191 instancesList.setCellRenderer(
new InstancesCellRenderer());
192 instancesList.setVisibleRowCount(2);
193 instancesScrollPane.setViewportView(instancesList);
195 javax.swing.GroupLayout instancesPanelLayout =
new javax.swing.GroupLayout(instancesPanel);
196 instancesPanel.setLayout(instancesPanelLayout);
197 instancesPanelLayout.setHorizontalGroup(
198 instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addGap(0, 775, Short.MAX_VALUE)
200 .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201 .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
203 instancesPanelLayout.setVerticalGroup(
204 instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205 .addGap(0, 79, Short.MAX_VALUE)
206 .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, instancesPanelLayout.createSequentialGroup()
209 .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
212 detailsSplitPane.setTopComponent(instancesPanel);
214 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
215 this.setLayout(layout);
216 layout.setHorizontalGroup(
217 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 .addGap(0, 777, Short.MAX_VALUE)
219 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220 .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
222 layout.setVerticalGroup(
223 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224 .addGap(0, 402, Short.MAX_VALUE)
225 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
232 private javax.swing.JSplitPane detailsSplitPane;
233 private javax.swing.JList<AbstractFile> instancesList;
241 private static final long serialVersionUID = 1L;
245 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
247 if (value instanceof AbstractFile) {
248 AbstractFile file = (AbstractFile) value;
250 name = file.getUniquePath();
251 }
catch (TskCoreException ingored) {
252 name = file.getParentPath() +
"/" + file.getName();
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)