Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DomainArtifactsTabPanel.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 
22 import com.google.common.eventbus.Subscribe;
23 import java.awt.Dimension;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.util.logging.Level;
27 import javax.swing.JPanel;
28 import javax.swing.JSplitPane;
29 import javax.swing.SwingUtilities;
30 import javax.swing.event.ListSelectionEvent;
31 import javax.swing.event.ListSelectionListener;
36 import org.sleuthkit.datamodel.BlackboardArtifact;
37 
41 final class DomainArtifactsTabPanel extends JPanel {
42 
43  private static final long serialVersionUID = 1L;
44  private final static Logger logger = Logger.getLogger(DomainArtifactsTabPanel.class.getName());
45  private final ArtifactsListPanel listPanel;
46  private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
47  private AbstractArtifactDetailsPanel rightPanel = null;
48  private int dividerLocation = 300;
49  private final PropertyChangeListener dividerListener;
50 
51  private ArtifactRetrievalStatus status = ArtifactRetrievalStatus.UNPOPULATED;
52  private final ListSelectionListener listener = new ListSelectionListener() {
53  @Override
54  public void valueChanged(ListSelectionEvent event) {
55  if (!event.getValueIsAdjusting()) {
56  mainSplitPane.removePropertyChangeListener(dividerListener);
57  rightPanel.setArtifact(listPanel.getSelectedArtifact());
58  mainSplitPane.setDividerLocation(dividerLocation);
59  mainSplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, dividerListener);
60  }
61  }
62  };
63 
69  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
70  DomainArtifactsTabPanel(BlackboardArtifact.ARTIFACT_TYPE type) {
71  initComponents();
72  dividerListener = new PropertyChangeListener() {
73  @Override
74  public void propertyChange(PropertyChangeEvent evt) {
75  if (evt.getPropertyName().equalsIgnoreCase(JSplitPane.DIVIDER_LOCATION_PROPERTY)
76  && evt.getNewValue() instanceof Integer
77  && evt.getOldValue() instanceof Integer
78  && (JSplitPane.UNDEFINED_CONDITION != (int) evt.getNewValue())) {
79  dividerLocation = (int) evt.getNewValue();
80  }
81  }
82  };
83  this.artifactType = type;
84  listPanel = new ArtifactsListPanel(artifactType);
85  listPanel.setPreferredSize(new Dimension(100, 20));
86  listPanel.addMouseListener(new ArtifactMenuMouseAdapter(listPanel));
87 
88  mainSplitPane.setLeftComponent(listPanel);
89  add(mainSplitPane);
90  setRightComponent();
91  mainSplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, dividerListener);
92  dividerLocation = mainSplitPane.getDividerLocation();
93  listPanel.addSelectionListener(listener);
94  }
95 
100  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
101  private void setRightComponent() {
102  switch (artifactType) {
103  case TSK_WEB_HISTORY:
104  case TSK_WEB_COOKIE:
105  case TSK_WEB_SEARCH_QUERY:
106  case TSK_WEB_BOOKMARK:
107  rightPanel = new GeneralPurposeArtifactViewer();
108  break;
109  case TSK_WEB_DOWNLOAD:
110  case TSK_WEB_CACHE:
111  rightPanel = new ContentViewerDetailsPanel();
112  break;
113  default:
114  rightPanel = new DefaultTableArtifactContentViewer();
115  break;
116  }
117  if (rightPanel != null) {
118  mainSplitPane.setRightComponent(rightPanel.getComponent());
119  }
120  }
121 
125  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
126  void focusList() {
127  listPanel.focusList();
128  }
129 
135  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
136  ArtifactRetrievalStatus getStatus() {
137  return status;
138  }
139 
145  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
146  void setStatus(ArtifactRetrievalStatus status) {
147  this.status = status;
148  mainSplitPane.removePropertyChangeListener(dividerListener);
149  if (status == ArtifactRetrievalStatus.UNPOPULATED) {
150  listPanel.clearList();
151  removeAll();
152  add(mainSplitPane);
153  if (rightPanel != null) {
154  rightPanel.setArtifact(null);
155  }
156  } else if (status == ArtifactRetrievalStatus.POPULATING) {
157  removeAll();
158  add(new LoadingPanel(artifactType.getDisplayName()));
159  }
160  mainSplitPane.setDividerLocation(dividerLocation);
161  mainSplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, dividerListener);
162  }
163 
170  @Subscribe
171  void handleArtifactSearchResultEvent(DiscoveryEventUtils.ArtifactSearchResultEvent artifactresultEvent) {
172  if (artifactType == artifactresultEvent.getArtifactType() && status == ArtifactRetrievalStatus.POPULATING) {
173  SwingUtilities.invokeLater(() -> {
174  mainSplitPane.removePropertyChangeListener(dividerListener);
175  listPanel.removeSelectionListener(listener);
176  listPanel.addArtifacts(artifactresultEvent.getListOfArtifacts());
177  status = ArtifactRetrievalStatus.POPULATED;
178  setEnabled(!listPanel.isEmpty());
179  listPanel.addSelectionListener(listener);
180  listPanel.selectFirst();
181  removeAll();
182  add(mainSplitPane);
183  mainSplitPane.setDividerLocation(dividerLocation);
184  mainSplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, dividerListener);
185  if (artifactresultEvent.shouldGrabFocus()) {
186  focusList();
187  }
188  revalidate();
189  repaint();
190  try {
191  DiscoveryEventUtils.getDiscoveryEventBus().unregister(this);
192  } catch (IllegalArgumentException notRegistered) {
193  logger.log(Level.INFO, "Attempting to unregister tab which was not registered");
194  // attempting to remove a tab that was never registered
195  }
196  });
197  }
198  }
199 
205  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
206  BlackboardArtifact.ARTIFACT_TYPE getArtifactType() {
207  return artifactType;
208  }
209 
215  @SuppressWarnings("unchecked")
216  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
217  private void initComponents() {
218 
219  mainSplitPane = new javax.swing.JSplitPane();
220 
221  mainSplitPane.setDividerLocation(dividerLocation);
222  mainSplitPane.setResizeWeight(0.2);
223  mainSplitPane.setLastDividerLocation(250);
224 
225  setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
226  setMinimumSize(new java.awt.Dimension(0, 0));
227  setLayout(new java.awt.BorderLayout());
228  }// </editor-fold>//GEN-END:initComponents
229 
230 
231  // Variables declaration - do not modify//GEN-BEGIN:variables
232  private javax.swing.JSplitPane mainSplitPane;
233  // End of variables declaration//GEN-END:variables
234 
238  enum ArtifactRetrievalStatus {
239  UNPOPULATED(),
240  POPULATING(),
241  POPULATED();
242  }
243 
244 }

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