Autopsy  4.19.3
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.awt.Dimension;
22 import java.util.ArrayList;
23 import java.util.List;
24 import javax.swing.JPanel;
25 import javax.swing.event.ListSelectionListener;
26 import javax.swing.table.AbstractTableModel;
27 import javax.swing.table.TableCellRenderer;
28 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 
37 final class MiniTimelineDateListPanel extends JPanel {
38 
39  private static final long serialVersionUID = 1L;
40  private final DateCountTableModel tableModel = new DateCountTableModel();
41 
45  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
46  MiniTimelineDateListPanel() {
47  initComponents();
48  // add the cell renderer to all columns
49  TableCellRenderer renderer = new SimpleTableCellRenderer();
50  for (int i = 0; i < tableModel.getColumnCount(); ++i) {
51  jTable1.getColumnModel().getColumn(i).setCellRenderer(renderer);
52  }
53  setMinimumSize(new Dimension(125, 20));
54  jTable1.getRowSorter().toggleSortOrder(0);
55  jTable1.getRowSorter().toggleSortOrder(0);
56  }
57 
64  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
65  void addSelectionListener(ListSelectionListener listener) {
66  jTable1.getSelectionModel().addListSelectionListener(listener);
67  }
68 
72  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
73  void focusList() {
74  jTable1.grabFocus();
75  }
76 
82  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
83  void removeListSelectionListener(ListSelectionListener listener) {
84  jTable1.getSelectionModel().removeListSelectionListener(listener);
85  }
86 
92  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
93  boolean isEmpty() {
94  return tableModel.getRowCount() <= 0;
95  }
96 
101  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
102  void selectFirst() {
103  if (!isEmpty()) {
104  jTable1.setRowSelectionInterval(0, 0);
105  } else {
106  jTable1.clearSelection();
107  }
108  }
109 
117  List<BlackboardArtifact> getArtifactsForSelectedDate() {
118  int selectedIndex = jTable1.getSelectionModel().getLeadSelectionIndex();
119  if (selectedIndex < jTable1.getSelectionModel().getMinSelectionIndex()
120  || jTable1.getSelectionModel().getMaxSelectionIndex() < 0
121  || selectedIndex > jTable1.getSelectionModel().getMaxSelectionIndex()) {
122  return new ArrayList<>();
123  }
124  return tableModel.getDateCountByRow(jTable1.convertRowIndexToModel(selectedIndex)).getArtifactList();
125  }
126 
133  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
134  void addArtifacts(List<MiniTimelineResult> dateArtifactList) {
135  tableModel.setContents(dateArtifactList);
136  jTable1.validate();
137  jTable1.repaint();
138  tableModel.fireTableDataChanged();
139  }
140 
144  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
145  void clearList() {
146  tableModel.setContents(new ArrayList<>());
147  tableModel.fireTableDataChanged();
148  }
149 
153  private void initComponents() {
154  //This class is a refactored copy of ArtifactsListPanel so lacks the form however the init method still constructs the proper UI elements.
155  javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
156  jTable1 = new javax.swing.JTable();
157 
158  setOpaque(false);
159  setPreferredSize(new java.awt.Dimension(200, 10));
160  jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 10));
161  jScrollPane1.setBorder(null);
162  jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
163 
164  jTable1.setAutoCreateRowSorter(true);
165  jTable1.setModel(tableModel);
166  jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
167  jScrollPane1.setViewportView(jTable1);
168 
169  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
170  this.setLayout(layout);
171  layout.setHorizontalGroup(
172  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
173  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
174  );
175  layout.setVerticalGroup(
176  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
178  );
179  }// </editor-fold>//GEN-END:initComponents
180 
185  private class DateCountTableModel extends AbstractTableModel {
186 
187  private static final long serialVersionUID = 1L;
188  private final List<MiniTimelineResult> dateCountList = new ArrayList<>();
189 
197  void setContents(List<MiniTimelineResult> dateCountList) {
198  jTable1.clearSelection();
199  this.dateCountList.clear();
200  this.dateCountList.addAll(dateCountList);
201  }
202 
204  @Override
205  public int getRowCount() {
206  return dateCountList.size();
207  }
208 
210  @Override
211  public int getColumnCount() {
212  return 2;
213  }
214 
223  MiniTimelineResult getDateCountByRow(int rowIndex) {
224  return dateCountList.get(rowIndex);
225  }
226 
228  @NbBundle.Messages({"MiniTimelineDateListPanel.value.noValue=No value available."})
229  @Override
230  public Object getValueAt(int rowIndex, int columnIndex) {
231  switch (columnIndex) {
232  case 0:
233  return dateCountList.get(rowIndex).getDate();
234  case 1:
235  return dateCountList.get(rowIndex).getCount();
236  default:
237  return Bundle.MiniTimelineDateListPanel_value_noValue();
238  }
239  }
240 
242  @NbBundle.Messages({
243  "MiniTimelineDateListPanel.dateColumn.name=Date",
244  "MiniTimelineDateListPanel.countColumn.name=Count"})
245  @Override
246  public String getColumnName(int column) {
247  switch (column) {
248  case 0:
249  return Bundle.MiniTimelineDateListPanel_dateColumn_name();
250  case 1:
251  return Bundle.MiniTimelineDateListPanel_countColumn_name();
252  default:
253  return "";
254  }
255  }
256  }
257 
258  // Variables declaration - do not modify//GEN-BEGIN:variables
259  private javax.swing.JTable jTable1;
260  // End of variables declaration//GEN-END:variables
261 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.