Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileDetailsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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 
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;
27 import java.util.Set;
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;
46 import org.sleuthkit.datamodel.AbstractFile;
47 import org.sleuthkit.datamodel.TskCoreException;
48 
52 final class FileDetailsPanel extends javax.swing.JPanel {
53 
54  private static final long serialVersionUID = 1L;
55 
56  private final DataContentPanel dataContentPanel;
57  private final DefaultListModel<AbstractFile> instancesListModel = new DefaultListModel<>();
58  private final ListSelectionListener listener;
59 
63  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
64  FileDetailsPanel() {
65  initComponents();
66  dataContentPanel = DataContentPanel.createInstance();
67  detailsSplitPane.setBottomComponent(dataContentPanel);
68  //Add the context menu when right clicking
69  instancesList.addMouseListener(new MouseAdapter() {
70  @Override
71  public void mousePressed(MouseEvent e) {
72  if (SwingUtilities.isRightMouseButton(e)) {
73  instancesList.setSelectedIndex(instancesList.locationToIndex(e.getPoint()));
74  Set<AbstractFile> files = new HashSet<>();
75  files.add(instancesList.getSelectedValue());
76  JPopupMenu menu = new JPopupMenu();
77  menu.add(new ViewContextAction(Bundle.ResultsPanel_viewFileInDir_name(), instancesList.getSelectedValue()));
78  menu.add(new ExternalViewerAction(Bundle.ResultsPanel_openInExternalViewer_name(), new FileNode(instancesList.getSelectedValue())));
79  menu.add(ViewFileInTimelineAction.createViewFileAction(instancesList.getSelectedValue()));
80  menu.add(new DiscoveryExtractAction(files));
81  menu.add(AddContentTagAction.getInstance().getMenuForContent(files));
82  menu.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(files));
83  menu.add(AddContentToHashDbAction.getInstance().getMenuForFiles(files));
84  menu.show(instancesList, e.getPoint().x, e.getPoint().y);
85  }
86  }
87  });
88  listener = new ListSelectionListener() {
89  @Override
90  public void valueChanged(ListSelectionEvent e) {
91  if (!e.getValueIsAdjusting()) {
92  AbstractFile file = getSelectedFile();
93  if (file != null) {
94  dataContentPanel.setNode(new TableFilterNode(new FileNode(file), false));
95  } else {
96  dataContentPanel.setNode(null);
97  }
98  }
99  }
100  };
101  instancesList.addListSelectionListener(listener);
102  }
103 
111  @Subscribe
112  void handleClearSelectionListener(DiscoveryEventUtils.ClearInstanceSelectionEvent clearEvent) {
113  SwingUtilities.invokeLater(() -> {
114  instancesList.clearSelection();
115  });
116  }
117 
124  @Subscribe
125  void handlePopulateInstancesListEvent(DiscoveryEventUtils.PopulateInstancesListEvent populateEvent) {
126  List<AbstractFile> files = populateEvent.getInstances();
127  SwingUtilities.invokeLater(() -> {
128  if (files.isEmpty()) {
129  //if there are no files currently remove the current items without removing listener to cause content viewer to reset
130  instancesListModel.removeAllElements();
131  //send fade out event
132  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(false));
133  } else {
134  //remove listener so content viewer node is not set multiple times
135  instancesList.removeListSelectionListener(listener);
136  instancesListModel.removeAllElements();
137  for (AbstractFile file : files) {
138  instancesListModel.addElement(file);
139  }
140  //add listener back to allow selection of first index to cause content viewer node to be set
141  instancesList.addListSelectionListener(listener);
142  if (!instancesListModel.isEmpty()) {
143  instancesList.setSelectedIndex(0);
144  }
145  //send fade in event
146  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(true));
147  }
148  });
149  }
150 
157  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
158  AbstractFile getSelectedFile() {
159  if (instancesList.getSelectedIndex() == -1) {
160  return null;
161  } else {
162  return instancesListModel.getElementAt(instancesList.getSelectedIndex());
163  }
164  }
165 
171  @SuppressWarnings("unchecked")
172  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
173  private void initComponents() {
174 
175  detailsSplitPane = new javax.swing.JSplitPane();
176  javax.swing.JPanel instancesPanel = new javax.swing.JPanel();
177  javax.swing.JScrollPane instancesScrollPane = new javax.swing.JScrollPane();
178  instancesList = new javax.swing.JList<>();
179 
180  detailsSplitPane.setDividerLocation(80);
181  detailsSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
182  detailsSplitPane.setMinimumSize(new java.awt.Dimension(200, 0));
183  detailsSplitPane.setPreferredSize(new java.awt.Dimension(700, 500));
184 
185  instancesPanel.setMinimumSize(new java.awt.Dimension(0, 60));
186  instancesPanel.setPreferredSize(new java.awt.Dimension(700, 80));
187 
188  instancesScrollPane.setPreferredSize(new java.awt.Dimension(775, 60));
189 
190  instancesList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(FileDetailsPanel.class, "FileDetailsPanel.instancesList.border.title"))); // NOI18N
191  instancesList.setModel(instancesListModel);
192  instancesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
193  instancesList.setCellRenderer(new InstancesCellRenderer());
194  instancesList.setVisibleRowCount(2);
195  instancesScrollPane.setViewportView(instancesList);
196 
197  javax.swing.GroupLayout instancesPanelLayout = new javax.swing.GroupLayout(instancesPanel);
198  instancesPanel.setLayout(instancesPanelLayout);
199  instancesPanelLayout.setHorizontalGroup(
200  instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201  .addGap(0, 775, Short.MAX_VALUE)
202  .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203  .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
204  );
205  instancesPanelLayout.setVerticalGroup(
206  instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207  .addGap(0, 79, Short.MAX_VALUE)
208  .addGroup(instancesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, instancesPanelLayout.createSequentialGroup()
210  .addGap(0, 0, 0)
211  .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
212  );
213 
214  detailsSplitPane.setTopComponent(instancesPanel);
215 
216  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
217  this.setLayout(layout);
218  layout.setHorizontalGroup(
219  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addGap(0, 777, Short.MAX_VALUE)
221  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
222  .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
223  );
224  layout.setVerticalGroup(
225  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addGap(0, 402, Short.MAX_VALUE)
227  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addComponent(detailsSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
229  );
230  }// </editor-fold>//GEN-END:initComponents
231 
232 
233  // Variables declaration - do not modify//GEN-BEGIN:variables
234  private javax.swing.JSplitPane detailsSplitPane;
235  private javax.swing.JList<AbstractFile> instancesList;
236  // End of variables declaration//GEN-END:variables
237 
241  private class InstancesCellRenderer extends DefaultListCellRenderer {
242 
243  private static final long serialVersionUID = 1L;
244 
246  @Override
247  public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
248  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
249  String name = "";
250  if (value instanceof AbstractFile) {
251  AbstractFile file = (AbstractFile) value;
252  try {
253  name = file.getUniquePath();
254  } catch (TskCoreException ingored) {
255  name = file.getParentPath() + "/" + file.getName();
256  }
257 
258  }
259  setText(name);
260  return this;
261  }
262 
263  }
264 }
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

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