Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DomainDetailsPanel.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 com.google.common.eventbus.Subscribe;
22 import java.awt.Component;
23 import javax.swing.JPanel;
24 import javax.swing.SwingUtilities;
25 import javax.swing.event.ChangeEvent;
26 import javax.swing.event.ChangeListener;
27 import org.apache.commons.lang.StringUtils;
28 import org.openide.util.NbBundle;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
33 
38 final class DomainDetailsPanel extends JPanel {
39 
40  private static final long serialVersionUID = 1L;
41  private ArtifactsWorker singleArtifactDomainWorker;
42  private String domain;
43  private String selectedTabName = null;
44 
50  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
51  DomainDetailsPanel() {
52  initComponents();
53  MiniTimelinePanel timelinePanel = new MiniTimelinePanel();
54  DiscoveryEventUtils.getDiscoveryEventBus().register(timelinePanel);
55  jTabbedPane1.add(Bundle.DomainDetailsPanel_miniTimelineTitle_text(), timelinePanel);
56  for (BlackboardArtifact.ARTIFACT_TYPE type : SearchData.Type.DOMAIN.getArtifactTypes()) {
57  jTabbedPane1.add(type.getDisplayName(), new DomainArtifactsTabPanel(type));
58  }
59  }
60 
67  @NbBundle.Messages({"DomainDetailsPanel.miniTimelineTitle.text=Timeline"})
68  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
69  void configureArtifactTabs(String tabName) {
70  selectedTabName = tabName;
71  if (StringUtils.isBlank(selectedTabName)) {
72  selectedTabName = Bundle.DomainDetailsPanel_miniTimelineTitle_text();
73  }
74  selectTab();
75  jTabbedPane1.addChangeListener(new ChangeListener() {
76  @Override
77  public void stateChanged(ChangeEvent e) {
78  if (jTabbedPane1.getSelectedIndex() >= 0) {
79  String newTabTitle = jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex());
80  if (selectedTabName == null || !selectedTabName.equals(newTabTitle)) {
81  selectedTabName = newTabTitle;
82  Component selectedComponent = jTabbedPane1.getSelectedComponent();
83  if (selectedComponent instanceof DomainArtifactsTabPanel) {
84  runDomainWorker((DomainArtifactsTabPanel) selectedComponent);
85  } else if (selectedComponent instanceof MiniTimelinePanel) {
86  runMiniTimelineWorker((MiniTimelinePanel) selectedComponent);
87  }
88  }
89  }
90  }
91  });
92  }
93 
94  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
99  private void selectTab() {
100  for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
101  if (!StringUtils.isBlank(selectedTabName) && selectedTabName.equals(jTabbedPane1.getTitleAt(i))) {
102  jTabbedPane1.setSelectedIndex(i);
103  return;
104  }
105  }
106  }
107 
113  DomainArtifactsTabPanel.ArtifactRetrievalStatus getCurrentTabStatus() {
114  if (jTabbedPane1.getSelectedComponent() instanceof MiniTimelinePanel) {
115  return ((MiniTimelinePanel) jTabbedPane1.getSelectedComponent()).getStatus();
116  } else if (jTabbedPane1.getSelectedComponent() instanceof DomainArtifactsTabPanel) {
117  return ((DomainArtifactsTabPanel) jTabbedPane1.getSelectedComponent()).getStatus();
118  }
119  return null;
120  }
121 
126  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
127  private void runDomainWorker(DomainArtifactsTabPanel domainArtifactsTabPanel) {
128  if (singleArtifactDomainWorker != null && !singleArtifactDomainWorker.isDone()) {
129  singleArtifactDomainWorker.cancel(true);
130  }
131  if (domainArtifactsTabPanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
132  DiscoveryEventUtils.getDiscoveryEventBus().register(domainArtifactsTabPanel);
133  domainArtifactsTabPanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING);
134  singleArtifactDomainWorker = new ArtifactsWorker(domainArtifactsTabPanel.getArtifactType(), domain);
135  singleArtifactDomainWorker.execute();
136  }
137 
138  }
139 
144  private void runMiniTimelineWorker(MiniTimelinePanel miniTimelinePanel) {
145  if (miniTimelinePanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
146  miniTimelinePanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING, domain);
147  new MiniTimelineWorker(domain).execute();
148  }
149  }
150 
157  @Subscribe
158  void handlePopulateDomainTabsEvent(DiscoveryEventUtils.PopulateDomainTabsEvent populateEvent) {
159  SwingUtilities.invokeLater(() -> {
160  if (StringUtils.isBlank(populateEvent.getDomain())) {
161  resetTabsStatus();
162  //send fade out event
163  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(false));
164  } else {
165  domain = populateEvent.getDomain();
166  Component selectedComponent = jTabbedPane1.getSelectedComponent();
167  if (selectedComponent instanceof DomainArtifactsTabPanel) {
168  runDomainWorker((DomainArtifactsTabPanel) selectedComponent);
169  } else if (selectedComponent instanceof MiniTimelinePanel) {
170  runMiniTimelineWorker((MiniTimelinePanel) selectedComponent);
171  }
172  //send fade in event
173  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(true));
174  }
175  });
176  }
177 
182  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
183  private void resetTabsStatus() {
184  for (Component comp : jTabbedPane1.getComponents()) {
185  if (comp instanceof DomainArtifactsTabPanel) {
186  ((DomainArtifactsTabPanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED);
187  } else if (comp instanceof MiniTimelinePanel) {
188  ((MiniTimelinePanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED, domain);
189  }
190  }
191  }
192 
198  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
199  String getSelectedTabName() {
200  return selectedTabName;
201  }
202 
208  @SuppressWarnings("unchecked")
209  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
210  private void initComponents() {
211 
212  jTabbedPane1 = new javax.swing.JTabbedPane();
213 
214  setEnabled(false);
215  setMinimumSize(new java.awt.Dimension(0, 0));
216  setPreferredSize(new java.awt.Dimension(0, 0));
217  setLayout(new java.awt.BorderLayout());
218 
219  jTabbedPane1.setMinimumSize(new java.awt.Dimension(0, 0));
220  jTabbedPane1.setPreferredSize(new java.awt.Dimension(0, 0));
221  add(jTabbedPane1, java.awt.BorderLayout.CENTER);
222  }// </editor-fold>//GEN-END:initComponents
223 
224  // Variables declaration - do not modify//GEN-BEGIN:variables
225  private javax.swing.JTabbedPane jTabbedPane1;
226  // End of variables declaration//GEN-END:variables
227 
228  /*
229  * Unregister the MiniTimelinePanel from the event bus.
230  */
231  void unregister() {
232  for (Component comp : jTabbedPane1.getComponents()) {
233  if (comp instanceof MiniTimelinePanel) {
234  DiscoveryEventUtils.getDiscoveryEventBus().unregister(comp);
235  }
236  }
237  }
238 }

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.