19 package org.sleuthkit.autopsy.discovery.ui;
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;
51 final class DetailsPanel
extends javax.swing.JPanel {
53 private static final long serialVersionUID = 1L;
55 private final DataContentPanel dataContentPanel;
56 private final DefaultListModel<AbstractFile> instancesListModel =
new DefaultListModel<>();
57 private final ListSelectionListener listener;
64 dataContentPanel = DataContentPanel.createInstance();
65 detailsSplitPane.setBottomComponent(dataContentPanel);
67 instancesList.addMouseListener(
new MouseAdapter() {
69 public void mousePressed(MouseEvent e) {
70 if (SwingUtilities.isRightMouseButton(e)) {
71 SwingUtilities.invokeLater(() -> {
72 instancesList.setSelectedIndex(instancesList.locationToIndex(e.getPoint()));
73 Set<AbstractFile> files =
new HashSet<>();
74 files.add(instancesList.getSelectedValue());
75 JPopupMenu menu =
new JPopupMenu();
76 menu.add(
new ViewContextAction(Bundle.ResultsPanel_viewFileInDir_name(), instancesList.getSelectedValue()));
77 menu.add(
new ExternalViewerAction(Bundle.ResultsPanel_openInExternalViewer_name(),
new FileNode(instancesList.getSelectedValue())));
78 menu.add(ViewFileInTimelineAction.createViewFileAction(instancesList.getSelectedValue()));
79 menu.add(
new DiscoveryExtractAction(files));
80 menu.add(AddContentTagAction.getInstance().getMenuForContent(files));
81 menu.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(files));
82 menu.add(AddContentToHashDbAction.getInstance().getMenuForFiles(files));
83 menu.show(instancesList, e.getPoint().x, e.getPoint().y);
88 listener =
new ListSelectionListener() {
90 public void valueChanged(ListSelectionEvent e) {
91 if (!e.getValueIsAdjusting()) {
92 SwingUtilities.invokeLater(() -> {
93 AbstractFile file = getSelectedFile();
95 dataContentPanel.setNode(
new TableFilterNode(
new FileNode(file),
false));
97 dataContentPanel.setNode(null);
103 instancesList.addListSelectionListener(listener);
114 void handleClearSelectionListener(DiscoveryEventUtils.ClearInstanceSelectionEvent clearEvent) {
115 instancesList.clearSelection();
125 synchronized void handlePopulateInstancesListEvent(DiscoveryEventUtils.PopulateInstancesListEvent populateEvent) {
126 SwingUtilities.invokeLater(() -> {
127 List<AbstractFile> files = populateEvent.getInstances();
128 if (files.isEmpty()) {
130 instancesListModel.removeAllElements();
132 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
false));
135 instancesList.removeListSelectionListener(listener);
136 instancesListModel.removeAllElements();
137 for (AbstractFile file : files) {
138 instancesListModel.addElement(file);
141 instancesList.addListSelectionListener(listener);
142 if (!instancesListModel.isEmpty()) {
143 instancesList.setSelectedIndex(0);
146 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
true));
157 synchronized AbstractFile getSelectedFile() {
158 if (instancesList.getSelectedIndex() == -1) {
161 return instancesListModel.getElementAt(instancesList.getSelectedIndex());
170 @SuppressWarnings(
"unchecked")
172 private
void initComponents() {
174 detailsSplitPane =
new javax.swing.JSplitPane();
175 javax.swing.JPanel instancesPanel =
new javax.swing.JPanel();
176 javax.swing.JScrollPane instancesScrollPane =
new javax.swing.JScrollPane();
177 instancesList =
new javax.swing.JList<>();
179 detailsSplitPane.setDividerLocation(80);
180 detailsSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
181 detailsSplitPane.setMinimumSize(
new java.awt.Dimension(200, 0));
182 detailsSplitPane.setPreferredSize(
new java.awt.Dimension(700, 500));
184 instancesPanel.setMinimumSize(
new java.awt.Dimension(0, 60));
185 instancesPanel.setPreferredSize(
new java.awt.Dimension(700, 80));
187 instancesScrollPane.setPreferredSize(
new java.awt.Dimension(775, 60));
189 instancesList.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(DetailsPanel.class,
"DetailsPanel.instancesList.border.title")));
190 instancesList.setModel(instancesListModel);
191 instancesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
192 instancesList.setCellRenderer(
new InstancesCellRenderer());
193 instancesList.setVisibleRowCount(2);
194 instancesScrollPane.setViewportView(instancesList);
196 javax.swing.GroupLayout instancesPanelLayout =
new javax.swing.GroupLayout(instancesPanel);
197 instancesPanel.setLayout(instancesPanelLayout);
198 instancesPanelLayout.setHorizontalGroup(
199 instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addGap(0, 775, Short.MAX_VALUE)
201 .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202 .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
204 instancesPanelLayout.setVerticalGroup(
205 instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206 .addGap(0, 79, Short.MAX_VALUE)
207 .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, instancesPanelLayout.createSequentialGroup()
210 .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
213 detailsSplitPane.setTopComponent(instancesPanel);
215 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
216 this.setLayout(layout);
217 layout.setHorizontalGroup(
218 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219 .addGap(0, 777, Short.MAX_VALUE)
220 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221 .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
223 layout.setVerticalGroup(
224 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
225 .addGap(0, 402, Short.MAX_VALUE)
226 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
227 .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
233 private javax.swing.JSplitPane detailsSplitPane;
234 private javax.swing.JList<AbstractFile> instancesList;
242 private static final long serialVersionUID = 1L;
246 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
248 if (value instanceof AbstractFile) {
249 AbstractFile file = (AbstractFile) value;
251 name = file.getUniquePath();
252 }
catch (TskCoreException ingored) {
253 name = file.getParentPath() +
"/" + file.getName();
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)