Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DetailsPanel.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;
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;
44 import org.sleuthkit.datamodel.AbstractFile;
45 import org.sleuthkit.datamodel.TskCoreException;
46 
50 final class DetailsPanel extends javax.swing.JPanel {
51 
52  private static final long serialVersionUID = 1L;
53 
54  private final DataContentPanel dataContentPanel;
55  private final DefaultListModel<AbstractFile> instancesListModel = new DefaultListModel<>();
56  private final ListSelectionListener listener;
57 
61  DetailsPanel() {
62  initComponents();
63  dataContentPanel = DataContentPanel.createInstance();
64  detailsSplitPane.setBottomComponent(dataContentPanel);
65  //Add the context menu when right clicking
66  instancesList.addMouseListener(new MouseAdapter() {
67  @Override
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);
83  });
84  }
85  }
86  });
87  listener = new ListSelectionListener() {
88  @Override
89  public void valueChanged(ListSelectionEvent e) {
90  if (!e.getValueIsAdjusting()) {
91  SwingUtilities.invokeLater(() -> {
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  };
102  instancesList.addListSelectionListener(listener);
103  }
104 
112  @Subscribe
113  void handleClearSelectionListener(DiscoveryEventUtils.ClearInstanceSelectionEvent clearEvent) {
114  instancesList.clearSelection();
115  }
116 
123  @Subscribe
124  synchronized void handlePopulateInstancesListEvent(DiscoveryEventUtils.PopulateInstancesListEvent populateEvent) {
125  SwingUtilities.invokeLater(() -> {
126  List<AbstractFile> files = populateEvent.getInstances();
127  if (files.isEmpty()) {
128  //if there are no files currently remove the current items without removing listener to cause content viewer to reset
129  instancesListModel.removeAllElements();
130  //send fade out event
131  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(false));
132  } else {
133  //remove listener so content viewer node is not set multiple times
134  instancesList.removeListSelectionListener(listener);
135  instancesListModel.removeAllElements();
136  for (AbstractFile file : files) {
137  instancesListModel.addElement(file);
138  }
139  //add listener back to allow selection of first index to cause content viewer node to be set
140  instancesList.addListSelectionListener(listener);
141  if (!instancesListModel.isEmpty()) {
142  instancesList.setSelectedIndex(0);
143  }
144  //send fade in event
145  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(true));
146  }
147  });
148  }
149 
156  synchronized AbstractFile getSelectedFile() {
157  if (instancesList.getSelectedIndex() == -1) {
158  return null;
159  } else {
160  return instancesListModel.getElementAt(instancesList.getSelectedIndex());
161  }
162  }
163 
169  @SuppressWarnings("unchecked")
170  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
171  private void initComponents() {
172 
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<>();
177 
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));
182 
183  instancesPanel.setMinimumSize(new java.awt.Dimension(0, 60));
184  instancesPanel.setPreferredSize(new java.awt.Dimension(700, 80));
185 
186  instancesScrollPane.setPreferredSize(new java.awt.Dimension(775, 60));
187 
188  instancesList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DetailsPanel.class, "DetailsPanel.instancesList.border.title"))); // NOI18N
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);
194 
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))
202  );
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()
208  .addGap(0, 0, 0)
209  .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
210  );
211 
212  detailsSplitPane.setTopComponent(instancesPanel);
213 
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))
221  );
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))
227  );
228  }// </editor-fold>//GEN-END:initComponents
229 
230 
231  // Variables declaration - do not modify//GEN-BEGIN:variables
232  private javax.swing.JSplitPane detailsSplitPane;
233  private javax.swing.JList<AbstractFile> instancesList;
234  // End of variables declaration//GEN-END:variables
235 
239  private class InstancesCellRenderer extends DefaultListCellRenderer {
240 
241  private static final long serialVersionUID = 1L;
242 
243  @Override
244  public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
245  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
246  String name = "";
247  if (value instanceof AbstractFile) {
248  AbstractFile file = (AbstractFile) value;
249  try {
250  name = file.getUniquePath();
251  } catch (TskCoreException ingored) {
252  name = file.getParentPath() + "/" + file.getName();
253  }
254 
255  }
256  setText(name);
257  return this;
258  }
259 
260  }
261 }
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

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