19 package org.sleuthkit.autopsy.discovery.ui;
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;
43 final class MiniTimelineArtifactListPanel
extends AbstractArtifactListPanel {
45 private static final long serialVersionUID = 1L;
46 private final TypeDescriptionTableModel tableModel;
47 private static final Logger logger = Logger.getLogger(MiniTimelineArtifactListPanel.class.getName());
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};
56 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
57 MiniTimelineArtifactListPanel() {
58 tableModel =
new TypeDescriptionTableModel();
61 TableCellRenderer renderer =
new SimpleTableCellRenderer();
62 for (
int i = 0; i < tableModel.getColumnCount(); ++i) {
63 artifactsTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
65 setMinimumSize(
new Dimension(125, 20));
66 artifactsTable.getRowSorter().toggleSortOrder(0);
67 artifactsTable.getRowSorter().toggleSortOrder(0);
71 void addMouseListener(java.awt.event.MouseAdapter mouseListener) {
72 artifactsTable.addMouseListener(mouseListener);
76 void showPopupMenu(JPopupMenu popupMenu, Point point) {
77 popupMenu.show(artifactsTable, point.x, point.y);
81 void addSelectionListener(ListSelectionListener listener) {
82 artifactsTable.getSelectionModel().addListSelectionListener(listener);
86 void removeSelectionListener(ListSelectionListener listener) {
87 artifactsTable.getSelectionModel().removeListSelectionListener(listener);
92 return tableModel.getRowCount() <= 0;
98 artifactsTable.setRowSelectionInterval(0, 0);
100 artifactsTable.clearSelection();
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;
113 return pointSelected;
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()) {
124 return tableModel.getArtifactByRow(artifactsTable.convertRowIndexToModel(selectedIndex));
128 void addArtifacts(List<BlackboardArtifact> artifactList) {
129 tableModel.setContents(artifactList);
130 artifactsTable.validate();
131 artifactsTable.repaint();
132 tableModel.fireTableDataChanged();
137 tableModel.setContents(
new ArrayList<>());
138 tableModel.fireTableDataChanged();
144 private void initComponents() {
146 javax.swing.JScrollPane jScrollPane1 =
new javax.swing.JScrollPane();
147 artifactsTable =
new javax.swing.JTable();
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));
155 artifactsTable.setAutoCreateRowSorter(
true);
156 artifactsTable.setModel(tableModel);
157 artifactsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
158 jScrollPane1.setViewportView(artifactsTable);
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)
166 layout.setVerticalGroup(
167 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
178 private static final long serialVersionUID = 1L;
179 private final List<BlackboardArtifact> artifactList =
new ArrayList<>();
188 void setContents(List<BlackboardArtifact> artifactList) {
189 artifactsTable.clearSelection();
190 this.artifactList.clear();
191 this.artifactList.addAll(artifactList);
197 return artifactList.size();
214 BlackboardArtifact getArtifactByRow(
int rowIndex) {
215 return artifactList.get(rowIndex);
219 @NbBundle.Messages({
"MiniTimelineArtifactListPanel.value.noValue=No value available."})
222 switch (columnIndex) {
224 return artifactList.get(rowIndex).getDisplayName();
228 return Bundle.MiniTimelineArtifactListPanel_value_noValue();
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();
240 }
catch (TskCoreException ex) {
241 logger.log(Level.WARNING,
"Unable to get description attribute for artifact id {0}", artifact.getArtifactID());
243 return Bundle.MiniTimelineArtifactListPanel_value_noValue();
248 "MiniTimelineArtifactListPanel.typeColumn.name=Result Type",
249 "MiniTimelineArtifactListPanel.descriptionColumn.name= Description"})
254 return Bundle.MiniTimelineArtifactListPanel_typeColumn_name();
256 return Bundle.MiniTimelineArtifactListPanel_descriptionColumn_name();
264 private javax.swing.JTable artifactsTable;
String getColumnName(int column)
Object getValueAt(int rowIndex, int columnIndex)
String getDescription(BlackboardArtifact artifact)