Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MiniTimelineDateListPanel.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.util.ArrayList;
22 import java.util.List;
23 import javax.swing.JPanel;
24 import javax.swing.event.ListSelectionListener;
25 import javax.swing.table.AbstractTableModel;
26 import javax.swing.table.TableCellRenderer;
27 import org.openide.util.NbBundle;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 
36 class MiniTimelineDateListPanel extends JPanel {
37 
38  private static final long serialVersionUID = 1L;
39  private final DateCountTableModel tableModel = new DateCountTableModel();
40 
44  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
45  MiniTimelineDateListPanel() {
46  initComponents();
47  // add the cell renderer to all columns
48  TableCellRenderer renderer = new SimpleTableCellRenderer();
49  for (int i = 0; i < tableModel.getColumnCount(); ++i) {
50  jTable1.getColumnModel().getColumn(i).setCellRenderer(renderer);
51  }
52  jTable1.getRowSorter().toggleSortOrder(0);
53  jTable1.getRowSorter().toggleSortOrder(0);
54  }
55 
62  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
63  void addSelectionListener(ListSelectionListener listener) {
64  jTable1.getSelectionModel().addListSelectionListener(listener);
65  }
66 
72  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
73  void removeListSelectionListener(ListSelectionListener listener) {
74  jTable1.getSelectionModel().removeListSelectionListener(listener);
75  }
76 
82  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
83  boolean isEmpty() {
84  return tableModel.getRowCount() <= 0;
85  }
86 
91  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
92  void selectFirst() {
93  if (!isEmpty()) {
94  jTable1.setRowSelectionInterval(0, 0);
95  } else {
96  jTable1.clearSelection();
97  }
98  }
99 
107  List<BlackboardArtifact> getArtifactsForSelectedDate() {
108  int selectedIndex = jTable1.getSelectionModel().getLeadSelectionIndex();
109  if (selectedIndex < jTable1.getSelectionModel().getMinSelectionIndex()
110  || jTable1.getSelectionModel().getMaxSelectionIndex() < 0
111  || selectedIndex > jTable1.getSelectionModel().getMaxSelectionIndex()) {
112  return new ArrayList<>();
113  }
114  return tableModel.getDateCountByRow(jTable1.convertRowIndexToModel(selectedIndex)).getArtifactList();
115  }
116 
123  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
124  void addArtifacts(List<MiniTimelineResult> dateArtifactList) {
125  tableModel.setContents(dateArtifactList);
126  jTable1.validate();
127  jTable1.repaint();
128  tableModel.fireTableDataChanged();
129  }
130 
134  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
135  void clearList() {
136  tableModel.setContents(new ArrayList<>());
137  tableModel.fireTableDataChanged();
138  }
139 
143  private void initComponents() {
144  //This class is a refactored copy of ArtifactsListPanel so lacks the form however the init method still constructs the proper UI elements.
145  javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
146  jTable1 = new javax.swing.JTable();
147 
148  setOpaque(false);
149  setPreferredSize(new java.awt.Dimension(200, 10));
150  jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 10));
151  jScrollPane1.setBorder(null);
152  jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
153 
154  jTable1.setAutoCreateRowSorter(true);
155  jTable1.setModel(tableModel);
156  jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
157  jScrollPane1.setViewportView(jTable1);
158 
159  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
160  this.setLayout(layout);
161  layout.setHorizontalGroup(
162  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
164  );
165  layout.setVerticalGroup(
166  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
168  );
169  }// </editor-fold>//GEN-END:initComponents
170 
175  private class DateCountTableModel extends AbstractTableModel {
176 
177  private static final long serialVersionUID = 1L;
178  private final List<MiniTimelineResult> dateCountList = new ArrayList<>();
179 
187  void setContents(List<MiniTimelineResult> dateCountList) {
188  jTable1.clearSelection();
189  this.dateCountList.clear();
190  this.dateCountList.addAll(dateCountList);
191  }
192 
194  @Override
195  public int getRowCount() {
196  return dateCountList.size();
197  }
198 
200  @Override
201  public int getColumnCount() {
202  return 2;
203  }
204 
213  MiniTimelineResult getDateCountByRow(int rowIndex) {
214  return dateCountList.get(rowIndex);
215  }
216 
218  @NbBundle.Messages({"MiniTimelineDateListPanel.value.noValue=No value available."})
219  @Override
220  public Object getValueAt(int rowIndex, int columnIndex) {
221  switch (columnIndex) {
222  case 0:
223  return dateCountList.get(rowIndex).getDate();
224  case 1:
225  return dateCountList.get(rowIndex).getCount();
226  default:
227  return Bundle.MiniTimelineDateListPanel_value_noValue();
228  }
229  }
230 
232  @NbBundle.Messages({
233  "MiniTimelineDateListPanel.dateColumn.name=Date",
234  "MiniTimelineDateListPanel.countColumn.name=Count"})
235  @Override
236  public String getColumnName(int column) {
237  switch (column) {
238  case 0:
239  return Bundle.MiniTimelineDateListPanel_dateColumn_name();
240  case 1:
241  return Bundle.MiniTimelineDateListPanel_countColumn_name();
242  default:
243  return "";
244  }
245  }
246  }
247 
248  // Variables declaration - do not modify//GEN-BEGIN:variables
249  private javax.swing.JTable jTable1;
250  // End of variables declaration//GEN-END:variables
251 }

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.