Autopsy  4.17.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 
69  DataSourceTab(String tabTitle, Component component, Consumer<DataSource> onDataSource, Runnable onClose) {
70  this.tabTitle = tabTitle;
71  this.component = component;
72  this.onDataSource = onDataSource;
73  this.onClose = onClose;
74  }
75 
83  DataSourceTab(String tabTitle, BaseDataSourceSummaryPanel panel) {
84 
85  panel.setParentCloseListener(() -> notifyParentClose());
86 
87  this.tabTitle = tabTitle;
88  this.component = panel;
89  this.onDataSource = panel::setDataSource;
90  this.onClose = panel::close;
91  }
92 
96  String getTabTitle() {
97  return tabTitle;
98  }
99 
103  Component getComponent() {
104  return component;
105  }
106 
110  Consumer<DataSource> getOnDataSource() {
111  return onDataSource;
112  }
113 
117  public Runnable getOnClose() {
118  return onClose;
119  }
120  }
121 
122  private static final long serialVersionUID = 1L;
123  // needs to match value provided for card layout in designed
124  private static final String TABBED_PANE = "tabbedPane";
125  private static final String NO_DATASOURCE_PANE = "noDataSourcePane";
126 
127  private Runnable notifyParentClose = null;
128  private final IngestJobInfoPanel ingestHistoryPanel = new IngestJobInfoPanel();
129 
130  private final List<DataSourceTab> tabs = Arrays.asList(
131  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_typesTab_title(), new TypesPanel()),
132  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_userActivityTab_title(), new UserActivityPanel()),
133  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_analysisTab_title(), new AnalysisPanel()),
134  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_recentFileTab_title(), new RecentFilesPanel()),
135  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_pastCasesTab_title(), new PastCasesPanel()),
136  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_geolocationTab_title(), new GeolocationPanel()),
137  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_timelineTab_title(), new TimelinePanel()),
138  // do nothing on closing
139  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_ingestHistoryTab_title(), ingestHistoryPanel, ingestHistoryPanel::setDataSource, () -> {
140  }),
141  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_detailsTab_title(), new ContainerPanel())
142  );
143 
144  private DataSource dataSource = null;
145  private CardLayout cardLayout;
146 
150  private final PropertyChangeListener caseEventsListener = (evt) -> {
151  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString()) && evt.getNewValue() == null) {
152  setDataSource(null);
153  }
154  };
155 
160  initComponents();
161  postInit();
162  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
163  }
164 
168  private void notifyParentClose() {
169  if (notifyParentClose != null) {
170  notifyParentClose.run();
171  }
172  }
173 
179  void setParentCloseListener(Runnable parentCloseAction) {
180  notifyParentClose = parentCloseAction;
181  }
182 
186  private void postInit() {
187  // get the card layout
188  cardLayout = (CardLayout) this.getLayout();
189 
190  // set up the tabs
191  for (DataSourceTab tab : tabs) {
192  tabbedPane.addTab(tab.getTabTitle(), tab.getComponent());
193  }
194 
195  // set this to no datasource initially
196  cardLayout.show(this, NO_DATASOURCE_PANE);
197  }
198 
204  public DataSource getDataSource() {
205  return dataSource;
206  }
207 
213  public void setDataSource(DataSource dataSource) {
214  this.dataSource = dataSource;
215 
216  for (DataSourceTab tab : tabs) {
217  tab.getOnDataSource().accept(dataSource);
218  }
219 
220  if (this.dataSource == null) {
221  cardLayout.show(this, NO_DATASOURCE_PANE);
222  } else {
223  cardLayout.show(this, TABBED_PANE);
224  }
225  }
226 
230  public void close() {
231  for (DataSourceTab tab : tabs) {
232  tab.getOnClose().run();
233  }
234 
235  Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
236  }
237 
243  @SuppressWarnings("unchecked")
244  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
245  private void initComponents() {
246 
247  tabbedPane = new javax.swing.JTabbedPane();
248  javax.swing.JPanel noDataSourcePane = new javax.swing.JPanel();
249  javax.swing.JLabel noDataSourceLabel = new javax.swing.JLabel();
250 
251  setLayout(new java.awt.CardLayout());
252  add(tabbedPane, "tabbedPane");
253 
254  noDataSourcePane.setLayout(new java.awt.BorderLayout());
255 
256  noDataSourceLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
257  org.openide.awt.Mnemonics.setLocalizedText(noDataSourceLabel, org.openide.util.NbBundle.getMessage(DataSourceSummaryTabbedPane.class, "DataSourceSummaryTabbedPane.noDataSourceLabel.text")); // NOI18N
258  noDataSourcePane.add(noDataSourceLabel, java.awt.BorderLayout.CENTER);
259 
260  add(noDataSourcePane, "noDataSourcePane");
261  }// </editor-fold>//GEN-END:initComponents
262 
263 
264  // Variables declaration - do not modify//GEN-BEGIN:variables
265  private javax.swing.JTabbedPane tabbedPane;
266  // End of variables declaration//GEN-END:variables
267 }
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:491
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:536

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.