Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MiniTimelineArtifactListPanel.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 java.awt.Dimension;
22 import java.awt.Point;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JPopupMenu;
27 import javax.swing.event.ListSelectionListener;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableCellRenderer;
30 import org.apache.commons.lang.StringUtils;
31 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.BlackboardArtifact;
36 import org.sleuthkit.datamodel.BlackboardAttribute;
37 import org.sleuthkit.datamodel.BlackboardAttribute.Type;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 final class MiniTimelineArtifactListPanel extends AbstractArtifactListPanel {
44 
45  private static final long serialVersionUID = 1L;
46  private final TypeDescriptionTableModel tableModel;
47  private static final Logger logger = Logger.getLogger(MiniTimelineArtifactListPanel.class.getName());
48 
49  private static final BlackboardAttribute.ATTRIBUTE_TYPE[] DESCRIPTION_TYPES = {BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE,
50  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
51  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL};
52 
56  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
57  MiniTimelineArtifactListPanel() {
58  tableModel = new TypeDescriptionTableModel();
59  initComponents();
60  // add the cell renderer to all columns
61  TableCellRenderer renderer = new SimpleTableCellRenderer();
62  for (int i = 0; i < tableModel.getColumnCount(); ++i) {
63  artifactsTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
64  }
65  setMinimumSize(new Dimension(125, 20));
66  artifactsTable.getRowSorter().toggleSortOrder(0);
67  artifactsTable.getRowSorter().toggleSortOrder(0);
68  }
69 
70  @Override
71  void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
72  artifactsTable.addMouseListener(mouseListener);
73  }
74 
75  @Override
76  void showPopupMenu(JPopupMenu popupMenu, Point point) {
77  popupMenu.show(artifactsTable, point.x, point.y);
78  }
79 
80  @Override
81  void addSelectionListener(ListSelectionListener listener) {
82  artifactsTable.getSelectionModel().addListSelectionListener(listener);
83  }
84 
85  @Override
86  void removeSelectionListener(ListSelectionListener listener) {
87  artifactsTable.getSelectionModel().removeListSelectionListener(listener);
88  }
89 
90  @Override
91  boolean isEmpty() {
92  return tableModel.getRowCount() <= 0;
93  }
94 
95  @Override
96  void selectFirst() {
97  if (!isEmpty()) {
98  artifactsTable.setRowSelectionInterval(0, 0);
99  } else {
100  artifactsTable.clearSelection();
101  }
102  }
103 
104  @Override
105  boolean selectAtPoint(Point point) {
106  boolean pointSelected = false;
107  int row = artifactsTable.rowAtPoint(point);
108  artifactsTable.clearSelection();
109  if (row < artifactsTable.getRowCount() && row >= 0) {
110  artifactsTable.addRowSelectionInterval(row, row);
111  pointSelected = true;
112  }
113  return pointSelected;
114  }
115 
116  @Override
117  BlackboardArtifact getSelectedArtifact() {
118  int selectedIndex = artifactsTable.getSelectionModel().getLeadSelectionIndex();
119  if (selectedIndex < artifactsTable.getSelectionModel().getMinSelectionIndex()
120  || artifactsTable.getSelectionModel().getMaxSelectionIndex() < 0
121  || selectedIndex > artifactsTable.getSelectionModel().getMaxSelectionIndex()) {
122  return null;
123  }
124  return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
125  }
126 
127  @Override
128  void addArtifacts(List<BlackboardArtifact> artifactList) {
129  tableModel.setContents(artifactList);
130  artifactsTable.validate();
131  artifactsTable.repaint();
132  tableModel.fireTableDataChanged();
133  }
134 
135  @Override
136  void clearList() {
137  tableModel.setContents(new ArrayList<>());
138  tableModel.fireTableDataChanged();
139  }
140 
144  private void initComponents() {
145  //This class is a refactored copy of ArtifactsListPanel so lacks the form however the init method still constructs the proper UI elements.
146  javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
147  artifactsTable = new javax.swing.JTable();
148 
149  setOpaque(false);
150  setPreferredSize(new java.awt.Dimension(200, 10));
151  jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 10));
152  jScrollPane1.setBorder(null);
153  jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
154 
155  artifactsTable.setAutoCreateRowSorter(true);
156  artifactsTable.setModel(tableModel);
157  artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
158  jScrollPane1.setViewportView(artifactsTable);
159 
160  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
161  this.setLayout(layout);
162  layout.setHorizontalGroup(
163  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
165  );
166  layout.setVerticalGroup(
167  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
169  );
170  }// </editor-fold>//GEN-END:initComponents
171 
176  private class TypeDescriptionTableModel extends AbstractTableModel {
177 
178  private static final long serialVersionUID = 1L;
179  private final List<BlackboardArtifact> artifactList = new ArrayList<>();
180 
188  void setContents(List<BlackboardArtifact> artifactList) {
189  artifactsTable.clearSelection();
190  this.artifactList.clear();
191  this.artifactList.addAll(artifactList);
192  }
193 
195  @Override
196  public int getRowCount() {
197  return artifactList.size();
198  }
199 
201  @Override
202  public int getColumnCount() {
203  return 2;
204  }
205 
214  BlackboardArtifact getArtifactByRow(int rowIndex) {
215  return artifactList.get(rowIndex);
216  }
217 
219  @NbBundle.Messages({"MiniTimelineArtifactListPanel.value.noValue=No value available."})
220  @Override
221  public Object getValueAt(int rowIndex, int columnIndex) {
222  switch (columnIndex) {
223  case 0:
224  return artifactList.get(rowIndex).getDisplayName();
225  case 1:
226  return getDescription(artifactList.get(rowIndex));
227  default:
228  return Bundle.MiniTimelineArtifactListPanel_value_noValue();
229  }
230  }
231 
232  private String getDescription(BlackboardArtifact artifact) {
233  try {
234  for (BlackboardAttribute.ATTRIBUTE_TYPE attributeType : DESCRIPTION_TYPES) {
235  BlackboardAttribute attribute = artifact.getAttribute(new Type(attributeType));
236  if (attribute != null && !StringUtils.isBlank(attribute.getDisplayString())) {
237  return attribute.getDisplayString();
238  }
239  }
240  } catch (TskCoreException ex) {
241  logger.log(Level.WARNING, "Unable to get description attribute for artifact id {0}", artifact.getArtifactID());
242  }
243  return Bundle.MiniTimelineArtifactListPanel_value_noValue();
244  }
245 
247  @NbBundle.Messages({
248  "MiniTimelineArtifactListPanel.typeColumn.name=Result Type",
249  "MiniTimelineArtifactListPanel.descriptionColumn.name= Description"})
250  @Override
251  public String getColumnName(int column) {
252  switch (column) {
253  case 0:
254  return Bundle.MiniTimelineArtifactListPanel_typeColumn_name();
255  case 1:
256  return Bundle.MiniTimelineArtifactListPanel_descriptionColumn_name();
257  default:
258  return "";
259  }
260  }
261  }
262 
263  // Variables declaration - do not modify//GEN-BEGIN:variables
264  private javax.swing.JTable artifactsTable;
265  // End of variables declaration//GEN-END:variables
266 }

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.