Autopsy  4.16.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.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;
45 import org.sleuthkit.datamodel.AbstractFile;
46 import org.sleuthkit.datamodel.TskCoreException;
47 
51 final class DetailsPanel extends javax.swing.JPanel {
52 
53  private static final long serialVersionUID = 1L;
54 
55  private final DataContentPanel dataContentPanel;
56  private final DefaultListModel<AbstractFile> instancesListModel = new DefaultListModel<>();
57  private final ListSelectionListener listener;
58 
62  DetailsPanel() {
63  initComponents();
64  dataContentPanel = DataContentPanel.createInstance();
65  detailsSplitPane.setBottomComponent(dataContentPanel);
66  //Add the context menu when right clicking
67  instancesList.addMouseListener(new MouseAdapter() {
68  @Override
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);
84  });
85  }
86  }
87  });
88  listener = new ListSelectionListener() {
89  @Override
90  public void valueChanged(ListSelectionEvent e) {
91  if (!e.getValueIsAdjusting()) {
92  SwingUtilities.invokeLater(() -> {
93  AbstractFile file = getSelectedFile();
94  if (file != null) {
95  dataContentPanel.setNode(new TableFilterNode(new FileNode(file), false));
96  } else {
97  dataContentPanel.setNode(null);
98  }
99  });
100  }
101  }
102  };
103  instancesList.addListSelectionListener(listener);
104  }
105 
113  @Subscribe
114  void handleClearSelectionListener(DiscoveryEventUtils.ClearInstanceSelectionEvent clearEvent) {
115  instancesList.clearSelection();
116  }
117 
124  @Subscribe
125  synchronized void handlePopulateInstancesListEvent(DiscoveryEventUtils.PopulateInstancesListEvent populateEvent) {
126  SwingUtilities.invokeLater(() -> {
127  List<AbstractFile> files = populateEvent.getInstances();
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  synchronized AbstractFile getSelectedFile() {
158  if (instancesList.getSelectedIndex() == -1) {
159  return null;
160  } else {
161  return instancesListModel.getElementAt(instancesList.getSelectedIndex());
162  }
163  }
164 
170  @SuppressWarnings("unchecked")
171  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
172  private void initComponents() {
173 
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<>();
178 
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));
183 
184  instancesPanel.setMinimumSize(new java.awt.Dimension(0, 60));
185  instancesPanel.setPreferredSize(new java.awt.Dimension(700, 80));
186 
187  instancesScrollPane.setPreferredSize(new java.awt.Dimension(775, 60));
188 
189  instancesList.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DetailsPanel.class, "DetailsPanel.instancesList.border.title"))); // NOI18N
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);
195 
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))
203  );
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()
209  .addGap(0, 0, 0)
210  .addComponent(instancesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
211  );
212 
213  detailsSplitPane.setTopComponent(instancesPanel);
214 
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))
222  );
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))
228  );
229  }// </editor-fold>//GEN-END:initComponents
230 
231 
232  // Variables declaration - do not modify//GEN-BEGIN:variables
233  private javax.swing.JSplitPane detailsSplitPane;
234  private javax.swing.JList<AbstractFile> instancesList;
235  // End of variables declaration//GEN-END:variables
236 
240  private class InstancesCellRenderer extends DefaultListCellRenderer {
241 
242  private static final long serialVersionUID = 1L;
243 
244  @Override
245  public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
246  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
247  String name = "";
248  if (value instanceof AbstractFile) {
249  AbstractFile file = (AbstractFile) value;
250  try {
251  name = file.getUniquePath();
252  } catch (TskCoreException ingored) {
253  name = file.getParentPath() + "/" + file.getName();
254  }
255 
256  }
257  setText(name);
258  return this;
259  }
260 
261  }
262 }
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

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