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

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