Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceSummaryTabbedPane.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
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.datasourcesummary.ui;
20 
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.beans.PropertyChangeListener;
24 import java.util.Arrays;
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.function.Consumer;
28 import org.openide.util.NbBundle.Messages;
31 import org.sleuthkit.datamodel.DataSource;
32 
37 @Messages({
38  "DataSourceSummaryTabbedPane_typesTab_title=Types",
39  "DataSourceSummaryTabbedPane_detailsTab_title=Container",
40  "DataSourceSummaryTabbedPane_userActivityTab_title=User Activity",
41  "DataSourceSummaryTabbedPane_ingestHistoryTab_title=Ingest History",
42  "DataSourceSummaryTabbedPane_recentFileTab_title=Recent Files",
43  "DataSourceSummaryTabbedPane_pastCasesTab_title=Past Cases",
44  "DataSourceSummaryTabbedPane_analysisTab_title=Analysis",
45  "DataSourceSummaryTabbedPane_geolocationTab_title=Geolocation",
46  "DataSourceSummaryTabbedPane_timelineTab_title=Timeline"
47 })
48 public class DataSourceSummaryTabbedPane extends javax.swing.JPanel {
49 
54  private class DataSourceTab {
55 
56  private final String tabTitle;
57  private final Component component;
58  private final Consumer<DataSource> onDataSource;
59  private final Runnable onClose;
60  private final Runnable onInit;
61 
68  DataSourceTab(String tabTitle, BaseDataSourceSummaryPanel panel) {
69  this(tabTitle, panel, panel::setDataSource, panel::close, panel::init);
70  panel.setParentCloseListener(() -> notifyParentClose());
71  }
72 
87  DataSourceTab(String tabTitle, Component component, Consumer<DataSource> onDataSource,
88  Runnable onClose, Runnable onInit) {
89  this.tabTitle = tabTitle;
90  this.component = component;
91  this.onDataSource = onDataSource;
92  this.onClose = onClose;
93  this.onInit = onInit;
94  }
95 
99  public String getTabTitle() {
100  return tabTitle;
101  }
102 
106  Component getComponent() {
107  return component;
108  }
109 
113  Consumer<DataSource> getOnDataSource() {
114  return onDataSource;
115  }
116 
120  public Runnable getOnClose() {
121  return onClose;
122  }
123 
128  public Runnable getOnInit() {
129  return onInit;
130  }
131  }
132 
133  private static final long serialVersionUID = 1L;
134 
135  // needs to match value provided for card layout in designed
136  private static final String TABBED_PANE = "tabbedPane";
137  private static final String NO_DATASOURCE_PANE = "noDataSourcePane";
138 
139  private Runnable notifyParentClose = null;
140  private final IngestJobInfoPanel ingestHistoryPanel = new IngestJobInfoPanel();
141 
142  private final List<DataSourceTab> tabs = Arrays.asList(
143  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_typesTab_title(), new TypesPanel()),
144  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_userActivityTab_title(), new UserActivityPanel()),
145  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_analysisTab_title(), new AnalysisPanel()),
146  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_recentFileTab_title(), new RecentFilesPanel()),
147  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_pastCasesTab_title(), new PastCasesPanel()),
148  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_geolocationTab_title(), new GeolocationPanel()),
149  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_timelineTab_title(), new TimelinePanel()),
150  // do nothing on closing
151  new DataSourceTab(
152  Bundle.DataSourceSummaryTabbedPane_ingestHistoryTab_title(),
153  ingestHistoryPanel,
154  ingestHistoryPanel::setDataSource,
155  null,
156  null),
157  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_detailsTab_title(), new ContainerPanel())
158  );
159 
160  private DataSource dataSource = null;
161  private CardLayout cardLayout;
162 
166  private final PropertyChangeListener caseEventsListener = (evt) -> {
167  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString()) && evt.getNewValue() == null) {
168  setDataSource(null);
169  }
170  };
171 
176  initComponents();
177  postInit();
178  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
179  }
180 
184  private void notifyParentClose() {
185  if (notifyParentClose != null) {
186  notifyParentClose.run();
187  }
188  }
189 
195  void setParentCloseListener(Runnable parentCloseAction) {
196  notifyParentClose = parentCloseAction;
197  }
198 
202  private void postInit() {
203  // get the card layout
204  cardLayout = (CardLayout) this.getLayout();
205 
206  // set up the tabs
207  for (DataSourceTab tab : tabs) {
208  tabbedPane.addTab(tab.getTabTitle(), tab.getComponent());
209 
210  // initialize the tab pane if it has an initialization method
211  Runnable onInitMethod = tab.getOnInit();
212  if (onInitMethod != null) {
213  onInitMethod.run();
214  }
215  }
216 
217  // set this to no datasource initially
218  cardLayout.show(this, NO_DATASOURCE_PANE);
219  }
220 
226  public DataSource getDataSource() {
227  return dataSource;
228  }
229 
235  public void setDataSource(DataSource dataSource) {
236  this.dataSource = dataSource;
237 
238  for (DataSourceTab tab : tabs) {
239  if (tab.getOnDataSource() != null) {
240  tab.getOnDataSource().accept(dataSource);
241  }
242  }
243 
244  if (this.dataSource == null) {
245  cardLayout.show(this, NO_DATASOURCE_PANE);
246  } else {
247  cardLayout.show(this, TABBED_PANE);
248  }
249  }
250 
254  public void close() {
255  for (DataSourceTab tab : tabs) {
256  if (tab.getOnClose() != null) {
257  tab.getOnClose().run();
258  }
259  }
260 
261  Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
262  }
263 
269  @SuppressWarnings("unchecked")
270  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
271  private void initComponents() {
272 
273  javax.swing.JPanel noDataSourcePane = new javax.swing.JPanel();
274  javax.swing.JLabel noDataSourceLabel = new javax.swing.JLabel();
275  javax.swing.JPanel tabContentPane = new javax.swing.JPanel();
276  tabbedPane = new javax.swing.JTabbedPane();
277 
278  setLayout(new java.awt.CardLayout());
279 
280  noDataSourcePane.setLayout(new java.awt.BorderLayout());
281 
282  noDataSourceLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
283  org.openide.awt.Mnemonics.setLocalizedText(noDataSourceLabel, org.openide.util.NbBundle.getMessage(DataSourceSummaryTabbedPane.class, "DataSourceSummaryTabbedPane.noDataSourceLabel.text")); // NOI18N
284  noDataSourcePane.add(noDataSourceLabel, java.awt.BorderLayout.CENTER);
285 
286  add(noDataSourcePane, "noDataSourcePane");
287 
288  tabContentPane.setLayout(new java.awt.BorderLayout());
289  tabContentPane.add(tabbedPane, java.awt.BorderLayout.CENTER);
290 
291  add(tabContentPane, "tabbedPane");
292  }// </editor-fold>//GEN-END:initComponents
293 
294 
295  // Variables declaration - do not modify//GEN-BEGIN:variables
296  private javax.swing.JTabbedPane tabbedPane;
297  // End of variables declaration//GEN-END:variables
298 }
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:704
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:749

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